Fix appending SHA256 hash to image reference in ImageWithDigest (#1784)

This commit is contained in:
Michal Vinkler 2023-06-06 21:01:26 +02:00 committed by GitHub
parent 75a8b8991d
commit 109e6b6be8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -472,6 +472,12 @@ func (f Function) ImageWithDigest() string {
return f.Image
}
// Return image with new Digest if image already contains SHA256 Digest
shaIndex := strings.Index(f.Image, "@sha256:")
if shaIndex > 0 {
return f.Image[:shaIndex] + "@" + f.ImageDigest
}
lastSlashIdx := strings.LastIndexAny(f.Image, "/")
imageAsBytes := []byte(f.Image)

View File

@ -105,6 +105,16 @@ func TestFunction_ImageWithDigest(t *testing.T) {
fields: fields{Image: "bar:latest", ImageDigest: "42"},
want: "bar@42",
},
{
name: "Full path with port and SHA256 Digest",
fields: fields{Image: "image-registry.openshift-image-registry.svc.cluster.local:50000/default/bar@sha256:42", ImageDigest: "sha256:42"},
want: "image-registry.openshift-image-registry.svc.cluster.local:50000/default/bar@sha256:42",
},
{
name: "Full path with port and SHA256 Digest with empty ImageDigest",
fields: fields{Image: "image-registry.openshift-image-registry.svc.cluster.local:50000/default/bar@sha256:42", ImageDigest: ""},
want: "image-registry.openshift-image-registry.svc.cluster.local:50000/default/bar@sha256:42",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {