Skip to content

Commit 4e81290

Browse files
author
vietanhduong
committed
update command
Signed-off-by: vietanhduong <anh.duong@kyber.network>
1 parent dda5646 commit 4e81290

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

cmd/gke/refresh/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Refresh all worker nodes in all node pools of the input cluster. This command ju
3333

3434
cmd.Flags().StringVarP(&runCfg.location, "location", "l", "asia-southeast1", "the cluster location")
3535
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")
3637

3738
return cmd
3839
}

cmd/gke/refresh/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type runConfig struct {
1010
name string
1111
project string
1212
location string
13+
recreate bool
1314
}
1415

1516
func run(cfg runConfig) error {
@@ -20,7 +21,7 @@ func run(cfg runConfig) error {
2021
if cluster == nil {
2122
return errors.Errorf("cluster '%s/%s/%s' not found", cfg.project, cfg.location, cfg.name)
2223
}
23-
if err = gke.RefreshCluster(cluster); err != nil {
24+
if err = gke.RefreshCluster(cluster, cfg.recreate); err != nil {
2425
return err
2526
}
2627
log.Printf("INFO: cluster '%s' has been refreshed!", cfg.name)

cmd/vm/pause/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ This command require '--zone' and '--project' flags.`,
3333

3434
cmd.Flags().StringVarP(&runCfg.zone, "zone", "z", "asia-southeast1-b", "the instance's zone")
3535
cmd.Flags().StringVarP(&runCfg.project, "project", "p", "", "the project where contain the instance")
36+
cmd.Flags().BoolVar(&runCfg.terminate, "terminate", false, "terminate the instance or suspend otherwise")
3637
return cmd
3738
}

cmd/vm/pause/run.go

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

99
type runConfig struct {
10-
project string
11-
zone string
12-
name string
10+
project string
11+
zone string
12+
name string
13+
terminate bool
1314
}
1415

1516
func run(cfg runConfig) error {
@@ -21,7 +22,7 @@ func run(cfg runConfig) error {
2122
return errors.Errorf("instance '%s/%s/%s' not found", cfg.project, cfg.zone, cfg.name)
2223
}
2324

24-
if err = vm.StopInstance(instance, false); err != nil {
25+
if err = vm.StopInstance(instance, cfg.terminate); err != nil {
2526
return err
2627
}
2728
log.Printf("INFO: instance %s has been stopped!", instance.GetName())

pkg/gcloud/gke/gke.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ type instanceGroup struct {
272272
IsManaged string `json:"isManaged,omitempty"`
273273
}
274274

275-
func RefreshCluster(cluster *apis.Cluster) error {
275+
func RefreshCluster(cluster *apis.Cluster, recreate bool) error {
276276
var refresh = func(project string, ig instanceGroup) error {
277277
if ig.IsManaged != "Yes" {
278278
log.Printf("INFO: instance group %s has been ignored becase it's not managed\n", ig.Name)
@@ -285,6 +285,11 @@ func RefreshCluster(cluster *apis.Cluster) error {
285285
location = ig.Region
286286
}
287287

288+
var replaceMethod = "substitute"
289+
if recreate {
290+
replaceMethod = "recreate"
291+
}
292+
288293
_, err := exec.Run(exec.Command("gcloud",
289294
"compute",
290295
"instance-groups",
@@ -294,7 +299,7 @@ func RefreshCluster(cluster *apis.Cluster) error {
294299
ig.Name,
295300
"--project", project,
296301
locationFlag, location,
297-
"--replacement-method", "recreate",
302+
"--replacement-method", replaceMethod,
298303
"--max-surge", "0",
299304
"--max-unavailable", "1"))
300305
if err != nil {

0 commit comments

Comments
 (0)