diff --git a/cmd/werf/bundle/apply/apply.go b/cmd/werf/bundle/apply/apply.go index 72e9c6494a..3b83f05cf3 100644 --- a/cmd/werf/bundle/apply/apply.go +++ b/cmd/werf/bundle/apply/apply.go @@ -139,7 +139,7 @@ func runApply(ctx context.Context) error { helm_v3.Settings.Debug = *commonCmdData.LogDebug - helmRegistryClientHandle, err := common.NewHelmRegistryClientHandle(ctx, &commonCmdData) + helmRegistryClient, err := common.NewHelmRegistryClient(ctx, *commonCmdData.DockerConfig, *commonCmdData.InsecureHelmDependencies) if err != nil { return fmt.Errorf("unable to create helm registry client: %w", err) } @@ -150,7 +150,7 @@ func runApply(ctx context.Context) error { } actionConfig := new(action.Configuration) - if err := helm.InitActionConfig(ctx, common.GetOndemandKubeInitializer(), *commonCmdData.Namespace, helm_v3.Settings, helmRegistryClientHandle, actionConfig, helm.InitActionConfigOptions{ + if err := helm.InitActionConfig(ctx, common.GetOndemandKubeInitializer(), *commonCmdData.Namespace, helm_v3.Settings, actionConfig, helm.InitActionConfigOptions{ StatusProgressPeriod: time.Duration(*commonCmdData.StatusProgressPeriodSeconds) * time.Second, HooksStatusProgressPeriod: time.Duration(*commonCmdData.HooksStatusProgressPeriodSeconds) * time.Second, KubeConfigOptions: kube.KubeConfigOptions{ @@ -160,6 +160,7 @@ func runApply(ctx context.Context) error { ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }, ReleasesHistoryMax: *commonCmdData.ReleasesHistoryMax, + RegistryClient: helmRegistryClient, }); err != nil { return err } @@ -190,7 +191,7 @@ func runApply(ctx context.Context) error { secretsManager := secrets_manager.NewSecretsManager(secrets_manager.SecretsManagerOptions{DisableSecretsDecryption: *commonCmdData.IgnoreSecretKey}) - bundle, err := chart_extender.NewBundle(ctx, bundleTmpDir, helm_v3.Settings, helmRegistryClientHandle, secretsManager, chart_extender.BundleOptions{ + bundle, err := chart_extender.NewBundle(ctx, bundleTmpDir, helm_v3.Settings, helmRegistryClient, secretsManager, chart_extender.BundleOptions{ SecretValueFiles: common.GetSecretValues(&commonCmdData), BuildChartDependenciesOpts: command_helpers.BuildChartDependenciesOptions{IgnoreInvalidAnnotationsAndLabels: true}, IgnoreInvalidAnnotationsAndLabels: true, diff --git a/cmd/werf/bundle/export/export.go b/cmd/werf/bundle/export/export.go index 3a90895807..3957e8c6c9 100644 --- a/cmd/werf/bundle/export/export.go +++ b/cmd/werf/bundle/export/export.go @@ -312,12 +312,12 @@ func runExport(ctx context.Context, imagesToProcess build.ImagesToProcess) error logboek.LogOptionalLn() } - helmRegistryClientHandle, err := common.NewHelmRegistryClientHandle(ctx, &commonCmdData) + helmRegistryClient, err := common.NewHelmRegistryClient(ctx, *commonCmdData.DockerConfig, *commonCmdData.InsecureHelmDependencies) if err != nil { return fmt.Errorf("unable to create helm registry client: %w", err) } - wc := chart_extender.NewWerfChart(ctx, giterminismManager, nil, chartDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.WerfChartOptions{ + wc := chart_extender.NewWerfChart(ctx, giterminismManager, nil, chartDir, helm_v3.Settings, helmRegistryClient, chart_extender.WerfChartOptions{ ExtraAnnotations: userExtraAnnotations, ExtraLabels: userExtraLabels, IgnoreInvalidAnnotationsAndLabels: true, diff --git a/cmd/werf/bundle/publish/publish.go b/cmd/werf/bundle/publish/publish.go index a5628ef817..7bccf7dfac 100644 --- a/cmd/werf/bundle/publish/publish.go +++ b/cmd/werf/bundle/publish/publish.go @@ -317,7 +317,7 @@ func runPublish(ctx context.Context, imagesToProcess build.ImagesToProcess) erro logboek.LogOptionalLn() } - helmRegistryClientHandle, err := common.NewHelmRegistryClientHandle(ctx, &commonCmdData) + helmRegistryClient, err := common.NewHelmRegistryClient(ctx, *commonCmdData.DockerConfig, *commonCmdData.InsecureHelmDependencies) if err != nil { return err } @@ -327,7 +327,7 @@ func runPublish(ctx context.Context, imagesToProcess build.ImagesToProcess) erro return err } - wc := chart_extender.NewWerfChart(ctx, giterminismManager, nil, chartDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.WerfChartOptions{ + wc := chart_extender.NewWerfChart(ctx, giterminismManager, nil, chartDir, helm_v3.Settings, helmRegistryClient, chart_extender.WerfChartOptions{ ExtraAnnotations: userExtraAnnotations, ExtraLabels: userExtraLabels, IgnoreInvalidAnnotationsAndLabels: true, diff --git a/cmd/werf/bundle/render/render.go b/cmd/werf/bundle/render/render.go index 02264fe16b..2e8a076bb9 100644 --- a/cmd/werf/bundle/render/render.go +++ b/cmd/werf/bundle/render/render.go @@ -144,13 +144,13 @@ func runRender(ctx context.Context) error { helm_v3.Settings.Debug = *commonCmdData.LogDebug - helmRegistryClientHandle, err := common.NewHelmRegistryClientHandle(ctx, &commonCmdData) + helmRegistryClient, err := common.NewHelmRegistryClient(ctx, *commonCmdData.DockerConfig, *commonCmdData.InsecureHelmDependencies) if err != nil { return fmt.Errorf("unable to create helm registry client: %w", err) } actionConfig := new(action.Configuration) - if err := helm.InitActionConfig(ctx, nil, *commonCmdData.Namespace, helm_v3.Settings, helmRegistryClientHandle, actionConfig, helm.InitActionConfigOptions{}); err != nil { + if err := helm.InitActionConfig(ctx, nil, *commonCmdData.Namespace, helm_v3.Settings, actionConfig, helm.InitActionConfigOptions{RegistryClient: helmRegistryClient}); err != nil { return err } @@ -189,7 +189,7 @@ func runRender(ctx context.Context) error { secretsManager := secrets_manager.NewSecretsManager(secrets_manager.SecretsManagerOptions{DisableSecretsDecryption: *commonCmdData.IgnoreSecretKey}) - bundle, err := chart_extender.NewBundle(ctx, bundleDir, helm_v3.Settings, helmRegistryClientHandle, secretsManager, chart_extender.BundleOptions{ + bundle, err := chart_extender.NewBundle(ctx, bundleDir, helm_v3.Settings, helmRegistryClient, secretsManager, chart_extender.BundleOptions{ SecretValueFiles: common.GetSecretValues(&commonCmdData), BuildChartDependenciesOpts: command_helpers.BuildChartDependenciesOptions{IgnoreInvalidAnnotationsAndLabels: false}, IgnoreInvalidAnnotationsAndLabels: false, diff --git a/cmd/werf/common/helm.go b/cmd/werf/common/helm.go index e289fbf9fb..4a06650f26 100644 --- a/cmd/werf/common/helm.go +++ b/cmd/werf/common/helm.go @@ -2,11 +2,8 @@ package common import ( "context" - "path/filepath" "time" - "github.com/docker/cli/cli/config" - "github.com/docker/docker/pkg/homedir" helm_v3 "helm.sh/helm/v3/cmd/helm" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/registry" @@ -15,18 +12,33 @@ import ( "github.com/werf/logboek" bundles_registry "github.com/werf/werf/pkg/deploy/bundles/registry" "github.com/werf/werf/pkg/deploy/helm" + "github.com/werf/werf/pkg/docker" "github.com/werf/werf/pkg/util" ) -func NewHelmRegistryClientHandle(ctx context.Context, commonCmdData *CmdData) (*registry.Client, error) { +func NewHelmRegistryClient(ctx context.Context, dockerConfig string, insecureHelmDependencies bool) (*registry.Client, error) { + client, err := NewHelmRegistryClientWithoutInit(ctx) + if err != nil { + return nil, err + } + + InitHelmRegistryClient(client, dockerConfig, insecureHelmDependencies) + + return client, nil +} + +func NewHelmRegistryClientWithoutInit(ctx context.Context) (*registry.Client, error) { return registry.NewClient( - registry.ClientOptCredentialsFile(getDockerConfigCredentialsFile(*commonCmdData.DockerConfig)), registry.ClientOptDebug(logboek.Context(ctx).Debug().IsAccepted()), - registry.ClientOptInsecure(*commonCmdData.InsecureHelmDependencies), registry.ClientOptWriter(logboek.Context(ctx).OutStream()), ) } +func InitHelmRegistryClient(registryClient *registry.Client, dockerConfig string, insecureHelmDependencies bool) { + registry.ClientOptCredentialsFile(docker.GetDockerConfigCredentialsFile(dockerConfig))(registryClient) + registry.ClientOptInsecure(insecureHelmDependencies)(registryClient) +} + func NewBundlesRegistryClient(ctx context.Context, commonCmdData *CmdData) (*bundles_registry.Client, error) { debug := logboek.Context(ctx).Debug().IsAccepted() insecure := util.GetBoolEnvironmentDefaultFalse("WERF_BUNDLE_INSECURE_REGISTRY") @@ -34,7 +46,7 @@ func NewBundlesRegistryClient(ctx context.Context, commonCmdData *CmdData) (*bun out := logboek.Context(ctx).OutStream() return bundles_registry.NewClient( - bundles_registry.ClientOptCredentialsFile(getDockerConfigCredentialsFile(*commonCmdData.DockerConfig)), + bundles_registry.ClientOptCredentialsFile(docker.GetDockerConfigCredentialsFile(*commonCmdData.DockerConfig)), bundles_registry.ClientOptDebug(debug), bundles_registry.ClientOptInsecure(insecure), bundles_registry.ClientOptSkipTlsVerify(skipTlsVerify), @@ -42,18 +54,10 @@ func NewBundlesRegistryClient(ctx context.Context, commonCmdData *CmdData) (*bun ) } -func getDockerConfigCredentialsFile(configDir string) string { - if configDir == "" { - return filepath.Join(homedir.Get(), ".docker", config.ConfigFileName) - } else { - return filepath.Join(configDir, config.ConfigFileName) - } -} - func NewActionConfig(ctx context.Context, kubeInitializer helm.KubeInitializer, namespace string, commonCmdData *CmdData, registryClient *registry.Client) (*action.Configuration, error) { actionConfig := new(action.Configuration) - if err := helm.InitActionConfig(ctx, kubeInitializer, namespace, helm_v3.Settings, registryClient, actionConfig, helm.InitActionConfigOptions{ + if err := helm.InitActionConfig(ctx, kubeInitializer, namespace, helm_v3.Settings, actionConfig, helm.InitActionConfigOptions{ StatusProgressPeriod: time.Duration(*commonCmdData.StatusProgressPeriodSeconds) * time.Second, HooksStatusProgressPeriod: time.Duration(*commonCmdData.HooksStatusProgressPeriodSeconds) * time.Second, KubeConfigOptions: kube.KubeConfigOptions{ @@ -63,6 +67,7 @@ func NewActionConfig(ctx context.Context, kubeInitializer helm.KubeInitializer, ConfigPathMergeList: *commonCmdData.KubeConfigPathMergeList, }, ReleasesHistoryMax: *commonCmdData.ReleasesHistoryMax, + RegistryClient: registryClient, }); err != nil { return nil, err } diff --git a/cmd/werf/converge/converge.go b/cmd/werf/converge/converge.go index d85d7c483d..2905ad9d7e 100644 --- a/cmd/werf/converge/converge.go +++ b/cmd/werf/converge/converge.go @@ -381,12 +381,12 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken lockManager = m } - helmRegistryClientHandle, err := common.NewHelmRegistryClientHandle(ctx, &commonCmdData) + helmRegistryClient, err := common.NewHelmRegistryClient(ctx, *commonCmdData.DockerConfig, *commonCmdData.InsecureHelmDependencies) if err != nil { return fmt.Errorf("unable to create helm registry client: %w", err) } - wc := chart_extender.NewWerfChart(ctx, giterminismManager, secretsManager, chartDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.WerfChartOptions{ + wc := chart_extender.NewWerfChart(ctx, giterminismManager, secretsManager, chartDir, helm_v3.Settings, helmRegistryClient, chart_extender.WerfChartOptions{ SecretValueFiles: common.GetSecretValues(&commonCmdData), ExtraAnnotations: userExtraAnnotations, ExtraLabels: userExtraLabels, @@ -435,17 +435,17 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken FileValues: common.GetSetFile(&commonCmdData), } - actionConfig, err := common.NewActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, &commonCmdData, helmRegistryClientHandle) + actionConfig, err := common.NewActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, &commonCmdData, helmRegistryClient) if err != nil { return err } maintenanceHelper := createMaintenanceHelper(ctx, actionConfig, kubeConfigOptions) - if err := migrateHelm2ToHelm3(ctx, releaseName, namespace, maintenanceHelper, wc.ChainPostRenderer, valueOpts, filepath.Join(giterminismManager.ProjectDir(), chartDir), helmRegistryClientHandle); err != nil { + if err := migrateHelm2ToHelm3(ctx, releaseName, namespace, maintenanceHelper, wc.ChainPostRenderer, valueOpts, filepath.Join(giterminismManager.ProjectDir(), chartDir), helmRegistryClient); err != nil { return err } - actionConfig, err = common.NewActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, &commonCmdData, helmRegistryClientHandle) + actionConfig, err = common.NewActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, &commonCmdData, helmRegistryClient) if err != nil { return err } diff --git a/cmd/werf/dismiss/dismiss.go b/cmd/werf/dismiss/dismiss.go index e5ffc5977c..b345330fb8 100644 --- a/cmd/werf/dismiss/dismiss.go +++ b/cmd/werf/dismiss/dismiss.go @@ -204,12 +204,12 @@ func runDismiss(ctx context.Context) error { return fmt.Errorf("getting helm chart dir failed: %w", err) } - helmRegistryClientHandle, err := common.NewHelmRegistryClientHandle(ctx, &commonCmdData) + helmRegistryClient, err := common.NewHelmRegistryClient(ctx, *commonCmdData.DockerConfig, *commonCmdData.InsecureHelmDependencies) if err != nil { return fmt.Errorf("unable to create helm registry client: %w", err) } - wc := chart_extender.NewWerfChart(ctx, giterminismManager, nil, chartDir, helm_v3.Settings, helmRegistryClientHandle, chart_extender.WerfChartOptions{ + wc := chart_extender.NewWerfChart(ctx, giterminismManager, nil, chartDir, helm_v3.Settings, helmRegistryClient, chart_extender.WerfChartOptions{ IgnoreInvalidAnnotationsAndLabels: true, }) @@ -221,7 +221,7 @@ func runDismiss(ctx context.Context) error { } actionConfig := new(action.Configuration) - if err := helm.InitActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, helm_v3.Settings, helmRegistryClientHandle, actionConfig, helm.InitActionConfigOptions{ + if err := helm.InitActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, helm_v3.Settings, actionConfig, helm.InitActionConfigOptions{ StatusProgressPeriod: time.Duration(*commonCmdData.StatusProgressPeriodSeconds) * time.Second, HooksStatusProgressPeriod: time.Duration(*commonCmdData.HooksStatusProgressPeriodSeconds) * time.Second, KubeConfigOptions: kube.KubeConfigOptions{ @@ -230,6 +230,7 @@ func runDismiss(ctx context.Context) error { ConfigDataBase64: *commonCmdData.KubeConfigBase64, }, ReleasesHistoryMax: *commonCmdData.ReleasesHistoryMax, + RegistryClient: helmRegistryClient, }); err != nil { return err } diff --git a/cmd/werf/helm/helm.go b/cmd/werf/helm/helm.go index cc7bb7d0d3..0635ad134f 100644 --- a/cmd/werf/helm/helm.go +++ b/cmd/werf/helm/helm.go @@ -36,10 +36,8 @@ func IsHelm3Mode() bool { return os.Getenv("WERF_HELM3_MODE") == "1" } -func NewCmd(ctx context.Context) *cobra.Command { +func NewCmd(ctx context.Context) (*cobra.Command, error) { var namespace string - actionConfig := new(action.Configuration) - ctx = common.NewContextWithCmdData(ctx, &_commonCmdData) cmd := common.SetCommandContext(ctx, &cobra.Command{ Use: "helm", @@ -47,6 +45,14 @@ func NewCmd(ctx context.Context) *cobra.Command { SilenceUsage: true, }) + registryClient, err := common.NewHelmRegistryClientWithoutInit(ctx) + if err != nil { + return nil, fmt.Errorf("unable to create helm registry client: %w", err) + } + + actionConfig := new(action.Configuration) + actionConfig.RegistryClient = registryClient + wc := chart_extender.NewWerfChartStub(ctx, false) loader.GlobalLoadOptions = &loader.LoadOptions{ @@ -164,14 +170,11 @@ func NewCmd(ctx context.Context) *cobra.Command { wc.SetStubServiceValues(vals) } - common.SetupOndemandKubeInitializer(*_commonCmdData.KubeContext, *_commonCmdData.KubeConfig, *_commonCmdData.KubeConfigBase64, *_commonCmdData.KubeConfigPathMergeList) + common.InitHelmRegistryClient(registryClient, *_commonCmdData.DockerConfig, *_commonCmdData.InsecureHelmDependencies) - helmRegistryClientHandle, err := common.NewHelmRegistryClientHandle(ctx, &_commonCmdData) - if err != nil { - return fmt.Errorf("unable to create helm registry client: %w", err) - } + common.SetupOndemandKubeInitializer(*_commonCmdData.KubeContext, *_commonCmdData.KubeConfig, *_commonCmdData.KubeConfigBase64, *_commonCmdData.KubeConfigPathMergeList) - helm.InitActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, helm_v3.Settings, helmRegistryClientHandle, actionConfig, helm.InitActionConfigOptions{ + helm.InitActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, helm_v3.Settings, actionConfig, helm.InitActionConfigOptions{ StatusProgressPeriod: time.Duration(*_commonCmdData.StatusProgressPeriodSeconds) * time.Second, HooksStatusProgressPeriod: time.Duration(*_commonCmdData.HooksStatusProgressPeriodSeconds) * time.Second, KubeConfigOptions: kube.KubeConfigOptions{ @@ -200,7 +203,7 @@ func NewCmd(ctx context.Context) *cobra.Command { cmd.PersistentFlags().Parse(os.Args[1:]) } - return cmd + return cmd, nil } func secretCmd(ctx context.Context) *cobra.Command { diff --git a/cmd/werf/helm/install.go b/cmd/werf/helm/install.go index cbf1edb39a..8d9fffc256 100644 --- a/cmd/werf/helm/install.go +++ b/cmd/werf/helm/install.go @@ -5,7 +5,7 @@ import ( "os" "github.com/spf13/cobra" - "helm.sh/helm/v3/cmd/helm" + helm_v3 "helm.sh/helm/v3/cmd/helm" "helm.sh/helm/v3/pkg/action" "github.com/werf/werf/cmd/werf/common" diff --git a/cmd/werf/helm/migrate2to3.go b/cmd/werf/helm/migrate2to3.go index c787cc45ec..fb321dc96c 100644 --- a/cmd/werf/helm/migrate2to3.go +++ b/cmd/werf/helm/migrate2to3.go @@ -134,13 +134,16 @@ func runMigrate2To3(ctx context.Context) error { ConfigPathMergeList: *migrate2To3CommonCmdData.KubeConfigPathMergeList, } - helmRegistryClientHandler, err := common.NewHelmRegistryClientHandle(ctx, &migrate2To3CommonCmdData) + helmRegistryClient, err := common.NewHelmRegistryClient(ctx, *migrate2To3CommonCmdData.DockerConfig, *migrate2To3CommonCmdData.InsecureHelmDependencies) if err != nil { return fmt.Errorf("unable to create helm registry client: %w", err) } actionConfig := new(action.Configuration) - if err := helm.InitActionConfig(ctx, common.GetOndemandKubeInitializer(), targetNamespace, helm_v3.Settings, helmRegistryClientHandler, actionConfig, helm.InitActionConfigOptions{KubeConfigOptions: kubeConfigOptions}); err != nil { + if err := helm.InitActionConfig(ctx, common.GetOndemandKubeInitializer(), targetNamespace, helm_v3.Settings, actionConfig, helm.InitActionConfigOptions{ + KubeConfigOptions: kubeConfigOptions, + RegistryClient: helmRegistryClient, + }); err != nil { return err } diff --git a/cmd/werf/main.go b/cmd/werf/main.go index 1d0c87fe56..36f01917d3 100644 --- a/cmd/werf/main.go +++ b/cmd/werf/main.go @@ -72,7 +72,11 @@ func main() { common.TerminateWithError(fmt.Sprintf("process exterminator initialization failed: %s", err), 1) } - rootCmd := constructRootCmd(ctx) + rootCmd, err := constructRootCmd(ctx) + if err != nil { + common.ShutdownTelemetry(ctx, 1) + common.TerminateWithError(err.Error(), 1) + } setupTelemetryInit(rootCmd) @@ -89,9 +93,14 @@ func main() { common.ShutdownTelemetry(ctx, 0) } -func constructRootCmd(ctx context.Context) *cobra.Command { +func constructRootCmd(ctx context.Context) (*cobra.Command, error) { + helmCmd, err := helm.NewCmd(ctx) + if err != nil { + return nil, fmt.Errorf("unable to init helm commands: %w", err) + } + if filepath.Base(os.Args[0]) == "helm" || helm.IsHelm3Mode() { - return helm.NewCmd(ctx) + return helmCmd, nil } rootCmd := common.SetCommandContext(ctx, &cobra.Command{ @@ -140,7 +149,7 @@ Find more information at https://werf.io`), configCmd(ctx), managedImagesCmd(ctx), hostCmd(ctx), - helm.NewCmd(ctx), + helmCmd, crCmd(ctx), kubectl.NewCmd(ctx), }, @@ -160,7 +169,7 @@ Find more information at https://werf.io`), templates.ActsAsRootCommand(rootCmd, *groups...) - return rootCmd + return rootCmd, nil } func dockerComposeCmd(ctx context.Context) *cobra.Command { diff --git a/cmd/werf/render/render.go b/cmd/werf/render/render.go index 7de3a4101b..a82ad2641d 100644 --- a/cmd/werf/render/render.go +++ b/cmd/werf/render/render.go @@ -363,12 +363,12 @@ func runRender(ctx context.Context, imagesToProcess build.ImagesToProcess) error secretsManager := secrets_manager.NewSecretsManager(secrets_manager.SecretsManagerOptions{DisableSecretsDecryption: *commonCmdData.IgnoreSecretKey}) - helmRegistryClientHandler, err := common.NewHelmRegistryClientHandle(ctx, &commonCmdData) + helmRegistryClient, err := common.NewHelmRegistryClient(ctx, *commonCmdData.DockerConfig, *commonCmdData.InsecureHelmDependencies) if err != nil { return fmt.Errorf("unable to create helm registry client: %w", err) } - wc := chart_extender.NewWerfChart(ctx, giterminismManager, secretsManager, chartDir, helm_v3.Settings, helmRegistryClientHandler, chart_extender.WerfChartOptions{ + wc := chart_extender.NewWerfChart(ctx, giterminismManager, secretsManager, chartDir, helm_v3.Settings, helmRegistryClient, chart_extender.WerfChartOptions{ SecretValueFiles: common.GetSecretValues(&commonCmdData), ExtraAnnotations: userExtraAnnotations, ExtraLabels: userExtraLabels, @@ -408,7 +408,7 @@ func runRender(ctx context.Context, imagesToProcess build.ImagesToProcess) error wc.SetServiceValues(vals) } - actionConfig, err := common.NewActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, &commonCmdData, helmRegistryClientHandler) + actionConfig, err := common.NewActionConfig(ctx, common.GetOndemandKubeInitializer(), namespace, &commonCmdData, helmRegistryClient) if err != nil { return err } diff --git a/pkg/deploy/helm/init.go b/pkg/deploy/helm/init.go index aec26360d4..3e1d6d8d6c 100644 --- a/pkg/deploy/helm/init.go +++ b/pkg/deploy/helm/init.go @@ -27,9 +27,10 @@ type InitActionConfigOptions struct { HooksStatusProgressPeriod time.Duration KubeConfigOptions kube.KubeConfigOptions ReleasesHistoryMax int + RegistryClient *registry.Client } -func InitActionConfig(ctx context.Context, kubeInitializer KubeInitializer, namespace string, envSettings *cli.EnvSettings, registryClient *registry.Client, actionConfig *action.Configuration, opts InitActionConfigOptions) error { +func InitActionConfig(ctx context.Context, kubeInitializer KubeInitializer, namespace string, envSettings *cli.EnvSettings, actionConfig *action.Configuration, opts InitActionConfigOptions) error { configGetter, err := kube.NewKubeConfigGetter(kube.KubeConfigGetterOptions{ KubeConfigOptions: opts.KubeConfigOptions, Namespace: namespace, @@ -63,9 +64,12 @@ func InitActionConfig(ctx context.Context, kubeInitializer KubeInitializer, name kubeClient.ResourcesWaiter = NewResourcesWaiter(kubeInitializer, kubeClient, time.Now(), opts.StatusProgressPeriod, opts.HooksStatusProgressPeriod) kubeClient.Extender = NewHelmKubeClientExtender() - actionConfig.RegistryClient = registryClient actionConfig.Log = func(f string, a ...interface{}) { - logboek.Context(ctx).Default().LogFDetails(fmt.Sprintf("%s\n", f), a...) + logboek.Context(ctx).Info().LogFDetails(fmt.Sprintf("%s\n", f), a...) + } + + if opts.RegistryClient != nil { + actionConfig.RegistryClient = opts.RegistryClient } return nil diff --git a/pkg/docker/config.go b/pkg/docker/config.go new file mode 100644 index 0000000000..e28f9d5a0b --- /dev/null +++ b/pkg/docker/config.go @@ -0,0 +1,16 @@ +package docker + +import ( + "path/filepath" + + "github.com/docker/cli/cli/config" + "github.com/docker/docker/pkg/homedir" +) + +func GetDockerConfigCredentialsFile(configDir string) string { + if configDir == "" { + return filepath.Join(homedir.Get(), ".docker", config.ConfigFileName) + } else { + return filepath.Join(configDir, config.ConfigFileName) + } +}