Skip to content

Commit d6a6baa

Browse files
author
Viet-Anh Duong
authored
Deprecate Gcloud CLI with gke module (#3)
* deprecated gcloud cli with gke Signed-off-by: vietanhduong <anh.duong@kyber.network> * fix cmd Signed-off-by: vietanhduong <anh.duong@kyber.network> * remove go work sum Signed-off-by: vietanhduong <anh.duong@kyber.network> --------- Signed-off-by: vietanhduong <anh.duong@kyber.network>
1 parent 596446c commit d6a6baa

File tree

9 files changed

+539
-243
lines changed

9 files changed

+539
-243
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# Go workspace file
2121
go.work
22+
go.work.sum
2223
*.env
2324
*.override.*
2425
.DS_Store

cmd/gke/pause/run.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ package pause
22

33
import (
44
"fmt"
5+
"log"
6+
"os"
7+
"strings"
8+
59
"github.com/pkg/errors"
610
apis "github.com/vietanhduong/pause-gcp/apis/v1"
711
"github.com/vietanhduong/pause-gcp/pkg/gcloud/gke"
812
"github.com/vietanhduong/pause-gcp/pkg/utils/exec"
913
"github.com/vietanhduong/pause-gcp/pkg/utils/sets"
1014
"google.golang.org/protobuf/encoding/protojson"
11-
"log"
12-
"os"
13-
"strings"
1415
)
1516

1617
type runConfig struct {
@@ -22,7 +23,8 @@ type runConfig struct {
2223
}
2324

2425
func run(cfg runConfig) error {
25-
cluster, err := gke.GetCluster(cfg.project, cfg.location, cfg.clusterName)
26+
gkeClient := gke.NewClient(gke.Options{})
27+
cluster, err := gkeClient.GetCluster(cfg.project, cfg.location, cfg.clusterName)
2628
if err != nil {
2729
return err
2830
}
@@ -38,7 +40,7 @@ func run(cfg runConfig) error {
3840
}
3941
}
4042
cluster.NodePools = pools
41-
if err = gke.PauseCluster(cluster, false); err != nil {
43+
if err = gkeClient.PauseCluster(cluster); err != nil {
4244
return err
4345
}
4446

@@ -54,8 +56,8 @@ func run(cfg runConfig) error {
5456
return err
5557
}
5658
} else {
57-
_ = os.MkdirAll(cfg.outputDir, 0755)
58-
if err = os.WriteFile(dst, b, 0644); err != nil {
59+
_ = os.MkdirAll(cfg.outputDir, 0o755)
60+
if err = os.WriteFile(dst, b, 0o644); err != nil {
5961
return err
6062
}
6163
}

cmd/gke/refresh/cmd.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import (
77
)
88

99
func NewCommand() *cobra.Command {
10-
var (
11-
runCfg runConfig
12-
)
10+
var runCfg runConfig
1311

14-
var cmd = &cobra.Command{
12+
cmd := &cobra.Command{
1513
Use: "refresh [CLUSTER_NAME]",
1614
Short: "Refresh a GKE cluster",
1715
Long: `Refresh a GKE cluster.
@@ -33,7 +31,6 @@ Refresh all worker nodes in all node pools of the input cluster. This command ju
3331

3432
cmd.Flags().StringVarP(&runCfg.location, "location", "l", "asia-southeast1", "the cluster location")
3533
cmd.Flags().StringVarP(&runCfg.project, "project", "p", "", "the project where contain the cluster")
36-
cmd.Flags().BoolVar(&runCfg.recreate, "recreate", false, "keep the instance (node) name or delete and create with new name otherwise")
3734

3835
return cmd
3936
}

cmd/gke/refresh/run.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
package refresh
22

33
import (
4+
"log"
5+
46
"github.com/pkg/errors"
57
"github.com/vietanhduong/pause-gcp/pkg/gcloud/gke"
6-
"log"
78
)
89

910
type runConfig struct {
1011
name string
1112
project string
1213
location string
13-
recreate bool
1414
}
1515

1616
func run(cfg runConfig) error {
17-
cluster, err := gke.GetCluster(cfg.project, cfg.location, cfg.name)
17+
gkeClient := gke.NewClient(gke.Options{})
18+
cluster, err := gkeClient.GetCluster(cfg.project, cfg.location, cfg.name)
1819
if err != nil {
1920
return err
2021
}
2122
if cluster == nil {
2223
return errors.Errorf("cluster '%s/%s/%s' not found", cfg.project, cfg.location, cfg.name)
2324
}
24-
if err = gke.RefreshCluster(cluster, cfg.recreate); err != nil {
25+
if err = gkeClient.RefreshCluster(cluster); err != nil {
2526
return err
2627
}
2728
log.Printf("INFO: cluster '%s' has been refreshed!", cfg.name)

cmd/gke/unpause/run.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
package unpause
22

33
import (
4+
"log"
5+
46
"github.com/pkg/errors"
57
apis "github.com/vietanhduong/pause-gcp/apis/v1"
68
"github.com/vietanhduong/pause-gcp/pkg/gcloud/gke"
7-
"log"
89
)
910

1011
type runConfig struct {
1112
cluster *apis.Cluster
1213
}
1314

1415
func run(cfg runConfig) error {
15-
cluster, err := gke.GetCluster(cfg.cluster.GetProject(), cfg.cluster.GetLocation(), cfg.cluster.GetName())
16+
gkeClient := gke.NewClient(gke.Options{})
17+
cluster, err := gkeClient.GetCluster(cfg.cluster.GetProject(), cfg.cluster.GetLocation(), cfg.cluster.GetName())
1618
if err != nil {
1719
return err
1820
}
1921
if cluster == nil {
2022
return errors.Errorf("cluster '%s/%s/%s' not found", cfg.cluster.GetProject(), cfg.cluster.GetLocation(), cfg.cluster.GetName())
2123
}
22-
if err = gke.UnpauseCluster(cfg.cluster); err != nil {
24+
if err = gkeClient.UnpauseCluster(cfg.cluster); err != nil {
2325
return err
2426
}
2527
log.Printf("INFO: cluster '%s' is running now!", cfg.cluster.GetName())

go.mod

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.20
44

55
require (
66
cloud.google.com/go/compute v1.19.3
7-
cloud.google.com/go/container v1.18.1
7+
cloud.google.com/go/container v1.21.0
88
github.com/golang/protobuf v1.5.3
99
github.com/json-iterator/go v1.1.12
1010
github.com/pkg/errors v0.9.1
@@ -14,19 +14,32 @@ require (
1414
golang.org/x/exp v0.0.0-20230519143937-03e91628a987
1515
golang.org/x/net v0.10.0
1616
golang.org/x/sync v0.2.0
17+
google.golang.org/api v0.125.0
1718
google.golang.org/protobuf v1.30.0
1819
k8s.io/apimachinery v0.27.2
1920
)
2021

2122
require (
23+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
2224
github.com/davecgh/go-spew v1.1.1 // indirect
25+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
26+
github.com/google/go-cmp v0.5.9 // indirect
27+
github.com/google/s2a-go v0.1.4 // indirect
28+
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
29+
github.com/googleapis/gax-go/v2 v2.10.0 // indirect
2330
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2431
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
2532
github.com/modern-go/reflect2 v1.0.2 // indirect
2633
github.com/pmezard/go-difflib v1.0.0 // indirect
34+
go.opencensus.io v0.24.0 // indirect
35+
golang.org/x/crypto v0.9.0 // indirect
36+
golang.org/x/oauth2 v0.8.0 // indirect
2737
golang.org/x/sys v0.8.0 // indirect
2838
golang.org/x/text v0.9.0 // indirect
29-
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
39+
google.golang.org/appengine v1.6.7 // indirect
40+
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
41+
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
42+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
3043
google.golang.org/grpc v1.55.0 // indirect
3144
gopkg.in/yaml.v3 v3.0.1 // indirect
3245
)

0 commit comments

Comments
 (0)