Skip to content

Commit

Permalink
bug fix from @cloudtagger for namespace support in helm v3
Browse files Browse the repository at this point in the history
  • Loading branch information
ktarplee committed Feb 25, 2020
1 parent 58e8b0a commit d40639c
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions pkg/skaffold/deploy/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,21 @@ func (h *HelmDeployer) deployRelease(ctx context.Context, out io.Writer, r lates
}

isInstalled := true

var ns string
if h.namespace != "" {
ns = h.namespace
} else if r.Namespace != "" {
ns = r.Namespace
}
if helmV3 {
if err := h.helm(ctx, ioutil.Discard, false, "get", "all", releaseName); err != nil {
var installedArgs []string

installedArgs = append(installedArgs, "get", "all", releaseName)
if ns != "" {
installedArgs = append(installedArgs, "--namespace", ns)
}
if err := h.helm(ctx, ioutil.Discard, false, installedArgs...); err != nil {
color.Yellow.Fprintf(out, "Helm release %s not installed. Installing...\n", releaseName)
isInstalled = false
}
Expand Down Expand Up @@ -279,12 +292,6 @@ func (h *HelmDeployer) deployRelease(ctx context.Context, out io.Writer, r lates
args = append(args, chartPath)
}

var ns string
if h.namespace != "" {
ns = h.namespace
} else if r.Namespace != "" {
ns = r.Namespace
}
if ns != "" {
args = append(args, "--namespace", ns)
}
Expand Down Expand Up @@ -442,7 +449,7 @@ func (h *HelmDeployer) packageChart(ctx context.Context, r latest.HelmRelease) (
return filepath.Join(tmp, fpath), nil
}

func (h *HelmDeployer) getReleaseInfo(ctx context.Context, release string) (*bufio.Reader, error) {
func (h *HelmDeployer) getReleaseInfo(ctx context.Context, release string, namespace string) (*bufio.Reader, error) {

helmV3, err := h.isHelmV3(ctx)
if err != nil {
Expand All @@ -451,7 +458,12 @@ func (h *HelmDeployer) getReleaseInfo(ctx context.Context, release string) (*buf

var releaseInfo bytes.Buffer
if helmV3 {
if err := h.helm(ctx, &releaseInfo, false, "get", "all", release); err != nil {
var installedArgs []string
installedArgs = append(installedArgs, "get", "all", release)
if namespace != "" {
installedArgs = append(installedArgs, "--namespace", namespace)
}
if err := h.helm(ctx, &releaseInfo, false, installedArgs...); err != nil {
return nil, fmt.Errorf("error retrieving helm deployment info: %s", releaseInfo.String())
}
} else {
Expand Down Expand Up @@ -501,7 +513,7 @@ func getImageSetValueFromHelmStrategy(cfg *latest.HelmConventionConfig, valueNam
// Skaffold labels will be applied to each deployed k8s object
// Since helm isn't always consistent with retrieving results, don't return errors here
func (h *HelmDeployer) getDeployResults(ctx context.Context, namespace string, release string) []Artifact {
b, err := h.getReleaseInfo(ctx, release)
b, err := h.getReleaseInfo(ctx, release, namespace)
if err != nil {
logrus.Warnf(err.Error())
return nil
Expand All @@ -522,6 +534,16 @@ func (h *HelmDeployer) deleteRelease(ctx context.Context, out io.Writer, r lates
args := []string{"delete", releaseName}
if !helmV3 {
args = append(args, "--purge")
} else {
var ns string
if h.namespace != "" {
ns = h.namespace
} else if r.Namespace != "" {
ns = r.Namespace
}
if ns != "" {
args = append(args, "--namespace", ns)
}
}
if err := h.helm(ctx, out, false, args...); err != nil {
logrus.Debugf("deleting release %s: %v\n", releaseName, err)
Expand Down

0 comments on commit d40639c

Please sign in to comment.