From 6f46cd2f4b7aa7e4c2017a2cb1748dea706b3388 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 3 Mar 2025 15:47:02 +0100 Subject: [PATCH] cli/registry/client: deprecate RepoNameForReference This function was added in 02719bdbb5fb47389e47575bb006509da86df344, and used newDefaultRepositoryEndpoint to get repository info for the given image-reference. newDefaultRepositoryEndpoint uses registry.ParseRepositoryInfo under the hood, but the only information used from the result was the Name field, which is set using `reference.TrimNamed(name)`. The possible error returned was based on the domain-name of the image, and only checked for the domain to not start, or end with a hyphen ("-"). This patch removes the use of RepoNameForReference, deprecates it, and inlines the code used by it. There are no known consumers of this function, so we can consider removing it in the first possible release after this (which can be a minor release). Signed-off-by: Sebastiaan van Stijn --- cli/command/manifest/push.go | 11 ++--------- cli/registry/client/endpoint.go | 11 ++++------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/cli/command/manifest/push.go b/cli/command/manifest/push.go index 2e1efd15e5..9b214eeaa7 100644 --- a/cli/command/manifest/push.go +++ b/cli/command/manifest/push.go @@ -99,17 +99,10 @@ func buildPushRequest(manifests []types.ImageManifest, targetRef reference.Named return req, err } - targetRepoName, err := registryclient.RepoNameForReference(targetRef) - if err != nil { - return req, err - } + targetRepoName := reference.Path(reference.TrimNamed(targetRef)) for _, imageManifest := range manifests { - manifestRepoName, err := registryclient.RepoNameForReference(imageManifest.Ref) - if err != nil { - return req, err - } - + manifestRepoName := reference.Path(reference.TrimNamed(imageManifest.Ref)) repoName, _ := reference.WithName(manifestRepoName) if repoName.Name() != targetRepoName { blobs, err := buildBlobRequestList(imageManifest, repoName) diff --git a/cli/registry/client/endpoint.go b/cli/registry/client/endpoint.go index 40abe31c20..407b8ac6f1 100644 --- a/cli/registry/client/endpoint.go +++ b/cli/registry/client/endpoint.go @@ -103,14 +103,11 @@ func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.API return transport.NewTransport(base, modifiers...), nil } -// RepoNameForReference returns the repository name from a reference +// RepoNameForReference returns the repository name from a reference. +// +// Deprecated: this function is no longer used and will be removed in the next release. func RepoNameForReference(ref reference.Named) (string, error) { - // insecure is fine since this only returns the name - repo, err := newDefaultRepositoryEndpoint(ref, false) - if err != nil { - return "", err - } - return repo.Name(), nil + return reference.Path(reference.TrimNamed(ref)), nil } type existingTokenHandler struct {