Skip to content

Commit b5eafcd

Browse files
nkubalayuwenma
authored andcommitted
Remove support for Helm 2 (GoogleContainerTools#5019)
remove const var kustomizeFurtherGuidance
1 parent 416804a commit b5eafcd

File tree

4 files changed

+161
-141
lines changed

4 files changed

+161
-141
lines changed

pkg/skaffold/deploy/helm/helm.go

+29-27
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,22 @@ func NewDeployer(cfg kubectl.Config, labels map[string]string) *Deployer {
107107
}
108108
}
109109

110+
func (h *Deployer) checkMinVersion(v semver.Version) error {
111+
if v.LT(helm3Version) {
112+
return fmt.Errorf("skaffold requires Helm version 3.0.0-beta.0 or greater")
113+
}
114+
return nil
115+
}
116+
110117
// Deploy deploys the build results to the Kubernetes cluster
111118
func (h *Deployer) Deploy(ctx context.Context, out io.Writer, builds []build.Artifact) ([]string, error) {
112119
hv, err := h.binVer(ctx)
113120
if err != nil {
114121
return nil, fmt.Errorf(versionErrorString, err)
115122
}
123+
if err = h.checkMinVersion(hv); err != nil {
124+
return nil, err
125+
}
116126

117127
logrus.Infof("Deploying with helm v%s ...", hv)
118128

@@ -187,15 +197,14 @@ func (h *Deployer) Dependencies() ([]string, error) {
187197

188198
lockFiles := []string{
189199
"Chart.lock",
190-
"requirements.lock",
191200
}
192201

193202
// We can always add a dependency if it is not contained in our chartDepsDirs.
194203
// However, if the file is in our chartDepsDir, we can only include the file
195204
// if we are not running the helm dep build phase, as that modifies files inside
196205
// the chartDepsDir and results in an infinite build loop.
197-
// We additionally exclude ChartFile.lock (Helm 3) and requirements.lock (Helm 2)
198-
// since they also get modified on helm dep build phase
206+
// We additionally exclude ChartFile.lock,
207+
// since it also gets modified during a `helm dep build`.
199208
isDep := func(path string, info walk.Dirent) (bool, error) {
200209
if info.IsDir() {
201210
return false, nil
@@ -233,6 +242,9 @@ func (h *Deployer) Cleanup(ctx context.Context, out io.Writer) error {
233242
if err != nil {
234243
return fmt.Errorf(versionErrorString, err)
235244
}
245+
if err = h.checkMinVersion(hv); err != nil {
246+
return err
247+
}
236248

237249
for _, r := range h.Releases {
238250
releaseName, err := util.ExpandEnvTemplate(r.Name, nil)
@@ -246,9 +258,7 @@ func (h *Deployer) Cleanup(ctx context.Context, out io.Writer) error {
246258
}
247259

248260
args := []string{"delete", releaseName}
249-
if hv.LT(helm3Version) {
250-
args = append(args, "--purge")
251-
} else if namespace != "" {
261+
if namespace != "" {
252262
args = append(args, "--namespace", namespace)
253263
}
254264
if err := h.exec(ctx, out, false, nil, args...); err != nil {
@@ -264,18 +274,16 @@ func (h *Deployer) Render(ctx context.Context, out io.Writer, builds []build.Art
264274
if err != nil {
265275
return fmt.Errorf(versionErrorString, err)
266276
}
277+
if err = h.checkMinVersion(hv); err != nil {
278+
return err
279+
}
267280

268281
renderedManifests := new(bytes.Buffer)
269282

270283
for _, r := range h.Releases {
271284
args := []string{"template", r.ChartPath}
272285

273-
if hv.GTE(helm3Version) {
274-
// Helm 3 requires the name to be before the chart path
275-
args = append(args[:1], append([]string{r.Name}, args[1:]...)...)
276-
} else {
277-
args = append(args, "--name", r.Name)
278-
}
286+
args = append(args[:1], append([]string{r.Name}, args[1:]...)...)
279287

280288
for _, vf := range r.ValuesFiles {
281289
args = append(args, "--values", vf)
@@ -399,7 +407,7 @@ func (h *Deployer) deployRelease(ctx context.Context, out io.Writer, r latest.He
399407
return nil, err
400408
}
401409

402-
if err := h.exec(ctx, ioutil.Discard, false, nil, getArgs(helmVersion, releaseName, opts.namespace)...); err != nil {
410+
if err := h.exec(ctx, ioutil.Discard, false, nil, getArgs(releaseName, opts.namespace)...); err != nil {
403411
color.Yellow.Fprintf(out, "Helm release %s not installed. Installing...\n", releaseName)
404412

405413
opts.upgrade = false
@@ -458,7 +466,7 @@ func (h *Deployer) deployRelease(ctx context.Context, out io.Writer, r latest.He
458466
return nil, fmt.Errorf("install: %w", err)
459467
}
460468

461-
b, err := h.getRelease(ctx, helmVersion, releaseName, opts.namespace)
469+
b, err := h.getRelease(ctx, releaseName, opts.namespace)
462470
if err != nil {
463471
return nil, fmt.Errorf("get release: %w", err)
464472
}
@@ -468,15 +476,15 @@ func (h *Deployer) deployRelease(ctx context.Context, out io.Writer, r latest.He
468476
}
469477

470478
// getRelease confirms that a release is visible to helm
471-
func (h *Deployer) getRelease(ctx context.Context, helmVersion semver.Version, releaseName string, namespace string) (bytes.Buffer, error) {
472-
// Retry, because under Helm 2, at least, a release may not be immediately visible
479+
func (h *Deployer) getRelease(ctx context.Context, releaseName string, namespace string) (bytes.Buffer, error) {
480+
// Retry, because sometimes a release may not be immediately visible
473481
opts := backoff.NewExponentialBackOff()
474482
opts.MaxElapsedTime = 4 * time.Second
475483
var b bytes.Buffer
476484

477485
err := backoff.Retry(
478486
func() error {
479-
if err := h.exec(ctx, &b, false, nil, getArgs(helmVersion, releaseName, namespace)...); err != nil {
487+
if err := h.exec(ctx, &b, false, nil, getArgs(releaseName, namespace)...); err != nil {
480488
logrus.Debugf("unable to get release: %v (may retry):\n%s", err, b.String())
481489
return err
482490
}
@@ -543,9 +551,6 @@ func installArgs(r latest.HelmRelease, builds []build.Artifact, valuesSet map[st
543551
}
544552
} else {
545553
args = append(args, "install")
546-
if o.helmVersion.LT(helm3Version) {
547-
args = append(args, "--name")
548-
}
549554
args = append(args, o.releaseName)
550555
args = append(args, o.flags...)
551556
}
@@ -686,13 +691,10 @@ func sortKeys(m map[string]string) []string {
686691
}
687692

688693
// getArgs calculates the correct arguments to "helm get"
689-
func getArgs(v semver.Version, releaseName string, namespace string) []string {
690-
args := []string{"get"}
691-
if v.GTE(helm3Version) {
692-
args = append(args, "all")
693-
if namespace != "" {
694-
args = append(args, "--namespace", namespace)
695-
}
694+
func getArgs(releaseName string, namespace string) []string {
695+
args := []string{"get", "all"}
696+
if namespace != "" {
697+
args = append(args, "--namespace", namespace)
696698
}
697699
return append(args, releaseName)
698700
}

0 commit comments

Comments
 (0)