diff --git a/pkg/model/bootstrapscript.go b/pkg/model/bootstrapscript.go index cc71e6d4abf06..5c0cb993d6023 100644 --- a/pkg/model/bootstrapscript.go +++ b/pkg/model/bootstrapscript.go @@ -108,31 +108,34 @@ func (b *BootstrapScript) buildEnvironmentVariables(cluster *kops.Cluster) (map[ env["S3_SECRET_ACCESS_KEY"] = os.Getenv("S3_SECRET_ACCESS_KEY") } - osEnvs := []string{ - "OS_TENANT_ID", "OS_TENANT_NAME", "OS_PROJECT_ID", "OS_PROJECT_NAME", - "OS_PROJECT_DOMAIN_NAME", "OS_PROJECT_DOMAIN_ID", - "OS_DOMAIN_NAME", "OS_DOMAIN_ID", - "OS_AUTH_URL", - "OS_REGION_NAME", - } + if usesOpenStack(cluster) { + + osEnvs := []string{ + "OS_TENANT_ID", "OS_TENANT_NAME", "OS_PROJECT_ID", "OS_PROJECT_NAME", + "OS_PROJECT_DOMAIN_NAME", "OS_PROJECT_DOMAIN_ID", + "OS_DOMAIN_NAME", "OS_DOMAIN_ID", + "OS_AUTH_URL", + "OS_REGION_NAME", + } - if os.Getenv("OS_APPLICATION_CREDENTIAL_ID") != "" && os.Getenv("OS_APPLICATION_CREDENTIAL_SECRET") != "" { - osEnvs = append(osEnvs, - "OS_APPLICATION_CREDENTIAL_ID", - "OS_APPLICATION_CREDENTIAL_SECRET", - ) - } else { - klog.Warning("exporting username and password. Consider using application credentials instead.") - osEnvs = append(osEnvs, - "OS_USERNAME", - "OS_PASSWORD", - ) - } + if os.Getenv("OS_APPLICATION_CREDENTIAL_ID") != "" && os.Getenv("OS_APPLICATION_CREDENTIAL_SECRET") != "" { + osEnvs = append(osEnvs, + "OS_APPLICATION_CREDENTIAL_ID", + "OS_APPLICATION_CREDENTIAL_SECRET", + ) + } else { + klog.Warning("exporting username and password. Consider using application credentials instead.") + osEnvs = append(osEnvs, + "OS_USERNAME", + "OS_PASSWORD", + ) + } - // Pass in required credentials when using user-defined swift endpoint - if os.Getenv("OS_AUTH_URL") != "" { - for _, envVar := range osEnvs { - env[envVar] = fmt.Sprintf("'%s'", os.Getenv(envVar)) + // Pass in required credentials when using user-defined swift endpoint + if os.Getenv("OS_AUTH_URL") != "" { + for _, envVar := range osEnvs { + env[envVar] = fmt.Sprintf("'%s'", os.Getenv(envVar)) + } } } @@ -511,3 +514,27 @@ func (b *BootstrapScript) createProxyEnv(ps *kops.EgressProxySpec) string { } return buffer.String() } + +func usesOpenStack(cluster *kops.Cluster) bool { + if kops.CloudProviderID(cluster.Spec.CloudProvider) == kops.CloudProviderOpenstack { + return true + } + if strings.HasPrefix(cluster.Spec.SecretStore, "swift://") { + return true + } + if strings.HasPrefix(cluster.Spec.KeyStore, "swift://") { + return true + } + if strings.HasPrefix(cluster.Spec.ConfigStore, "swift://") { + return true + } + for _, c := range cluster.Spec.EtcdClusters { + if c.Backups == nil { + return true + } + if strings.HasPrefix(c.Backups.BackupStore, "swift://") { + return true + } + } + return false +}