Skip to content

Commit

Permalink
Merge pull request #330 from banzaicloud/fix-cluster-id
Browse files Browse the repository at this point in the history
cluster: don't bind current cluster id env var
  • Loading branch information
Máté Őry authored Nov 13, 2020
2 parents fb36609 + bf93c72 commit 8792d58
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/cli/command/cluster/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package clustercontext
import (
"context"
"fmt"
"os"

"emperror.dev/errors"
"github.com/AlecAivazis/survey/v2"
Expand Down Expand Up @@ -48,7 +49,6 @@ func NewClusterContext(cmd *cobra.Command, banzaiCli cli.Cli, verb string) Conte
flags := cmd.Flags()

flags.Int32Var(&ctx.id, "cluster", 0, fmt.Sprintf("ID of cluster to %s", verb))
viper.BindEnv(clusterIdKey, "BANZAI_CURRENT_CLUSTER_ID")
flags.StringVar(&ctx.name, "cluster-name", "", fmt.Sprintf("Name of cluster to %s", verb))

return &ctx
Expand Down Expand Up @@ -79,7 +79,12 @@ func (c *clusterContext) Init(args ...string) error {
return errors.New("invalid number of arguments")
}

if c.name == "" && c.id == 0 {
if id := os.Getenv("BANZAI_CURRENT_CLUSTER_ID"); id != "" {
_, err := fmt.Sscanf(id, "%d", &c.id)
if err != nil {
return errors.WrapIff(err, "invalid BANZAI_CURRENT_CLUSTER_ID=%q env var", id)
}
} else if c.name == "" && c.id == 0 {
c.id = viper.GetInt32(clusterIdKey)
}

Expand Down

0 comments on commit 8792d58

Please sign in to comment.