Skip to content

Commit

Permalink
update command
Browse files Browse the repository at this point in the history
Signed-off-by: vietanhduong <[email protected]>
  • Loading branch information
vietanhduong committed Jun 1, 2023
1 parent dda5646 commit 4e81290
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/gke/refresh/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Refresh all worker nodes in all node pools of the input cluster. This command ju

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

return cmd
}
3 changes: 2 additions & 1 deletion cmd/gke/refresh/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type runConfig struct {
name string
project string
location string
recreate bool
}

func run(cfg runConfig) error {
Expand All @@ -20,7 +21,7 @@ func run(cfg runConfig) error {
if cluster == nil {
return errors.Errorf("cluster '%s/%s/%s' not found", cfg.project, cfg.location, cfg.name)
}
if err = gke.RefreshCluster(cluster); err != nil {
if err = gke.RefreshCluster(cluster, cfg.recreate); err != nil {
return err
}
log.Printf("INFO: cluster '%s' has been refreshed!", cfg.name)
Expand Down
1 change: 1 addition & 0 deletions cmd/vm/pause/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ This command require '--zone' and '--project' flags.`,

cmd.Flags().StringVarP(&runCfg.zone, "zone", "z", "asia-southeast1-b", "the instance's zone")
cmd.Flags().StringVarP(&runCfg.project, "project", "p", "", "the project where contain the instance")
cmd.Flags().BoolVar(&runCfg.terminate, "terminate", false, "terminate the instance or suspend otherwise")
return cmd
}
9 changes: 5 additions & 4 deletions cmd/vm/pause/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
)

type runConfig struct {
project string
zone string
name string
project string
zone string
name string
terminate bool
}

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

if err = vm.StopInstance(instance, false); err != nil {
if err = vm.StopInstance(instance, cfg.terminate); err != nil {
return err
}
log.Printf("INFO: instance %s has been stopped!", instance.GetName())
Expand Down
9 changes: 7 additions & 2 deletions pkg/gcloud/gke/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ type instanceGroup struct {
IsManaged string `json:"isManaged,omitempty"`
}

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

var replaceMethod = "substitute"
if recreate {
replaceMethod = "recreate"
}

_, err := exec.Run(exec.Command("gcloud",
"compute",
"instance-groups",
Expand All @@ -294,7 +299,7 @@ func RefreshCluster(cluster *apis.Cluster) error {
ig.Name,
"--project", project,
locationFlag, location,
"--replacement-method", "recreate",
"--replacement-method", replaceMethod,
"--max-surge", "0",
"--max-unavailable", "1"))
if err != nil {
Expand Down

0 comments on commit 4e81290

Please sign in to comment.