diff --git a/pkg/utils/imagerefs/reference.go b/pkg/utils/imagerefs/reference.go index 09dd49d9..0808303e 100644 --- a/pkg/utils/imagerefs/reference.go +++ b/pkg/utils/imagerefs/reference.go @@ -35,16 +35,24 @@ func Parse(name string) (string, string, string, string, error) { named = reference.TagNameOnly(named) domain := reference.Domain(named) path := reference.Path(named) + + var tagOrDigest string tagged, ok := named.(reference.Tagged) if !ok { - return "", "", "", "", fmt.Errorf("reference is not tagged: %v, %s", named, name) + digested, ok := named.(reference.Digested) + if !ok { + return "", "", "", "", fmt.Errorf("reference is not tagged or digested: %v, %s", named, name) + } + tagOrDigest = digested.Digest().String() + } else { + tagOrDigest = tagged.Tag() } - tag := tagged.Tag() + if !strings.Contains(path, "/") { return "", "", "", "", fmt.Errorf("invalid reference: %s", name) } parts := strings.Split(path, "/") ns := parts[0] repo := path - return domain, ns, repo, tag, nil + return domain, ns, repo, tagOrDigest, nil } diff --git a/pkg/utils/imagerefs/reference_test.go b/pkg/utils/imagerefs/reference_test.go index f0b4e760..dc956b2c 100644 --- a/pkg/utils/imagerefs/reference_test.go +++ b/pkg/utils/imagerefs/reference_test.go @@ -88,6 +88,28 @@ func TestParse(t *testing.T) { }, { name: "test6", + args: args{ + name: "kubernetes-helm/test/tiller@sha256:4ca2a277f1dc3ddd0da33a258096de9a1cf5b9d9bd96b27ee78763ee2248c28c", + }, + want: "docker.io", + want1: "kubernetes-helm", + want2: "kubernetes-helm/test/tiller", + want3: "sha256:4ca2a277f1dc3ddd0da33a258096de9a1cf5b9d9bd96b27ee78763ee2248c28c", + wantErr: false, + }, + { + name: "test7", + args: args{ + name: "kubernetes-helm/test/tiller:v1@sha256:4ca2a277f1dc3ddd0da33a258096de9a1cf5b9d9bd96b27ee78763ee2248c28c", + }, + want: "docker.io", + want1: "kubernetes-helm", + want2: "kubernetes-helm/test/tiller", + want3: "v1", + wantErr: false, + }, + { + name: "test8", args: args{ name: "kubernetes-helm/test/tiller", }, @@ -98,7 +120,7 @@ func TestParse(t *testing.T) { wantErr: false, }, { - name: "test7", + name: "test9", args: args{ name: "busybox", },