Support pulling plugins by digest (#3803)

Previously `WithPlugins` only supported passing image URIs "by tag" --
e.g. `gcr.io/my-repo/my-image:v0.1.2`. With this commit, we add support
for pulling "by digest" -- e.g.
`gcr.io/my-repo/my-image@sha256:a75f9e8c3ced3943515f249597be389f8233e1258d289b11184796edceaa7dab`

Signed-off-by: Eric Fried <efried@redhat.com>
pull/3814/head
Eric Fried 2021-05-18 00:27:49 -05:00 committed by GitHub
parent 5601758723
commit 7566962b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View File

@ -0,0 +1 @@
Support pulling plugin images by digest

View File

@ -60,11 +60,18 @@ func getName(image string) string {
start = slashIndex + 1
}
// this removes the tag
colonIndex := strings.LastIndex(image, ":")
// If the image spec is by digest, remove the digest.
// If it is by tag, remove the tag.
// Otherwise (implicit :latest) leave it alone.
end := len(image)
if colonIndex > 0 {
end = colonIndex
atIndex := strings.LastIndex(image, "@")
if atIndex > 0 {
end = atIndex
} else {
colonIndex := strings.LastIndex(image, ":")
if colonIndex > 0 {
end = colonIndex
}
}
// https://github.com/distribution/distribution/blob/main/docs/spec/api.md#overview

View File

@ -87,6 +87,11 @@ func TestGetName(t *testing.T) {
image: "projects.registry.vmware.com/tanzu.migrator/route-2-httpproxy:myTag",
expected: "tanzu-migrator-route-2-httpproxy",
},
{
name: "pull by digest",
image: "quay.io/vmware-tanzu/velero@sha256:a75f9e8c3ced3943515f249597be389f8233e1258d289b11184796edceaa7dab",
expected: "vmware-tanzu-velero",
},
}
for _, test := range tests {