From 491e8fdaf8409f9141ee48a6fb7d774e342bbe56 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 25 Mar 2025 09:44:13 +0100 Subject: [PATCH] cli/registry/client: skip RepositoryInfo as intermediate Remove RepositoryInfo as intermediate struct in some places; we want to remove the use of this additional abstration. More changes are needed to fully remove it, but chipping away its use in small bits. Signed-off-by: Sebastiaan van Stijn --- cli/registry/client/client.go | 2 +- cli/registry/client/endpoint.go | 31 ++++++++++++++++++------------- cli/registry/client/fetcher.go | 8 +++++++- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/cli/registry/client/client.go b/cli/registry/client/client.go index 31975d483e..f1fee951f3 100644 --- a/cli/registry/client/client.go +++ b/cli/registry/client/client.go @@ -147,7 +147,7 @@ func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Na func (c *client) getHTTPTransportForRepoEndpoint(ctx context.Context, repoEndpoint repositoryEndpoint) (http.RoundTripper, error) { httpTransport, err := getHTTPTransport( - c.authConfigResolver(ctx, repoEndpoint.info.Index), + c.authConfigResolver(ctx, repoEndpoint.indexInfo), repoEndpoint.endpoint, repoEndpoint.Name(), c.userAgent, diff --git a/cli/registry/client/endpoint.go b/cli/registry/client/endpoint.go index ab35e73c44..df0b190d56 100644 --- a/cli/registry/client/endpoint.go +++ b/cli/registry/client/endpoint.go @@ -14,14 +14,15 @@ import ( ) type repositoryEndpoint struct { - info *registry.RepositoryInfo - endpoint registry.APIEndpoint - actions []string + repoName reference.Named + indexInfo *registrytypes.IndexInfo + endpoint registry.APIEndpoint + actions []string } // Name returns the repository name func (r repositoryEndpoint) Name() string { - return reference.Path(r.info.Name) + return reference.Path(r.repoName) } // BaseURL returns the endpoint url @@ -30,32 +31,36 @@ func (r repositoryEndpoint) BaseURL() string { } func newDefaultRepositoryEndpoint(ref reference.Named, insecure bool) (repositoryEndpoint, error) { + repoName := reference.TrimNamed(ref) repoInfo, _ := registry.ParseRepositoryInfo(ref) - endpoint, err := getDefaultEndpointFromRepoInfo(repoInfo) + indexInfo := repoInfo.Index + + endpoint, err := getDefaultEndpoint(ref, !indexInfo.Secure) if err != nil { return repositoryEndpoint{}, err } if insecure { endpoint.TLSConfig.InsecureSkipVerify = true } - return repositoryEndpoint{info: repoInfo, endpoint: endpoint}, nil + return repositoryEndpoint{ + repoName: repoName, + indexInfo: indexInfo, + endpoint: endpoint, + }, nil } -func getDefaultEndpointFromRepoInfo(repoInfo *registry.RepositoryInfo) (registry.APIEndpoint, error) { - var err error - - options := registry.ServiceOptions{} - registryService, err := registry.NewService(options) +func getDefaultEndpoint(repoName reference.Named, insecure bool) (registry.APIEndpoint, error) { + registryService, err := registry.NewService(registry.ServiceOptions{}) if err != nil { return registry.APIEndpoint{}, err } - endpoints, err := registryService.LookupPushEndpoints(reference.Domain(repoInfo.Name)) + endpoints, err := registryService.LookupPushEndpoints(reference.Domain(repoName)) if err != nil { return registry.APIEndpoint{}, err } // Default to the highest priority endpoint to return endpoint := endpoints[0] - if !repoInfo.Index.Secure { + if insecure { for _, ep := range endpoints { if ep.URL.Scheme == "http" { endpoint = ep diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index f0a2f9869a..f270d49432 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -220,7 +220,9 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named, return err } + repoName := reference.TrimNamed(namedRef) repoInfo, _ := registry.ParseRepositoryInfo(namedRef) + indexInfo := repoInfo.Index confirmedTLSRegistries := make(map[string]bool) for _, endpoint := range endpoints { @@ -234,7 +236,11 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named, if c.insecureRegistry { endpoint.TLSConfig.InsecureSkipVerify = true } - repoEndpoint := repositoryEndpoint{endpoint: endpoint, info: repoInfo} + repoEndpoint := repositoryEndpoint{ + repoName: repoName, + indexInfo: indexInfo, + endpoint: endpoint, + } repo, err := c.getRepositoryForReference(ctx, namedRef, repoEndpoint) if err != nil { logrus.Debugf("error %s with repo endpoint %+v", err, repoEndpoint)