From d43e61758ad95fe71c238434c26a7897cc7248f4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Aug 2023 12:47:07 +0200 Subject: [PATCH] registry: deprecate APIEndpoint.Version and APIVersion type This field was used when the code supported both "v1" and "v2" registries. We no longer support v1 registries, and the only v1 endpoint that's still used is for the legacy "search" endpoint, which does not use the APIEndpoint type. As no code is using this field, and the value will always be set to "v2", we can deprecated the Version field. I'm keeping this field for 1 release, to give notice to any potential external consumer, after which we can delete it. Signed-off-by: Sebastiaan van Stijn --- distribution/pull_v2_test.go | 1 - distribution/push_v2_test.go | 3 +-- distribution/registry_unit_test.go | 1 - registry/service.go | 2 +- registry/service_v2.go | 8 ++++---- registry/types.go | 6 ++++-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/distribution/pull_v2_test.go b/distribution/pull_v2_test.go index 60d8835944..60a147d044 100644 --- a/distribution/pull_v2_test.go +++ b/distribution/pull_v2_test.go @@ -331,7 +331,6 @@ func testNewPuller(t *testing.T, rawurl string) *puller { endpoint := registry.APIEndpoint{ Mirror: false, URL: uri, - Version: registry.APIVersion2, Official: false, TrimHostname: false, TLSConfig: nil, diff --git a/distribution/push_v2_test.go b/distribution/push_v2_test.go index 3abc68222f..6ae4921023 100644 --- a/distribution/push_v2_test.go +++ b/distribution/push_v2_test.go @@ -534,9 +534,8 @@ func TestWhenEmptyAuthConfig(t *testing.T) { endpoint: registrypkg.APIEndpoint{ URL: &url.URL{ Scheme: "https", - Host: "index.docker.io", + Host: registrypkg.IndexHostname, }, - Version: registrypkg.APIVersion2, TrimHostname: true, }, } diff --git a/distribution/registry_unit_test.go b/distribution/registry_unit_test.go index de56ddd921..2e0ccd22ff 100644 --- a/distribution/registry_unit_test.go +++ b/distribution/registry_unit_test.go @@ -43,7 +43,6 @@ func testTokenPassThru(t *testing.T, ts *httptest.Server) { endpoint := registrypkg.APIEndpoint{ Mirror: false, URL: uri, - Version: registrypkg.APIVersion2, Official: false, TrimHostname: false, TLSConfig: nil, diff --git a/registry/service.go b/registry/service.go index 752d2e7458..a738f7dbfb 100644 --- a/registry/service.go +++ b/registry/service.go @@ -115,7 +115,7 @@ func (s *Service) ResolveRepository(name reference.Named) (*RepositoryInfo, erro type APIEndpoint struct { Mirror bool URL *url.URL - Version APIVersion + Version APIVersion // Deprecated: v1 registries are deprecated, and endpoints are always v2. AllowNondistributableArtifacts bool Official bool TrimHostname bool diff --git a/registry/service_v2.go b/registry/service_v2.go index c8c545d21f..5d09e11c9c 100644 --- a/registry/service_v2.go +++ b/registry/service_v2.go @@ -25,7 +25,7 @@ func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, e } endpoints = append(endpoints, APIEndpoint{ URL: mirrorURL, - Version: APIVersion2, + Version: APIVersion2, //nolint:staticcheck // ignore SA1019 (Version is deprecated) to allow potential consumers to transition. Mirror: true, TrimHostname: true, TLSConfig: mirrorTLSConfig, @@ -33,7 +33,7 @@ func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, e } endpoints = append(endpoints, APIEndpoint{ URL: DefaultV2Registry, - Version: APIVersion2, + Version: APIVersion2, //nolint:staticcheck // ignore SA1019 (Version is deprecated) to allow potential consumers to transition. Official: true, TrimHostname: true, TLSConfig: tlsconfig.ServerDefault(), @@ -55,7 +55,7 @@ func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, e Scheme: "https", Host: hostname, }, - Version: APIVersion2, + Version: APIVersion2, //nolint:staticcheck // ignore SA1019 (Version is deprecated) to allow potential consumers to transition. AllowNondistributableArtifacts: ana, TrimHostname: true, TLSConfig: tlsConfig, @@ -68,7 +68,7 @@ func (s *Service) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, e Scheme: "http", Host: hostname, }, - Version: APIVersion2, + Version: APIVersion2, //nolint:staticcheck // ignore SA1019 (Version is deprecated) to allow potential consumers to transition. AllowNondistributableArtifacts: ana, TrimHostname: true, // used to check if supposed to be secure via InsecureSkipVerify diff --git a/registry/types.go b/registry/types.go index 37094737f2..dc76aeb2cc 100644 --- a/registry/types.go +++ b/registry/types.go @@ -7,6 +7,8 @@ import ( // APIVersion is an integral representation of an API version (presently // either 1 or 2) +// +// Deprecated: v1 registries are deprecated, and endpoints are always v2. type APIVersion int func (av APIVersion) String() string { @@ -15,8 +17,8 @@ func (av APIVersion) String() string { // API Version identifiers. const ( - APIVersion1 APIVersion = 1 - APIVersion2 APIVersion = 2 + APIVersion1 APIVersion = 1 // Deprecated: v1 registries are deprecated, and endpoints are always v2. + APIVersion2 APIVersion = 2 // Deprecated: v1 registries are deprecated, and endpoints are always v2. ) var apiVersions = map[APIVersion]string{