Skip to content

Commit

Permalink
fix: resolve issue where skaffold would not add digest when using hel…
Browse files Browse the repository at this point in the history
…m in v1 -> v2 migration case
  • Loading branch information
aaron-prindle committed Dec 21, 2022
1 parent b166d34 commit a9cfb67
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion integration/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestHelmDeploy(t *testing.T) {
skaffold.Delete().InDir("testdata/helm").InNs(ns.Name).WithEnv(env).RunOrFail(t)
}

func TestDevHelmMultiConfig(t *testing.T) {
func TestRunHelmMultiConfig(t *testing.T) {
var tests = []struct {
description string
dir string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ manifests:
createNamespace: true
name: app1
setValueTemplates:
image.repository: '{{.IMAGE_REPO_app1}}'
image.tag: "{{.IMAGE_TAG_app1}}"
image.repository: "{{.IMAGE_REPO_app1}}"
image.tag: "{{.IMAGE_TAG_app1}}@{{.IMAGE_DIGEST_app1}}"
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ manifests:
createNamespace: true
name: app2
setValueTemplates:
image.repository: '{{.IMAGE_REPO_app2}}'
image.tag: "{{.IMAGE_TAG_app2}}"
image.repository: "{{.IMAGE_REPO_app2}}"
image.tag: "{{.IMAGE_TAG_app2}}@{{.IMAGE_DIGEST_app2}}"
8 changes: 8 additions & 0 deletions pkg/skaffold/helm/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ func ConstructOverrideArgs(r *latest.HelmRelease, builds []graph.Artifact, args
return nil, err
}

// hack required when using new Skaffold v2.X.Y setValueTemplates w/ Skaffold v1.X.Y "imageStrategy: helm"
// ex: image: "{{.Values.image.repository}}:{{.Values.image.tag}}"
// when the helm template replacements are done with `dev` and `run` there
// is an additional `@` suffix inserted that needs to be removed or else deploys will fail
if strings.HasPrefix(expandedKey, "IMAGE_") {
v = strings.TrimSuffix(v, "@")
}

args = append(args, "--set", fmt.Sprintf("%s=%s", expandedKey, v))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/schema/v2beta29/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func upgradeOnePipeline(oldPipeline, newPipeline interface{}) error {
if svts == nil {
svts = map[string]string{}
}
svts[k+".tag"] = fmt.Sprintf("{{.IMAGE_TAG_%s}}", validV)
svts[k+".tag"] = fmt.Sprintf("{{.IMAGE_TAG_%s}}@{{.IMAGE_DIGEST_%s}}", validV, validV)
svts[k+".repository"] = fmt.Sprintf("{{.IMAGE_REPO_%s}}", validV)
if oldPL.Deploy.HelmDeploy.Releases[i].ImageStrategy.HelmConventionConfig.ExplicitRegistry {
// is 'helm' imageStrategy + explicitRegistry
Expand Down

0 comments on commit a9cfb67

Please sign in to comment.