Skip to content

Commit 6570720

Browse files
committed
deprecate OPENSHIFT_DEFAULT_REGISTRY environment variable
1 parent 0658af0 commit 6570720

File tree

5 files changed

+11
-63
lines changed

5 files changed

+11
-63
lines changed

pkg/cmd/server/apis/config/types.go

-2
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,6 @@ type ImagePolicyConfig struct {
518518
AllowedRegistriesForImport *AllowedRegistries
519519
// InternalRegistryHostname sets the hostname for the default internal image
520520
// registry. The value must be in "hostname[:port]" format.
521-
// For backward compatibility, users can still use OPENSHIFT_DEFAULT_REGISTRY
522-
// environment variable but this setting overrides the environment variable.
523521
InternalRegistryHostname string
524522
// ExternalRegistryHostname sets the hostname for the default external image
525523
// registry. The external hostname should be set only when the image registry

pkg/cmd/server/apis/config/v1/types.go

-2
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,6 @@ type ImagePolicyConfig struct {
403403
AllowedRegistriesForImport *AllowedRegistries `json:"allowedRegistriesForImport,omitempty"`
404404
// InternalRegistryHostname sets the hostname for the default internal image
405405
// registry. The value must be in "hostname[:port]" format.
406-
// For backward compatibility, users can still use OPENSHIFT_DEFAULT_REGISTRY
407-
// environment variable but this setting overrides the environment variable.
408406
InternalRegistryHostname string `json:"internalRegistryHostname,omitempty"`
409407
// ExternalRegistryHostname sets the hostname for the default external image
410408
// registry. The external hostname should be set only when the image registry

pkg/cmd/server/origin/admission/plugin_initializer.go

+2-21
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package admission
33
import (
44
"fmt"
55
"io/ioutil"
6-
"os"
76

87
authorizationclient "github.com/openshift/client-go/authorization/clientset/versioned"
98
buildclient "github.com/openshift/client-go/build/clientset/versioned"
@@ -21,10 +20,8 @@ import (
2120
quotaclient "github.com/openshift/origin/pkg/quota/generated/internalclientset"
2221
"github.com/openshift/origin/pkg/quota/image"
2322
securityinformer "github.com/openshift/origin/pkg/security/generated/informers/internalversion"
24-
"github.com/openshift/origin/pkg/service"
2523
templateclient "github.com/openshift/origin/pkg/template/generated/internalclientset"
2624
"k8s.io/apimachinery/pkg/api/meta"
27-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2825
"k8s.io/apimachinery/pkg/runtime/schema"
2926
"k8s.io/apiserver/pkg/admission"
3027
"k8s.io/apiserver/pkg/admission/initializer"
@@ -104,13 +101,6 @@ func NewPluginInitializer(
104101
quotaRegistry.Add(imageEvaluators[i])
105102
}
106103

107-
defaultRegistry := env("OPENSHIFT_DEFAULT_REGISTRY", "${DOCKER_REGISTRY_SERVICE_HOST}:${DOCKER_REGISTRY_SERVICE_PORT}")
108-
svcCache := service.NewServiceResolverCache(kubeInternalClient.Core().Services(metav1.NamespaceDefault).Get)
109-
defaultRegistryFunc, err := svcCache.Defer(defaultRegistry)
110-
if err != nil {
111-
return nil, fmt.Errorf("OPENSHIFT_DEFAULT_REGISTRY variable is invalid %q: %v", defaultRegistry, err)
112-
}
113-
114104
// punch through layers to build this in order to get a string for a cloud provider file
115105
// TODO refactor us into a forward building flow with a side channel like this
116106
kubeOptions, err := kubernetes.BuildKubeAPIserverOptions(options)
@@ -123,7 +113,7 @@ func NewPluginInitializer(
123113
var err error
124114
cloudConfig, err = ioutil.ReadFile(kubeOptions.CloudProvider.CloudConfigFile)
125115
if err != nil {
126-
return nil, fmt.Errorf("Error reading from cloud configuration file %s: %v", kubeOptions.CloudProvider.CloudConfigFile, err)
116+
return nil, fmt.Errorf("error reading from cloud configuration file %s: %v", kubeOptions.CloudProvider.CloudConfigFile, err)
127117
}
128118
}
129119
// note: we are passing a combined quota registry here...
@@ -177,19 +167,10 @@ func NewPluginInitializer(
177167
Informers: informers.GetInternalKubeInformers(),
178168
ClusterResourceQuotaInformer: informers.GetQuotaInformers().Quota().InternalVersion().ClusterResourceQuotas(),
179169
ClusterQuotaMapper: clusterQuotaMappingController.GetClusterQuotaMapper(),
180-
RegistryHostnameRetriever: imageapi.DefaultRegistryHostnameRetriever(defaultRegistryFunc, options.ImagePolicyConfig.ExternalRegistryHostname, options.ImagePolicyConfig.InternalRegistryHostname),
170+
RegistryHostnameRetriever: imageapi.DefaultRegistryHostnameRetriever(options.ImagePolicyConfig.ExternalRegistryHostname, options.ImagePolicyConfig.InternalRegistryHostname),
181171
SecurityInformers: informers.GetSecurityInformers(),
182172
UserInformers: informers.GetUserInformers(),
183173
}
184174

185175
return admission.PluginInitializers{genericInitializer, webhookInitializer, kubePluginInitializer, openshiftPluginInitializer}, nil
186176
}
187-
188-
// env returns an environment variable, or the defaultValue if it is not set.
189-
func env(key string, defaultValue string) string {
190-
val := os.Getenv(key)
191-
if len(val) == 0 {
192-
return defaultValue
193-
}
194-
return val
195-
}

pkg/cmd/server/origin/master_config.go

+3-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"k8s.io/client-go/restmapper"
1212

1313
kapierrors "k8s.io/apimachinery/pkg/api/errors"
14-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1514
"k8s.io/apimachinery/pkg/labels"
1615
"k8s.io/apimachinery/pkg/runtime/schema"
1716
"k8s.io/apiserver/pkg/admission"
@@ -54,7 +53,6 @@ import (
5453
templateinformer "github.com/openshift/origin/pkg/template/generated/informers/internalversion"
5554

5655
securityinformer "github.com/openshift/origin/pkg/security/generated/informers/internalversion"
57-
"github.com/openshift/origin/pkg/service"
5856
"github.com/openshift/origin/pkg/util/restoptions"
5957
)
6058

@@ -150,13 +148,6 @@ func BuildMasterConfig(
150148
return nil, err
151149
}
152150

153-
defaultRegistry := env("OPENSHIFT_DEFAULT_REGISTRY", "${DOCKER_REGISTRY_SERVICE_HOST}:${DOCKER_REGISTRY_SERVICE_PORT}")
154-
svcCache := service.NewServiceResolverCache(kubeInternalClient.Core().Services(metav1.NamespaceDefault).Get)
155-
defaultRegistryFunc, err := svcCache.Defer(defaultRegistry)
156-
if err != nil {
157-
return nil, fmt.Errorf("OPENSHIFT_DEFAULT_REGISTRY variable is invalid %q: %v", defaultRegistry, err)
158-
}
159-
160151
authenticator, authenticatorPostStartHooks, err := NewAuthenticator(options, privilegedLoopbackConfig, informers)
161152
if err != nil {
162153
return nil, err
@@ -184,14 +175,14 @@ func BuildMasterConfig(
184175
admission.DecoratorFunc(namespaceLabelDecorator.WithNamespaceLabelConditions),
185176
admission.DecoratorFunc(admissionmetrics.WithControllerMetrics),
186177
}
187-
admission, err := originadmission.NewAdmissionChains(options, admissionInitializer, admissionDecorators)
178+
admissionChains, err := originadmission.NewAdmissionChains(options, admissionInitializer, admissionDecorators)
188179
if err != nil {
189180
return nil, err
190181
}
191182

192183
kubeAPIServerConfig, err := kubernetes.BuildKubernetesMasterConfig(
193184
options,
194-
admission,
185+
admissionChains,
195186
authenticator,
196187
authorizer,
197188
)
@@ -235,7 +226,7 @@ func BuildMasterConfig(
235226
ClusterQuotaMappingController: clusterQuotaMappingController,
236227
RESTMapper: restMapper,
237228

238-
RegistryHostnameRetriever: imageapi.DefaultRegistryHostnameRetriever(defaultRegistryFunc, options.ImagePolicyConfig.ExternalRegistryHostname, options.ImagePolicyConfig.InternalRegistryHostname),
229+
RegistryHostnameRetriever: imageapi.DefaultRegistryHostnameRetriever(options.ImagePolicyConfig.ExternalRegistryHostname, options.ImagePolicyConfig.InternalRegistryHostname),
239230

240231
PrivilegedLoopbackClientConfig: *privilegedLoopbackConfig,
241232
PrivilegedLoopbackKubernetesClientsetInternal: kubeInternalClient,

pkg/image/apis/image/helper.go

+6-26
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ const (
3232

3333
// TagReferenceAnnotationTagHidden indicates that a given TagReference is hidden from search results
3434
TagReferenceAnnotationTagHidden = "hidden"
35-
36-
// ImportRegistryNotAllowed indicates that the image tag was not imported due to
37-
// untrusted registry.
38-
ImportRegistryNotAllowed = "registry is not allowed for import"
3935
)
4036

4137
var errNoRegistryURLPathAllowed = errors.New("no path after <host>[:<port>] is allowed")
@@ -67,36 +63,24 @@ type RegistryHostnameRetriever interface {
6763

6864
// DefaultRegistryHostnameRetriever is a default implementation of
6965
// RegistryHostnameRetriever.
70-
// The first argument is a function that lazy-loads the value of
71-
// OPENSHIFT_DEFAULT_REGISTRY environment variable which should be deprecated in
72-
// future.
73-
func DefaultRegistryHostnameRetriever(deprecatedDefaultRegistryEnvFn func() (string, bool), external, internal string) RegistryHostnameRetriever {
66+
func DefaultRegistryHostnameRetriever(external, internal string) RegistryHostnameRetriever {
7467
return &defaultRegistryHostnameRetriever{
75-
deprecatedDefaultFn: deprecatedDefaultRegistryEnvFn,
76-
externalHostname: external,
77-
internalHostname: internal,
68+
externalHostname: external,
69+
internalHostname: internal,
7870
}
7971
}
8072

8173
type defaultRegistryHostnameRetriever struct {
82-
// deprecatedDefaultFn points to a function that will lazy-load the value of
83-
// OPENSHIFT_DEFAULT_REGISTRY.
84-
deprecatedDefaultFn func() (string, bool)
85-
internalHostname string
86-
externalHostname string
74+
internalHostname string
75+
externalHostname string
8776
}
8877

8978
// InternalRegistryHostnameFn returns a function that can be used to lazy-load
90-
// the internal Docker Registry hostname. If the master configuration properly
91-
// InternalRegistryHostname is set, it will prefer that over the lazy-loaded
92-
// environment variable 'OPENSHIFT_DEFAULT_REGISTRY'.
79+
// the internal Docker Registry hostname.
9380
func (r *defaultRegistryHostnameRetriever) InternalRegistryHostname() (string, bool) {
9481
if len(r.internalHostname) > 0 {
9582
return r.internalHostname, true
9683
}
97-
if r.deprecatedDefaultFn != nil {
98-
return r.deprecatedDefaultFn()
99-
}
10084
return "", false
10185
}
10286

@@ -813,10 +797,6 @@ func PrioritizeTags(tags []string) {
813797
}
814798
}
815799

816-
func LabelForStream(stream *ImageStream) string {
817-
return fmt.Sprintf("%s/%s", stream.Namespace, stream.Name)
818-
}
819-
820800
// JoinImageSignatureName joins image name and custom signature name into one string with @ separator.
821801
func JoinImageSignatureName(imageName, signatureName string) (string, error) {
822802
if len(imageName) == 0 {

0 commit comments

Comments
 (0)