From dce7c32b33c0c7ac5b14eaa4a786417a67e3504f Mon Sep 17 00:00:00 2001 From: Matthias Diester Date: Thu, 20 Jun 2024 22:01:00 +0200 Subject: [PATCH] Add legacy endpoints to registry detection Add the respective legacy/old registry endpoints to the list of endpoints of the registry detection to allow users to potentially still use the old registry endpoints. --- pkg/image/delete.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkg/image/delete.go b/pkg/image/delete.go index eea604445f..2fb7e3be3b 100644 --- a/pkg/image/delete.go +++ b/pkg/image/delete.go @@ -49,8 +49,9 @@ import ( // Other registries: // Use standard spec delete API request to delete the provided tag. func Delete(ref name.Reference, options []remote.Option, auth authn.AuthConfig) error { + var registry = ref.Context().RegistryStr() switch { - case strings.Contains(ref.Context().RegistryStr(), "docker.io"): + case isDockerHubEndpoint(registry): list, err := remote.List(ref.Context(), options...) if err != nil { return err @@ -70,7 +71,7 @@ func Delete(ref name.Reference, options []remote.Option, auth authn.AuthConfig) return dockerHubRepoDelete(token, ref) default: - log.Printf("Removing a specific image tag is not supported on %q, the respective image tag will be overwritten with an empty image.\n", ref.Context().RegistryStr()) + log.Printf("Removing a specific image tag is not supported on %q, the respective image tag will be overwritten with an empty image.\n", registry) // In case the input argument included a digest, the reference // needs to be updated to exclude the digest for the empty image @@ -90,8 +91,8 @@ func Delete(ref name.Reference, options []remote.Option, auth authn.AuthConfig) ) } - case strings.Contains(ref.Context().RegistryStr(), "icr.io"): - token, accountID, err := icrLogin(ref.Context().RegistryStr(), auth.Username, auth.Password) + case isIcrEndpoint(registry): + token, accountID, err := icrLogin(registry, auth.Username, auth.Password) if err != nil { return err } @@ -112,6 +113,16 @@ func httpClient() *http.Client { } } +func isDockerHubEndpoint(registry string) bool { + return strings.Contains(registry, "docker.io") || + strings.Contains(registry, "registry.hub.docker.com") +} + +func isIcrEndpoint(registry string) bool { + return strings.Contains(registry, "icr.io") || + strings.Contains(registry, "bluemix.net") +} + func dockerHubLogin(username string, password string) (string, error) { type LoginData struct { Username string `json:"username"`