diff --git a/docs/content/en/schemas/v1beta6.json b/docs/content/en/schemas/v1beta6.json index cdc96da81c4..14906e68769 100755 --- a/docs/content/en/schemas/v1beta6.json +++ b/docs/content/en/schemas/v1beta6.json @@ -1042,6 +1042,12 @@ "x-intellij-html-description": "should build dependencies be skipped.", "default": "false" }, + "useHelmSecrets": { + "type": "boolean", + "description": "instructs skaffold to use secrets plugin on deployment.", + "x-intellij-html-description": "instructs skaffold to use secrets plugin on deployment.", + "default": "false" + }, "values": { "additionalProperties": { "type": "string" @@ -1084,6 +1090,7 @@ "wait", "recreatePods", "skipBuildDependencies", + "useHelmSecrets", "overrides", "packaged", "imageStrategy" diff --git a/pkg/skaffold/deploy/helm.go b/pkg/skaffold/deploy/helm.go index 82944938e75..54764bd8814 100644 --- a/pkg/skaffold/deploy/helm.go +++ b/pkg/skaffold/deploy/helm.go @@ -140,10 +140,15 @@ func (h *HelmDeployer) Cleanup(ctx context.Context, out io.Writer) error { return nil } -func (h *HelmDeployer) helm(ctx context.Context, out io.Writer, arg ...string) error { +func (h *HelmDeployer) helm(ctx context.Context, out io.Writer, useSecrets bool, arg ...string) error { + args := append([]string{"--kube-context", h.kubeContext}, arg...) args = append(args, h.Flags.Global...) + if useSecrets { + args = append([]string{"secrets"}, args...) + } + cmd := exec.CommandContext(ctx, "helm", args...) cmd.Stdout = out cmd.Stderr = out @@ -158,7 +163,7 @@ func (h *HelmDeployer) deployRelease(ctx context.Context, out io.Writer, r lates if err != nil { return nil, errors.Wrap(err, "cannot parse the release name template") } - if err := h.helm(ctx, out, "get", releaseName); err != nil { + if err := h.helm(ctx, out, false, "get", releaseName); err != nil { color.Red.Fprintf(out, "Helm release %s not installed. Installing...\n", releaseName) isInstalled = false } @@ -185,7 +190,7 @@ func (h *HelmDeployer) deployRelease(ctx context.Context, out io.Writer, r lates if !r.SkipBuildDependencies { // First build dependencies. logrus.Infof("Building helm dependencies...") - if err := h.helm(ctx, out, "dep", "build", r.ChartPath); err != nil { + if err := h.helm(ctx, out, false, "dep", "build", r.ChartPath); err != nil { return nil, errors.Wrap(err, "building helm dependencies") } } @@ -291,7 +296,7 @@ func (h *HelmDeployer) deployRelease(ctx context.Context, out io.Writer, r lates } args = append(args, setOpts...) - helmErr := h.helm(ctx, out, args...) + helmErr := h.helm(ctx, out, r.UseHelmSecrets, args...) return h.getDeployResults(ctx, ns, releaseName), helmErr } @@ -346,7 +351,7 @@ func (h *HelmDeployer) packageChart(ctx context.Context, r latest.HelmRelease) ( } buf := &bytes.Buffer{} - err := h.helm(ctx, buf, packageArgs...) + err := h.helm(ctx, buf, false, packageArgs...) output := strings.TrimSpace(buf.String()) if err != nil { return "", errors.Wrapf(err, "package chart into a .tgz archive (%s)", output) @@ -362,7 +367,7 @@ func (h *HelmDeployer) packageChart(ctx context.Context, r latest.HelmRelease) ( func (h *HelmDeployer) getReleaseInfo(ctx context.Context, release string) (*bufio.Reader, error) { var releaseInfo bytes.Buffer - if err := h.helm(ctx, &releaseInfo, "get", release); err != nil { + if err := h.helm(ctx, &releaseInfo, false, "get", release); err != nil { return nil, fmt.Errorf("error retrieving helm deployment info: %s", releaseInfo.String()) } return bufio.NewReader(&releaseInfo), nil @@ -386,7 +391,7 @@ func (h *HelmDeployer) deleteRelease(ctx context.Context, out io.Writer, r lates return errors.Wrap(err, "cannot parse the release name template") } - if err := h.helm(ctx, out, "delete", releaseName, "--purge"); err != nil { + if err := h.helm(ctx, out, false, "delete", releaseName, "--purge"); err != nil { logrus.Debugf("deleting release %s: %v\n", releaseName, err) } diff --git a/pkg/skaffold/schema/latest/config.go b/pkg/skaffold/schema/latest/config.go index 4ad233a6338..4644cc960ea 100644 --- a/pkg/skaffold/schema/latest/config.go +++ b/pkg/skaffold/schema/latest/config.go @@ -417,6 +417,9 @@ type HelmRelease struct { // SkipBuildDependencies should build dependencies be skipped. SkipBuildDependencies bool `yaml:"skipBuildDependencies,omitempty"` + // UseHelmSecrets instructs skaffold to use secrets plugin on deployment. + UseHelmSecrets bool `yaml:"useHelmSecrets,omitempty"` + // Overrides are key-value pairs. // If present, Skaffold will build a Helm `values` file that overrides // the original and use it to call Helm CLI (`--f` flag).