-
Notifications
You must be signed in to change notification settings - Fork 181
/
main.go
67 lines (54 loc) · 1.81 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"context"
"flag"
"os"
"github.com/kyma-project/test-infra/development/prow-installer/pkg/cluster"
log "github.com/sirupsen/logrus"
container "google.golang.org/api/container/v1"
"google.golang.org/api/option"
)
var (
projectID = flag.String("proj", "", "ProjectID of the GCP project [Required]")
zoneID = flag.String("zone", "global", "GCP zone for the cluster to be created [Required]")
)
func main() {
if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" {
log.Fatalf("Requires the environment variable GOOGLE_APPLICATION_CREDENTIALS to be set to a GCP service account file.")
}
flag.Parse()
if *projectID == "" {
log.Fatalf("Missing required argument : -proj")
}
if *zoneID == "" {
log.Fatalf("Missing required argument : -zone")
}
ctx := context.Background()
containerService, err := container.NewService(ctx, option.WithServiceAccountFile(os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")))
if err != nil {
log.Fatalf("Couldn't create service handle for GCP: %w", err)
}
clusterService := containerService.Projects.Zones.Clusters
wrappedAPI := &cluster.APIWrapper{
ProjectID: *projectID,
ZoneID: *zoneID,
ClusterService: clusterService,
}
clientOpts := cluster.Option{}
clientOpts = clientOpts.WithProjectID(*projectID).WithServiceAccount(os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
gkeClient, err := cluster.New(clientOpts, wrappedAPI)
if err != nil {
log.Errorf("Could not create GKE Client: %v", err)
os.Exit(1)
}
labels := make(map[string]string)
labels["created-for"] = "testing"
// err = gkeClient.Create(ctx, "daniel-test-cluster", labels, 1, true)
// if err != nil {
// log.Fatalf("Couldn't create cluster %w", err)
// }
err = gkeClient.Delete(ctx, "", "europe-west-3-c")
if err != nil {
log.Fatalf("Couldn't delete cluster %w", err)
}
}