Skip to content

Commit

Permalink
created useHelmSecrets functionality to use helm secrets plugin if sp…
Browse files Browse the repository at this point in the history
…ecified in config
  • Loading branch information
rorymaidbot committed Mar 4, 2019
1 parent 6a829c4 commit 06c73d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
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

0 comments on commit 06c73d8

Please sign in to comment.