From 293bbb44a0062fd039acf20b8babd1da440d88bd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 3 Mar 2025 15:22:42 +0100 Subject: [PATCH 1/3] cli/registry/client: remove unused PutManifestOptions This type was added in 02719bdbb5fb47389e47575bb006509da86df344, but was never used; git rev-parse --verify HEAD 02719bdbb5fb47389e47575bb006509da86df344 git grep 'PutManifestOptions' cli/registry/client/client.go:// PutManifestOptions is the data sent to push a manifest cli/registry/client/client.go:type PutManifestOptions struct { This patch removes it, because it's not used. Signed-off-by: Sebastiaan van Stijn --- cli/registry/client/client.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cli/registry/client/client.go b/cli/registry/client/client.go index c7f1a48082..24b78165d0 100644 --- a/cli/registry/client/client.go +++ b/cli/registry/client/client.go @@ -37,12 +37,6 @@ func NewRegistryClient(resolver AuthConfigResolver, userAgent string, insecure b // AuthConfigResolver returns Auth Configuration for an index type AuthConfigResolver func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig -// PutManifestOptions is the data sent to push a manifest -type PutManifestOptions struct { - MediaType string - Payload []byte -} - type client struct { authConfigResolver AuthConfigResolver insecureRegistry bool From 1a165fd535cdec150c5d5333f42beb0d2f6d0968 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 3 Mar 2025 15:32:58 +0100 Subject: [PATCH 2/3] cli/registry/client: un-export ErrHTTPProto This type was added in 02719bdbb5fb47389e47575bb006509da86df344, but was never used outside of the package itself. This patch un-exports it. Signed-off-by: Sebastiaan van Stijn --- cli/registry/client/client.go | 12 ++++++------ cli/registry/client/fetcher.go | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cli/registry/client/client.go b/cli/registry/client/client.go index 24b78165d0..31975d483e 100644 --- a/cli/registry/client/client.go +++ b/cli/registry/client/client.go @@ -54,13 +54,13 @@ func (err ErrBlobCreated) Error() string { err.From, err.Target) } -// ErrHTTPProto returned if attempting to use TLS with a non-TLS registry -type ErrHTTPProto struct { - OrigErr string +// httpProtoError returned if attempting to use TLS with a non-TLS registry +type httpProtoError struct { + cause error } -func (err ErrHTTPProto) Error() string { - return err.OrigErr +func (e httpProtoError) Error() string { + return e.cause.Error() } var _ RegistryClient = &client{} @@ -131,7 +131,7 @@ func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Na return nil, err } if !repoEndpoint.endpoint.TLSConfig.InsecureSkipVerify { - return nil, ErrHTTPProto{OrigErr: err.Error()} + return nil, httpProtoError{cause: err} } // --insecure was set; fall back to plain HTTP if url := repoEndpoint.endpoint.URL; url != nil && url.Scheme == "https" { diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index d1f255bf9f..767d1129ce 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -241,7 +241,8 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named, repo, err := c.getRepositoryForReference(ctx, namedRef, repoEndpoint) if err != nil { logrus.Debugf("error %s with repo endpoint %+v", err, repoEndpoint) - if _, ok := err.(ErrHTTPProto); ok { + var protoErr httpProtoError + if errors.As(err, &protoErr) { continue } return err From 6f46cd2f4b7aa7e4c2017a2cb1748dea706b3388 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 3 Mar 2025 15:47:02 +0100 Subject: [PATCH 3/3] 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 {