Skip to content

Commit a92342a

Browse files
committed
registry: deprecate APIEndpoint.TrimHostName
This field was added in 19515a7, but looks to be always set for endpoints used, so we can trim remote names unconditionally. The field is unlikely used outside of our codebased, but deprecating it before removal just in case. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 9d60f68 commit a92342a

File tree

5 files changed

+15
-24
lines changed

5 files changed

+15
-24
lines changed

distribution/push_v2_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ func TestWhenEmptyAuthConfig(t *testing.T) {
517517
Scheme: "https",
518518
Host: registrypkg.IndexHostname,
519519
},
520-
TrimHostname: true,
521520
},
522521
}
523522
pusher.push(context.Background())

distribution/registry.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,8 @@ func newRepository(
7676
ctx context.Context, repoInfo *registry.RepositoryInfo, endpoint registry.APIEndpoint,
7777
metaHeaders http.Header, authConfig *registrytypes.AuthConfig, actions ...string,
7878
) (distribution.Repository, error) {
79-
repoName := repoInfo.Name.Name()
80-
// If endpoint does not support CanonicalName, use the RemoteName instead
81-
if endpoint.TrimHostname {
82-
repoName = reference.Path(repoInfo.Name)
83-
}
79+
// Trim the hostname to form the RemoteName
80+
repoName := reference.Path(repoInfo.Name)
8481

8582
direct := &net.Dialer{
8683
Timeout: 30 * time.Second,
@@ -131,6 +128,7 @@ func newRepository(
131128
}
132129
tr := transport.NewTransport(base, modifiers...)
133130

131+
// FIXME(thaJeztah): should this just take the original repoInfo.Name instead of converting the remote name back to a named reference?
134132
repoNameRef, err := reference.WithName(repoName)
135133
if err != nil {
136134
return nil, fallbackError{

distribution/registry_unit_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ func testTokenPassThru(t *testing.T, ts *httptest.Server) {
4040
t.Fatalf("could not parse url from test server: %v", err)
4141
}
4242

43-
endpoint := registrypkg.APIEndpoint{
44-
URL: uri,
45-
TrimHostname: false,
46-
}
4743
n, _ := reference.ParseNormalizedNamed("testremotename")
4844
repoInfo := &registrypkg.RepositoryInfo{
4945
Name: n,
@@ -59,7 +55,7 @@ func testTokenPassThru(t *testing.T, ts *httptest.Server) {
5955
},
6056
},
6157
}
62-
p := newPuller(endpoint, repoInfo, imagePullConfig, nil)
58+
p := newPuller(registrypkg.APIEndpoint{URL: uri}, repoInfo, imagePullConfig, nil)
6359
ctx := context.Background()
6460
p.repo, err = newRepository(ctx, p.repoInfo, p.endpoint, p.config.MetaHeaders, p.config.AuthConfig, "pull")
6561
if err != nil {

registry/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type APIEndpoint struct {
105105
URL *url.URL
106106
AllowNondistributableArtifacts bool
107107
Official bool
108-
TrimHostname bool
108+
TrimHostname bool // Deprecated: hostname is now trimmed unconditionally for remote names. This field will be removed in the next release.
109109
TLSConfig *tls.Config
110110
}
111111

registry/service_v2.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@ func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, e
2424
return nil, err
2525
}
2626
endpoints = append(endpoints, APIEndpoint{
27-
URL: mirrorURL,
28-
Mirror: true,
29-
TrimHostname: true,
30-
TLSConfig: mirrorTLSConfig,
27+
URL: mirrorURL,
28+
Mirror: true,
29+
TLSConfig: mirrorTLSConfig,
3130
})
3231
}
3332
endpoints = append(endpoints, APIEndpoint{
34-
URL: DefaultV2Registry,
35-
Official: true,
36-
TrimHostname: true,
37-
TLSConfig: tlsconfig.ServerDefault(),
33+
URL: DefaultV2Registry,
34+
Official: true,
35+
TLSConfig: tlsconfig.ServerDefault(),
3836

3937
AllowNondistributableArtifacts: ana,
4038
})
@@ -53,9 +51,9 @@ func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, e
5351
Scheme: "https",
5452
Host: hostname,
5553
},
54+
TLSConfig: tlsConfig,
55+
5656
AllowNondistributableArtifacts: ana,
57-
TrimHostname: true,
58-
TLSConfig: tlsConfig,
5957
},
6058
}
6159

@@ -65,10 +63,10 @@ func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, e
6563
Scheme: "http",
6664
Host: hostname,
6765
},
68-
AllowNondistributableArtifacts: ana,
69-
TrimHostname: true,
7066
// used to check if supposed to be secure via InsecureSkipVerify
7167
TLSConfig: tlsConfig,
68+
69+
AllowNondistributableArtifacts: ana,
7270
})
7371
}
7472

0 commit comments

Comments
 (0)