Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Support parse tag with digest #216

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pkg/utils/imagerefs/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,24 @@
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)
}

Check warning on line 45 in pkg/utils/imagerefs/reference.go

View check run for this annotation

Codecov / codecov/patch

pkg/utils/imagerefs/reference.go#L44-L45

Added lines #L44 - L45 were not covered by tests
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
}
24 changes: 23 additions & 1 deletion pkg/utils/imagerefs/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -98,7 +120,7 @@ func TestParse(t *testing.T) {
wantErr: false,
},
{
name: "test7",
name: "test9",
args: args{
name: "busybox",
},
Expand Down
Loading