Skip to content

Commit

Permalink
Handle err when importing k8s context
Browse files Browse the repository at this point in the history
- print command execution errors to stderr
  • Loading branch information
arunvelsriram committed Mar 26, 2019
1 parent e35dd16 commit 686f5fe
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions pkg/commander/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Default struct{}
// Execute executes a command on the actual machine
func (d *Default) Execute(cmdStr string, args []string, envs []string) (string, error) {
cmd := exec.Command(cmdStr, args...)
cmd.Stderr = os.Stderr
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, envs...)
out, err := cmd.Output()
Expand Down
2 changes: 0 additions & 2 deletions pkg/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func (k *KubeConfig) AddRegionalCluster(project string, cluster string, region s
fmt.Sprintf("--project=%s", project),
}
envs := []string{
"CLOUDSDK_CONTAINER_USE_V1_API_CLIENT=false",
"CLOUDSDK_CONTAINER_USE_V1_API=false",
fmt.Sprintf("KUBECONFIG=%s", kubeCfgFile),
}
if _, err := k.commander.Execute("gcloud", args, envs); err != nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/kubeconfig/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ func TestAddRegionalCluster(t *testing.T) {
"--project=test-project",
}
envs := []string{
"CLOUDSDK_CONTAINER_USE_V1_API_CLIENT=false",
"CLOUDSDK_CONTAINER_USE_V1_API=false",
"KUBECONFIG=/Users/test/.kube/configs/test-context",
}
mockCmdr.EXPECT().Execute("gcloud", args, envs).Return("Context added successfully", nil)
Expand Down Expand Up @@ -135,8 +133,6 @@ func TestAddRegionalCluster(t *testing.T) {
"--project=test-project",
}
envs := []string{
"CLOUDSDK_CONTAINER_USE_V1_API_CLIENT=false",
"CLOUDSDK_CONTAINER_USE_V1_API=false",
"KUBECONFIG=/Users/test/.kube/configs/test-context",
}
mockCmdr.EXPECT().Execute("gcloud", args, envs).Return("", fmt.Errorf("some error"))
Expand Down
8 changes: 6 additions & 2 deletions pkg/kubetmuxp/kubetmuxp.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,13 @@ func (c *Config) Process() error {
if regional, err := cluster.IsRegional(); err != nil {
return err
} else if regional {
c.kubeCfg.AddRegionalCluster(project.Name, cluster.Name, cluster.Region, kubeCfgFile)
if err := c.kubeCfg.AddRegionalCluster(project.Name, cluster.Name, cluster.Region, kubeCfgFile); err != nil {
return err
}
} else {
c.kubeCfg.AddZonalCluster(project.Name, cluster.Name, cluster.Zone, kubeCfgFile)
if err := c.kubeCfg.AddZonalCluster(project.Name, cluster.Name, cluster.Zone, kubeCfgFile); err != nil {
return err
}
}

fmt.Println("Renaming context...")
Expand Down

0 comments on commit 686f5fe

Please sign in to comment.