Skip to content

Commit

Permalink
Set KUBE_CONFIG_PATH just for environment applier methods (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
poornima-krishnasamy committed Jul 13, 2023
1 parent 724a581 commit 95cffed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 0 additions & 5 deletions pkg/commands/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ func addEnvironmentCmd(topLevel *cobra.Command) {
environmentPlanCmd.Flags().StringVar(&optFlags.ClusterCtx, "cluster", "", "folder name under namespaces/ inside cloud-platform-environments repo refering to full cluster name")
environmentPlanCmd.PersistentFlags().BoolVar(&optFlags.RedactedEnv, "redact", true, "Redact the terraform output before printing")

// Set KUBE_CONFIG_PATH to the path of the kubeconfig file
// This is needed for terraform to be able to connect to the cluster
if err := os.Setenv("KUBE_CONFIG_PATH", optFlags.KubecfgPath); err != nil {
log.Fatal(err)
}
}

var environmentCmd = &cobra.Command{
Expand Down
10 changes: 10 additions & 0 deletions pkg/environment/environmentApply.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (a *Apply) Initialize() {
a.RequiredEnvVars.githubowner = reqEnvVars.githubowner
a.RequiredEnvVars.githubtoken = reqEnvVars.githubtoken
a.RequiredEnvVars.pingdomapitoken = reqEnvVars.pingdomapitoken
// Set KUBE_CONFIG_PATH to the path of the kubeconfig file
// This is needed for terraform to be able to connect to the cluster when a different kubecfg is passed
if err := os.Setenv("KUBE_CONFIG_PATH", a.Options.KubecfgPath); err != nil {
log.Fatalln("KUBE_CONFIG_PATH environment variable cant be set:", err.Error())
}
}

// Plan is the entry point for performing a namespace plan.
Expand Down Expand Up @@ -416,6 +421,11 @@ func (a *Apply) applyNamespace() error {
}

exists, err := util.IsFilePathExists(repoPath + "/resources")
// Set KUBE_CONFIG_PATH to the path of the kubeconfig file
// This is needed for terraform to be able to connect to the cluster when a different kubecfg is passed
if err := os.Setenv("KUBE_CONFIG_PATH", a.Options.KubecfgPath); err != nil {
return err
}
if err == nil && exists {
outputTerraform, err := applier.applyTerraform()
if err != nil {
Expand Down

0 comments on commit 95cffed

Please sign in to comment.