mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Implement support for digests in imageTags
This commit adds a new field to imageTags transformer so that digests can be used instead of image tags if needed. Closes https://github.com/kubernetes-sigs/kustomize/issues/326
This commit is contained in:
@@ -18,7 +18,6 @@ package transformers
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/kubernetes-sigs/kustomize/pkg/resmap"
|
||||
"github.com/kubernetes-sigs/kustomize/pkg/types"
|
||||
@@ -83,7 +82,12 @@ func (pt *imageTagTransformer) updateContainers(obj map[string]interface{}, path
|
||||
}
|
||||
for _, imagetag := range pt.imageTags {
|
||||
if isImageMatched(image.(string), imagetag.Name) {
|
||||
container["image"] = strings.Join([]string{imagetag.Name, imagetag.NewTag}, ":")
|
||||
container["image"] = imagetag.Name + ":" + imagetag.NewTag
|
||||
|
||||
if imagetag.Digest != "" {
|
||||
container["image"] = imagetag.Name + "@" + imagetag.Digest
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ func TestImageTagTransformer(t *testing.T) {
|
||||
"name": "nginx",
|
||||
"image": "nginx:1.7.9",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "replaced-with-digest",
|
||||
"image": "foobar:1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -114,6 +118,10 @@ func TestImageTagTransformer(t *testing.T) {
|
||||
"name": "nginx",
|
||||
"image": "nginx:v2",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "replaced-with-digest",
|
||||
"image": "foobar@sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -160,6 +168,7 @@ func TestImageTagTransformer(t *testing.T) {
|
||||
{Name: "nginx", NewTag: "v2"},
|
||||
{Name: "my-nginx", NewTag: "previous"},
|
||||
{Name: "myprivaterepohostname:1234/my/image", NewTag: "v1.0.1"},
|
||||
{Name: "foobar", Digest: "sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user