diff --git a/cmd/werf/cleanup/cleanup.go b/cmd/werf/cleanup/cleanup.go index 2b7492b736..525b547126 100644 --- a/cmd/werf/cleanup/cleanup.go +++ b/cmd/werf/cleanup/cleanup.go @@ -125,9 +125,10 @@ func runCleanup() error { ctx = ctxWithDockerCli if err := kube.Init(kube.InitOptions{KubeConfigOptions: kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }}); err != nil { return fmt.Errorf("cannot initialize kube: %s", err) } diff --git a/cmd/werf/common/cleanup_namespaces_scan.go b/cmd/werf/common/cleanup_namespaces_scan.go index eb98bfa61e..cd62548758 100644 --- a/cmd/werf/common/cleanup_namespaces_scan.go +++ b/cmd/werf/common/cleanup_namespaces_scan.go @@ -15,7 +15,11 @@ func SetupScanContextNamespaceOnly(cmdData *CmdData, cmd *cobra.Command) { func GetKubernetesContextClients(cmdData *CmdData) ([]*kube.ContextClient, error) { var res []*kube.ContextClient - if contextClients, err := kube.GetAllContextsClients(kube.GetAllContextsClientsOptions{KubeConfig: *cmdData.KubeConfig}); err != nil { + if contextClients, err := kube.GetAllContextsClients(kube.GetAllContextsClientsOptions{ + ConfigPath: *cmdData.KubeConfig, + ConfigDataBase64: *cmdData.KubeConfigBase64, + ConfigPathMergeList: *cmdData.KubeConfigPathMergeList, + }); err != nil { return nil, err } else { if *cmdData.KubeContext != "" { diff --git a/cmd/werf/common/common.go b/cmd/werf/common/common.go index 7bbe0af2ec..7d056cf82f 100644 --- a/cmd/werf/common/common.go +++ b/cmd/werf/common/common.go @@ -56,6 +56,7 @@ type CmdData struct { KubeContext *string KubeConfig *string KubeConfigBase64 *string + KubeConfigPathMergeList *[]string HelmReleaseStorageNamespace *string HelmReleaseStorageType *string StatusProgressPeriodSeconds *int64 @@ -300,7 +301,13 @@ func SetupKubeContext(cmdData *CmdData, cmd *cobra.Command) { func SetupKubeConfig(cmdData *CmdData, cmd *cobra.Command) { cmdData.KubeConfig = new(string) - cmd.PersistentFlags().StringVarP(cmdData.KubeConfig, "kube-config", "", getFirstExistingEnvVarAsString("WERF_KUBE_CONFIG", "WERF_KUBECONFIG", "KUBECONFIG"), "Kubernetes config file path (default $WERF_KUBE_CONFIG or $WERF_KUBECONFIG or $KUBECONFIG)") + cmd.PersistentFlags().StringVarP(cmdData.KubeConfig, "kube-config", "", "", "Kubernetes config file path (default $WERF_KUBE_CONFIG, or $WERF_KUBECONFIG, or $KUBECONFIG)") + + cmdData.KubeConfigPathMergeList = new([]string) + kubeConfigPathMergeListStr := getFirstExistingEnvVarAsString("WERF_KUBE_CONFIG", "WERF_KUBECONFIG", "KUBECONFIG") + for _, path := range filepath.SplitList(kubeConfigPathMergeListStr) { + *cmdData.KubeConfigPathMergeList = append(*cmdData.KubeConfigPathMergeList, path) + } } func SetupKubeConfigBase64(cmdData *CmdData, cmd *cobra.Command) { diff --git a/cmd/werf/common/helm.go b/cmd/werf/common/helm.go index 525eef307b..8886a08faf 100644 --- a/cmd/werf/common/helm.go +++ b/cmd/werf/common/helm.go @@ -21,9 +21,10 @@ func NewActionConfig(ctx context.Context, namespace string, commonCmdData *CmdDa StatusProgressPeriod: time.Duration(*commonCmdData.StatusProgressPeriodSeconds) * time.Second, HooksStatusProgressPeriod: time.Duration(*commonCmdData.HooksStatusProgressPeriodSeconds) * time.Second, KubeConfigOptions: kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }, ReleasesHistoryMax: *commonCmdData.ReleasesHistoryMax, }); err != nil { diff --git a/cmd/werf/converge/converge.go b/cmd/werf/converge/converge.go index 2a1348478b..393963114b 100644 --- a/cmd/werf/converge/converge.go +++ b/cmd/werf/converge/converge.go @@ -236,9 +236,10 @@ func runConverge() error { } kubeConfigOptions := kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, } if err := kube.Init(kube.InitOptions{KubeConfigOptions: kubeConfigOptions}); err != nil { diff --git a/cmd/werf/deploy/main.go b/cmd/werf/deploy/main.go index bb546d3f49..85fe2b1d81 100644 --- a/cmd/werf/deploy/main.go +++ b/cmd/werf/deploy/main.go @@ -190,9 +190,10 @@ func runDeploy() error { ctx = ctxWithDockerCli kubeConfigOptions := kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, } if err := kube.Init(kube.InitOptions{KubeConfigOptions: kubeConfigOptions}); err != nil { diff --git a/cmd/werf/deploy_v2/main.go b/cmd/werf/deploy_v2/main.go index 69b88cad80..fa4ad79711 100644 --- a/cmd/werf/deploy_v2/main.go +++ b/cmd/werf/deploy_v2/main.go @@ -176,9 +176,10 @@ func runDeploy() error { } if err := kube.Init(kube.InitOptions{KubeConfigOptions: kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }}); err != nil { return fmt.Errorf("cannot initialize kube: %s", err) } diff --git a/cmd/werf/diff/diff.go b/cmd/werf/diff/diff.go index cae96bfa19..98847a6f0b 100644 --- a/cmd/werf/diff/diff.go +++ b/cmd/werf/diff/diff.go @@ -257,9 +257,10 @@ func runDiff() error { } if err := kube.Init(kube.InitOptions{kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }}); err != nil { return fmt.Errorf("cannot initialize kube: %s", err) } diff --git a/cmd/werf/dismiss/dismiss.go b/cmd/werf/dismiss/dismiss.go index 0d44d506cb..a2d9c0b387 100644 --- a/cmd/werf/dismiss/dismiss.go +++ b/cmd/werf/dismiss/dismiss.go @@ -153,9 +153,10 @@ func runDismiss() error { projectName := werfConfig.Meta.Project err = kube.Init(kube.InitOptions{kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }}) if err != nil { return fmt.Errorf("cannot initialize kube: %s", err) diff --git a/cmd/werf/dismiss_v2/dismiss.go b/cmd/werf/dismiss_v2/dismiss.go index f975831df8..cb8df70c2f 100644 --- a/cmd/werf/dismiss_v2/dismiss.go +++ b/cmd/werf/dismiss_v2/dismiss.go @@ -136,9 +136,10 @@ func runDismiss() error { logboek.LogOptionalLn() err = kube.Init(kube.InitOptions{kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }}) if err != nil { return fmt.Errorf("cannot initialize kube: %s", err) diff --git a/cmd/werf/helm/deploy_chart/main.go b/cmd/werf/helm/deploy_chart/main.go index b8f2f3f448..a20bb464a0 100644 --- a/cmd/werf/helm/deploy_chart/main.go +++ b/cmd/werf/helm/deploy_chart/main.go @@ -149,9 +149,10 @@ func runDeployChart(chartDirOrChartReference string, releaseName string) error { } if err := kube.Init(kube.InitOptions{kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }}); err != nil { return fmt.Errorf("cannot initialize kube: %s", err) } diff --git a/cmd/werf/helm/rollback/rollback.go b/cmd/werf/helm/rollback/rollback.go index 8f6523304b..a2252c5481 100644 --- a/cmd/werf/helm/rollback/rollback.go +++ b/cmd/werf/helm/rollback/rollback.go @@ -103,9 +103,10 @@ func runRollback(releaseName string, revision int32) error { } if err := kube.Init(kube.InitOptions{kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }}); err != nil { return fmt.Errorf("cannot initialize kube: %s", err) } diff --git a/cmd/werf/helm_v3/helm_v3.go b/cmd/werf/helm_v3/helm_v3.go index 99f5763057..c56251852e 100644 --- a/cmd/werf/helm_v3/helm_v3.go +++ b/cmd/werf/helm_v3/helm_v3.go @@ -103,9 +103,10 @@ func NewCmd() *cobra.Command { ctx := common.BackgroundContext() if err := kube.Init(kube.InitOptions{kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }}); err != nil { return fmt.Errorf("cannot initialize kube: %s", err) } diff --git a/cmd/werf/images/cleanup/cleanup.go b/cmd/werf/images/cleanup/cleanup.go index f8343b6308..92dae5511f 100644 --- a/cmd/werf/images/cleanup/cleanup.go +++ b/cmd/werf/images/cleanup/cleanup.go @@ -118,9 +118,10 @@ func runCleanup() error { ctx = ctxWithDockerCli if err := kube.Init(kube.InitOptions{KubeConfigOptions: kube.KubeConfigOptions{ - Context: *commonCmdData.KubeContext, - ConfigPath: *commonCmdData.KubeConfig, - ConfigDataBase64: *commonCmdData.KubeConfigBase64, + Context: *commonCmdData.KubeContext, + ConfigPath: *commonCmdData.KubeConfig, + ConfigDataBase64: *commonCmdData.KubeConfigBase64, + ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }}); err != nil { return fmt.Errorf("cannot initialize kube: %s", err) } diff --git a/go.mod b/go.mod index 35c005b87a..76f1e6bf7f 100644 --- a/go.mod +++ b/go.mod @@ -62,7 +62,7 @@ require ( github.com/theupdateframework/notary v0.6.1 // indirect github.com/tonistiigi/fsutil v0.0.0-20200724193237-c3ed55f3b481 // indirect github.com/tonistiigi/go-rosetta v0.0.0-20200727161949-f79598599c5d // indirect - github.com/werf/kubedog v0.4.1-0.20210609160549-c5ed5d787e86 + github.com/werf/kubedog v0.4.1-0.20220222103049-afc67463c609 github.com/werf/lockgate v0.0.0-20200729113342-ec2c142f71ea github.com/werf/logboek v0.4.7 github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect diff --git a/go.sum b/go.sum index aba1f573d9..8a45e5d5a8 100644 --- a/go.sum +++ b/go.sum @@ -1533,6 +1533,8 @@ github.com/werf/kubedog v0.4.1-0.20210604070304-fde5b6c69f6a h1:S9uj3JDE0i/Ux+DS github.com/werf/kubedog v0.4.1-0.20210604070304-fde5b6c69f6a/go.mod h1:7SuLhuQddKnJri0LiMPoch94b6zAor7X3GvcufmgLqY= github.com/werf/kubedog v0.4.1-0.20210609160549-c5ed5d787e86 h1:o+Xy3n9Kvme9wfalydgcRYv3Tjk/fIoLb5/BQOyhpd8= github.com/werf/kubedog v0.4.1-0.20210609160549-c5ed5d787e86/go.mod h1:7SuLhuQddKnJri0LiMPoch94b6zAor7X3GvcufmgLqY= +github.com/werf/kubedog v0.4.1-0.20220222103049-afc67463c609 h1:gH8Zjx49Ze2YT7qgEYYnR+amdQUZeaZCaEQTGJ4HiRk= +github.com/werf/kubedog v0.4.1-0.20220222103049-afc67463c609/go.mod h1:7SuLhuQddKnJri0LiMPoch94b6zAor7X3GvcufmgLqY= github.com/werf/lockgate v0.0.0-20200729113342-ec2c142f71ea h1:R5tJUhL5a3YfHTrHWyuAdJW3h//fmONrpHJjjAZ79e4= github.com/werf/lockgate v0.0.0-20200729113342-ec2c142f71ea/go.mod h1:/CeY6KDiBSCU9PUmjt7zGhqpzp8FAPg/wNVfLZHQGWI= github.com/werf/logboek v0.4.3 h1:aXAVLlGT/ZiD8Srj+B71Tw20PtDyuYZSEJZjODNraeA= diff --git a/pkg/deploy/helm/client_getter_from_data.go b/pkg/deploy/helm/client_getter_from_data.go index ff30e8e757..9b5389f7f1 100644 --- a/pkg/deploy/helm/client_getter_from_data.go +++ b/pkg/deploy/helm/client_getter_from_data.go @@ -71,6 +71,6 @@ func (getter *ClientGetterFromConfigData) getRawKubeConfigLoader() (clientcmd.Cl if data, err := base64.StdEncoding.DecodeString(getter.ConfigDataBase64); err != nil { return nil, fmt.Errorf("unable to decode base64 config data: %s", err) } else { - return kube.GetClientConfig(getter.Context, "", data) + return kube.GetClientConfig(getter.Context, "", data, []string{}) } } diff --git a/pkg/deploy/helm/tiller.go b/pkg/deploy/helm/tiller.go index 1eb062904a..5bb9b9b540 100644 --- a/pkg/deploy/helm/tiller.go +++ b/pkg/deploy/helm/tiller.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "os" "regexp" "strings" "text/tabwriter" @@ -89,7 +90,9 @@ func loadChartfile(chartPath string) (*chart.Chart, error) { } type InitOptions struct { - KubeConfig string + KubeConfig string + // We are using WERF_KUBE_CONFIG, WERF_KUBECONFIG and KUBECONFIG variables directly at this level (1.1 only) + // KubeConfigPathMergeList []string KubeConfigBase64 string KubeContext string HelmReleaseStorageNamespace string @@ -119,6 +122,15 @@ func Init(ctx context.Context, options InitOptions) error { } HelmSettings.KubeConfig = options.KubeConfig + + // Make sure WERF_KUBE_CONFIG and WERF_KUBECONFIG variables with config path merge list are supported + for _, env := range []string{"WERF_KUBE_CONFIG", "WERF_KUBECONFIG"} { + if v := os.Getenv(env); v != "" { + os.Setenv("KUBECONFIG", v) + break + } + } + HelmSettings.KubeContext = options.KubeContext HelmSettings.TillerNamespace = options.HelmReleaseStorageNamespace