From bee8f006fedd42dcb4af7f9d874eeb554fe5f24a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Feb 2022 16:57:46 +0100 Subject: [PATCH] registry: serviceConfig: don't embed registry.ServiceConfig Just define it as a type, which makes it slightly easier to consume. Signed-off-by: Sebastiaan van Stijn --- registry/config.go | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/registry/config.go b/registry/config.go index 1f1be93f5a..0d92a52813 100644 --- a/registry/config.go +++ b/registry/config.go @@ -20,9 +20,7 @@ type ServiceOptions struct { } // serviceConfig holds daemon configuration for the registry service. -type serviceConfig struct { - registry.ServiceConfig -} +type serviceConfig registry.ServiceConfig // TODO(thaJeztah) both the "index.docker.io" and "registry-1.docker.io" domains // are here for historic reasons and backward-compatibility. These domains @@ -65,14 +63,7 @@ var ( // newServiceConfig returns a new instance of ServiceConfig func newServiceConfig(options ServiceOptions) (*serviceConfig, error) { - config := &serviceConfig{ - ServiceConfig: registry.ServiceConfig{ - InsecureRegistryCIDRs: make([]*registry.NetIPNet, 0), - IndexConfigs: make(map[string]*registry.IndexInfo), - // Hack: Bypass setting the mirrors to IndexConfigs since they are going away - // and Mirrors are only for the official registry anyways. - }, - } + config := &serviceConfig{} if err := config.loadAllowNondistributableArtifacts(options.AllowNondistributableArtifacts); err != nil { return nil, err } @@ -87,15 +78,15 @@ func newServiceConfig(options ServiceOptions) (*serviceConfig, error) { } // copy constructs a new ServiceConfig with a copy of the configuration in config. -func (config *serviceConfig) copy() *registrytypes.ServiceConfig { - ic := make(map[string]*registrytypes.IndexInfo) +func (config *serviceConfig) copy() *registry.ServiceConfig { + ic := make(map[string]*registry.IndexInfo) for key, value := range config.IndexConfigs { ic[key] = value } - return ®istrytypes.ServiceConfig{ - AllowNondistributableArtifactsCIDRs: append([]*registrytypes.NetIPNet(nil), config.AllowNondistributableArtifactsCIDRs...), + return ®istry.ServiceConfig{ + AllowNondistributableArtifactsCIDRs: append([]*registry.NetIPNet(nil), config.AllowNondistributableArtifactsCIDRs...), AllowNondistributableArtifactsHostnames: append([]string(nil), config.AllowNondistributableArtifactsHostnames...), - InsecureRegistryCIDRs: append([]*registrytypes.NetIPNet(nil), config.InsecureRegistryCIDRs...), + InsecureRegistryCIDRs: append([]*registry.NetIPNet(nil), config.InsecureRegistryCIDRs...), IndexConfigs: ic, Mirrors: append([]string(nil), config.Mirrors...), } @@ -158,11 +149,13 @@ func (config *serviceConfig) loadMirrors(mirrors []string) error { config.Mirrors = unique // Configure public registry since mirrors may have changed. - config.IndexConfigs[IndexName] = ®istry.IndexInfo{ - Name: IndexName, - Mirrors: config.Mirrors, - Secure: true, - Official: true, + config.IndexConfigs = map[string]*registry.IndexInfo{ + IndexName: { + Name: IndexName, + Mirrors: unique, + Secure: true, + Official: true, + }, } return nil