@@ -107,12 +107,22 @@ func NewDeployer(cfg kubectl.Config, labels map[string]string) *Deployer {
107
107
}
108
108
}
109
109
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
+
110
117
// Deploy deploys the build results to the Kubernetes cluster
111
118
func (h * Deployer ) Deploy (ctx context.Context , out io.Writer , builds []build.Artifact ) ([]string , error ) {
112
119
hv , err := h .binVer (ctx )
113
120
if err != nil {
114
121
return nil , fmt .Errorf (versionErrorString , err )
115
122
}
123
+ if err = h .checkMinVersion (hv ); err != nil {
124
+ return nil , err
125
+ }
116
126
117
127
logrus .Infof ("Deploying with helm v%s ..." , hv )
118
128
@@ -187,15 +197,14 @@ func (h *Deployer) Dependencies() ([]string, error) {
187
197
188
198
lockFiles := []string {
189
199
"Chart.lock" ,
190
- "requirements.lock" ,
191
200
}
192
201
193
202
// We can always add a dependency if it is not contained in our chartDepsDirs.
194
203
// However, if the file is in our chartDepsDir, we can only include the file
195
204
// if we are not running the helm dep build phase, as that modifies files inside
196
205
// 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`.
199
208
isDep := func (path string , info walk.Dirent ) (bool , error ) {
200
209
if info .IsDir () {
201
210
return false , nil
@@ -233,6 +242,9 @@ func (h *Deployer) Cleanup(ctx context.Context, out io.Writer) error {
233
242
if err != nil {
234
243
return fmt .Errorf (versionErrorString , err )
235
244
}
245
+ if err = h .checkMinVersion (hv ); err != nil {
246
+ return err
247
+ }
236
248
237
249
for _ , r := range h .Releases {
238
250
releaseName , err := util .ExpandEnvTemplate (r .Name , nil )
@@ -246,9 +258,7 @@ func (h *Deployer) Cleanup(ctx context.Context, out io.Writer) error {
246
258
}
247
259
248
260
args := []string {"delete" , releaseName }
249
- if hv .LT (helm3Version ) {
250
- args = append (args , "--purge" )
251
- } else if namespace != "" {
261
+ if namespace != "" {
252
262
args = append (args , "--namespace" , namespace )
253
263
}
254
264
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
264
274
if err != nil {
265
275
return fmt .Errorf (versionErrorString , err )
266
276
}
277
+ if err = h .checkMinVersion (hv ); err != nil {
278
+ return err
279
+ }
267
280
268
281
renderedManifests := new (bytes.Buffer )
269
282
270
283
for _ , r := range h .Releases {
271
284
args := []string {"template" , r .ChartPath }
272
285
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 :]... )... )
279
287
280
288
for _ , vf := range r .ValuesFiles {
281
289
args = append (args , "--values" , vf )
@@ -399,7 +407,7 @@ func (h *Deployer) deployRelease(ctx context.Context, out io.Writer, r latest.He
399
407
return nil , err
400
408
}
401
409
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 {
403
411
color .Yellow .Fprintf (out , "Helm release %s not installed. Installing...\n " , releaseName )
404
412
405
413
opts .upgrade = false
@@ -458,7 +466,7 @@ func (h *Deployer) deployRelease(ctx context.Context, out io.Writer, r latest.He
458
466
return nil , fmt .Errorf ("install: %w" , err )
459
467
}
460
468
461
- b , err := h .getRelease (ctx , helmVersion , releaseName , opts .namespace )
469
+ b , err := h .getRelease (ctx , releaseName , opts .namespace )
462
470
if err != nil {
463
471
return nil , fmt .Errorf ("get release: %w" , err )
464
472
}
@@ -468,15 +476,15 @@ func (h *Deployer) deployRelease(ctx context.Context, out io.Writer, r latest.He
468
476
}
469
477
470
478
// 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
473
481
opts := backoff .NewExponentialBackOff ()
474
482
opts .MaxElapsedTime = 4 * time .Second
475
483
var b bytes.Buffer
476
484
477
485
err := backoff .Retry (
478
486
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 {
480
488
logrus .Debugf ("unable to get release: %v (may retry):\n %s" , err , b .String ())
481
489
return err
482
490
}
@@ -543,9 +551,6 @@ func installArgs(r latest.HelmRelease, builds []build.Artifact, valuesSet map[st
543
551
}
544
552
} else {
545
553
args = append (args , "install" )
546
- if o .helmVersion .LT (helm3Version ) {
547
- args = append (args , "--name" )
548
- }
549
554
args = append (args , o .releaseName )
550
555
args = append (args , o .flags ... )
551
556
}
@@ -686,13 +691,10 @@ func sortKeys(m map[string]string) []string {
686
691
}
687
692
688
693
// 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 )
696
698
}
697
699
return append (args , releaseName )
698
700
}
0 commit comments