From 674e91e53c5d0e65518cb5539afe034bae636d63 Mon Sep 17 00:00:00 2001 From: Michael Beaumont Date: Fri, 27 Sep 2019 13:22:35 +0200 Subject: [PATCH] Properly tag images with digest when using helm --- pkg/skaffold/deploy/helm.go | 11 +++++++++-- pkg/skaffold/deploy/helm_test.go | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/skaffold/deploy/helm.go b/pkg/skaffold/deploy/helm.go index 5248864474f..4e1482b2270 100644 --- a/pkg/skaffold/deploy/helm.go +++ b/pkg/skaffold/deploy/helm.go @@ -411,6 +411,13 @@ func getImageSetValueFromHelmStrategy(cfg *latest.HelmConventionConfig, valueNam return "", errors.Wrapf(err, "cannot parse the image reference %s", tag) } + var imageTag string + if dockerRef.Digest != "" { + imageTag = fmt.Sprintf("%s@%s", dockerRef.Tag, dockerRef.Digest) + } else { + imageTag = dockerRef.Tag + } + if cfg.ExplicitRegistry { if dockerRef.Domain == "" { return "", errors.New(fmt.Sprintf("image reference %s has no domain", tag)) @@ -420,13 +427,13 @@ func getImageSetValueFromHelmStrategy(cfg *latest.HelmConventionConfig, valueNam valueName, dockerRef.Domain, dockerRef.Path, - dockerRef.Tag, + imageTag, ), nil } return fmt.Sprintf( "%[1]s.repository=%[2]s,%[1]s.tag=%[3]s", valueName, dockerRef.BaseName, - dockerRef.Tag, + imageTag, ), nil } return fmt.Sprintf("%s=%s", valueName, tag), nil diff --git a/pkg/skaffold/deploy/helm_test.go b/pkg/skaffold/deploy/helm_test.go index acafb5e01d7..3d2e39c862b 100644 --- a/pkg/skaffold/deploy/helm_test.go +++ b/pkg/skaffold/deploy/helm_test.go @@ -728,6 +728,14 @@ func TestGetImageSetValueFromHelmStrategy(t *testing.T) { }, shouldErr: true, }, + { + description: "Helm set values using digest", + valueName: "image", + tag: "skaffold-helm:stable@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2", + expected: "image.repository=skaffold-helm,image.tag=stable@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2", + strategy: &latest.HelmConventionConfig{}, + shouldErr: false, + }, } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) {