Skip to content

Commit

Permalink
Merge pull request #378 from flavianmissi/OCPBUGS-17674
Browse files Browse the repository at this point in the history
IR-401: pkg/dockerregistry/server/configuration: remove OPENSHIFT_DEFAULT_REGISTRY support
  • Loading branch information
openshift-ci[bot] committed Oct 23, 2023
2 parents c3068bc + 6bd6aac commit 855b24b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 48 deletions.
18 changes: 0 additions & 18 deletions pkg/dockerregistry/server/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ const (
// DEPRECATED: Use the REGISTRY_OPENSHIFT_SERVER_ADDR instead.
openShiftDockerRegistryURLEnvVar = "REGISTRY_MIDDLEWARE_REPOSITORY_OPENSHIFT_DOCKERREGISTRYURL"

// openShiftDefaultRegistryEnvVar overrides the dockerRegistryURLEnvVar as in OpenShift the
// default registry URL is controlled by this environment variable.
// DEPRECATED: Use the REGISTRY_OPENSHIFT_SERVER_ADDR instead.
openShiftDefaultRegistryEnvVar = "OPENSHIFT_DEFAULT_REGISTRY"

// enforceQuotaEnvVar is a boolean environment variable that allows to turn quota enforcement on or off.
// By default, quota enforcement is off. It overrides openshift middleware configuration option.
// Recognized values are "true" and "false".
Expand Down Expand Up @@ -324,13 +319,6 @@ func setDefaultMiddleware(config *configuration.Configuration) {
func getServerAddr(options configuration.Parameters, cfgValue string) (registryAddr string, err error) {
var found bool

if len(registryAddr) == 0 {
registryAddr, found = os.LookupEnv(openShiftDefaultRegistryEnvVar)
if found {
log.Infof("DEPRECATED: %q is deprecated, use the 'REGISTRY_OPENSHIFT_SERVER_ADDR' instead", openShiftDefaultRegistryEnvVar)
}
}

if len(registryAddr) == 0 {
registryAddr, found = os.LookupEnv(dockerRegistryURLEnvVar)
if found {
Expand All @@ -350,12 +338,6 @@ func getServerAddr(options configuration.Parameters, cfgValue string) (registryA
registryAddr = cfgValue
}

// TODO: This is a fallback to assuming there is a service named 'docker-registry'. This
// might change in the future and we should make this configurable.
if len(registryAddr) == 0 && len(os.Getenv("DOCKER_REGISTRY_SERVICE_HOST")) > 0 && len(os.Getenv("DOCKER_REGISTRY_SERVICE_PORT")) > 0 {
registryAddr = os.Getenv("DOCKER_REGISTRY_SERVICE_HOST") + ":" + os.Getenv("DOCKER_REGISTRY_SERVICE_PORT")
}

if len(registryAddr) == 0 {
err = fmt.Errorf("REGISTRY_OPENSHIFT_SERVER_ADDR variable must be set when running outside of Kubernetes cluster")
}
Expand Down
45 changes: 15 additions & 30 deletions pkg/dockerregistry/server/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func testConfigurationOverwriteEnv(t *testing.T, config string) {
}

func TestConfigurationOverwriteEnv(t *testing.T) {
var configYaml = `
configYaml := `
version: 0.1
storage:
inmemory: {}
Expand All @@ -121,7 +121,7 @@ openshift:
}

func TestConfigurationWithEmptyOpenshiftOverwriteEnv(t *testing.T) {
var configYaml = `
configYaml := `
version: 0.1
storage:
inmemory: {}
Expand All @@ -130,7 +130,7 @@ storage:
}

func TestDockerConfigurationError(t *testing.T) {
var badDockerConfigYamlV0_1 = `
badDockerConfigYamlV0_1 := `
version: 0.1
http:
addr: :5000
Expand All @@ -147,7 +147,7 @@ storage:
}

func TestExtraConfigurationError(t *testing.T) {
var badExtraConfigYaml = `
badExtraConfigYaml := `
version: 0.1
http:
addr: :5000
Expand All @@ -167,7 +167,7 @@ openshift:
}

func TestEmptyExtraConfigurationError(t *testing.T) {
var emptyExtraConfigYaml = `
emptyExtraConfigYaml := `
version: 0.1
http:
addr: :5000
Expand All @@ -186,7 +186,7 @@ storage:
}

func TestExtraConfigurationVersionError(t *testing.T) {
var badExtraConfigYaml = `
badExtraConfigYaml := `
version: 0.1
http:
addr: :5000
Expand Down Expand Up @@ -458,7 +458,7 @@ middleware:
}

func TestMiddlewareMigration(t *testing.T) {
var inputConfigYaml = `
inputConfigYaml := `
version: 0.1
log:
level: debug
Expand Down Expand Up @@ -492,7 +492,7 @@ openshift:
server:
addr: :5000
`
var expectConfigYaml = `
expectConfigYaml := `
version: 0.1
log:
level: debug
Expand Down Expand Up @@ -563,7 +563,7 @@ openshift:
}

func TestServerAddrEnvOrder(t *testing.T) {
var configYaml = `
configYaml := `
version: 0.1
http:
addr: :5000
Expand All @@ -580,13 +580,6 @@ openshift:
setenv []env
expected string
}{
{
setenv: []env{
{name: "DOCKER_REGISTRY_SERVICE_HOST", value: "DOCKER_REGISTRY_SERVICE_HOST"},
{name: "DOCKER_REGISTRY_SERVICE_PORT", value: "DOCKER_REGISTRY_SERVICE_PORT"},
},
expected: "DOCKER_REGISTRY_SERVICE_HOST:DOCKER_REGISTRY_SERVICE_PORT",
},
{
setenv: []env{{name: "REGISTRY_OPENSHIFT_SERVER_ADDR", value: "REGISTRY_OPENSHIFT_SERVER_ADDR"}},
expected: "REGISTRY_OPENSHIFT_SERVER_ADDR",
Expand All @@ -599,10 +592,6 @@ openshift:
setenv: []env{{name: "DOCKER_REGISTRY_URL", value: "DOCKER_REGISTRY_URL"}},
expected: "DOCKER_REGISTRY_URL",
},
{
setenv: []env{{name: "OPENSHIFT_DEFAULT_REGISTRY", value: "OPENSHIFT_DEFAULT_REGISTRY"}},
expected: "OPENSHIFT_DEFAULT_REGISTRY",
},
}

for _, test := range testCases {
Expand All @@ -621,7 +610,7 @@ openshift:
}

func TestServerAddrConfigPriority(t *testing.T) {
var configYaml = `
configYaml := `
version: 0.1
http:
addr: :5000
Expand Down Expand Up @@ -663,10 +652,6 @@ openshift:
setenv: []env{{name: "DOCKER_REGISTRY_URL", value: "DOCKER_REGISTRY_URL"}},
expected: "DOCKER_REGISTRY_URL",
},
{
setenv: []env{{name: "OPENSHIFT_DEFAULT_REGISTRY", value: "OPENSHIFT_DEFAULT_REGISTRY"}},
expected: "OPENSHIFT_DEFAULT_REGISTRY",
},
}

for _, test := range testCases {
Expand All @@ -685,7 +670,7 @@ openshift:
}

func TestAudit(t *testing.T) {
var configYaml = `
configYaml := `
version: 0.1
http:
addr: :5000
Expand Down Expand Up @@ -716,7 +701,7 @@ openshift:
}

func testDisableInmemoryCacheName(t *testing.T, field string) {
var configYaml = `
configYaml := `
version: 0.1
http:
addr: :5000
Expand Down Expand Up @@ -747,7 +732,7 @@ func testDisableInmemoryCache(t *testing.T) {
}

func testPreserveRedisCacheName(t *testing.T, field string) {
var configYaml = `
configYaml := `
version: 0.1
http:
addr: :5000
Expand Down Expand Up @@ -784,7 +769,7 @@ func TestPreserveRedisCache(t *testing.T) {
}

func TestDisabledMiddleware(t *testing.T) {
var inputConfigYaml = `
inputConfigYaml := `
version: 0.1
storage:
inmemory: {}
Expand All @@ -801,7 +786,7 @@ openshift:
server:
addr: "localhost:5000"
`
var expectConfigYaml = `
expectConfigYaml := `
version: 0.1
storage:
inmemory: {}
Expand Down

0 comments on commit 855b24b

Please sign in to comment.