From 2ce94e4fffd33e8ca35aba395935409fbf75e2ad Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 20 Aug 2025 14:02:26 +0200 Subject: [PATCH] internal/registryclient: repositoryEndpoint: memoize repoName - Parse/format the repository name when constructing and store the result. - Remove the Name() accessor, as this type is only used internally, and no longer had any special handling. Signed-off-by: Sebastiaan van Stijn --- internal/registryclient/client.go | 4 ++-- internal/registryclient/endpoint.go | 11 ++--------- internal/registryclient/fetcher.go | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/internal/registryclient/client.go b/internal/registryclient/client.go index f848dea5f..71d6b227c 100644 --- a/internal/registryclient/client.go +++ b/internal/registryclient/client.go @@ -120,7 +120,7 @@ func (c *client) PutManifest(ctx context.Context, ref reference.Named, manifest } func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Named, repoEndpoint repositoryEndpoint) (distribution.Repository, error) { - repoName, err := reference.WithName(repoEndpoint.Name()) + repoName, err := reference.WithName(repoEndpoint.repoName) if err != nil { return nil, fmt.Errorf("failed to parse repo name from %s: %w", ref, err) } @@ -148,7 +148,7 @@ func (c *client) getHTTPTransportForRepoEndpoint(ctx context.Context, repoEndpoi httpTransport, err := getHTTPTransport( c.authConfigResolver(ctx, repoEndpoint.indexInfo), repoEndpoint.endpoint, - repoEndpoint.Name(), + repoEndpoint.repoName, c.userAgent, repoEndpoint.actions, ) diff --git a/internal/registryclient/endpoint.go b/internal/registryclient/endpoint.go index 85fd67813..6cef45350 100644 --- a/internal/registryclient/endpoint.go +++ b/internal/registryclient/endpoint.go @@ -16,26 +16,19 @@ import ( ) type repositoryEndpoint struct { - repoName reference.Named + repoName string indexInfo *registrytypes.IndexInfo endpoint registry.APIEndpoint actions []string } -// Name returns the repository name -func (r repositoryEndpoint) Name() string { - return reference.Path(r.repoName) -} - // BaseURL returns the endpoint url func (r repositoryEndpoint) BaseURL() string { return r.endpoint.URL.String() } func newDefaultRepositoryEndpoint(ref reference.Named, insecure bool) (repositoryEndpoint, error) { - repoName := reference.TrimNamed(ref) indexInfo := registry.NewIndexInfo(ref) - endpoint, err := getDefaultEndpoint(ref, !indexInfo.Secure) if err != nil { return repositoryEndpoint{}, err @@ -44,7 +37,7 @@ func newDefaultRepositoryEndpoint(ref reference.Named, insecure bool) (repositor endpoint.TLSConfig.InsecureSkipVerify = true } return repositoryEndpoint{ - repoName: repoName, + repoName: reference.Path(reference.TrimNamed(ref)), indexInfo: indexInfo, endpoint: endpoint, }, nil diff --git a/internal/registryclient/fetcher.go b/internal/registryclient/fetcher.go index 325cbf6e0..42ef0dec5 100644 --- a/internal/registryclient/fetcher.go +++ b/internal/registryclient/fetcher.go @@ -221,7 +221,7 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named, return err } - repoName := reference.TrimNamed(namedRef) + repoName := reference.Path(reference.TrimNamed(namedRef)) indexInfo := registry.NewIndexInfo(namedRef) confirmedTLSRegistries := make(map[string]bool)