Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1178 helm secrets integration #1617

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/content/en/schemas/v1beta6.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1084,6 +1090,7 @@
"wait",
"recreatePods",
"skipBuildDependencies",
"useHelmSecrets",
"overrides",
"packaged",
"imageStrategy"
Expand Down
19 changes: 12 additions & 7 deletions pkg/skaffold/deploy/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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")
}
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,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).
Expand Down