Skip to content

Commit

Permalink
registry: add dockerregistryurl optional to middleware config
Browse files Browse the repository at this point in the history
  • Loading branch information
mfojtik committed Sep 18, 2017
1 parent f7ec657 commit f8d7d28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 11 additions & 0 deletions pkg/dockerregistry/server/repositoryconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const (
// DEPRECATED: Use the OPENSHIFT_DEFAULT_REGISTRY instead.
DockerRegistryURLEnvVar = "DOCKER_REGISTRY_URL"

// DockerRegistryURLEnvVarOption is an optional environment that overrides the
// DOCKER_REGISTRY_URL.
DockerRegistryURLEnvVarOption = "REGISTRY_MIDDLEWARE_REPOSITORY_OPENSHIFT_DOCKERREGISTRYURL"

// OpenShiftDefaultRegistry overrides the DockerRegistryURLEnvVar as in OpenShift the
// default registry URL is controller by this environment variable.
OpenShiftDefaultRegistryEnvVar = "OPENSHIFT_DEFAULT_REGISTRY"
Expand Down Expand Up @@ -74,6 +78,13 @@ func newRepositoryConfig(ctx context.Context, options map[string]interface{}) (r
} else {
context.GetLogger(ctx).Infof("DEPRECATED: %q is deprecated, use the %q instead", DockerRegistryURLEnvVar, OpenShiftDefaultRegistryEnvVar)
}
if len(rc.registryAddr) == 0 {
rc.registryAddr, err = getStringOption(DockerRegistryURLEnvVarOption, "dockerregistryurl", rc.registryAddr, options)
if err != nil {
return
}
}

// 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(rc.registryAddr) == 0 {
Expand Down
11 changes: 2 additions & 9 deletions pkg/dockerregistry/server/signaturedispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"reflect"
"testing"

Expand Down Expand Up @@ -57,8 +56,6 @@ func TestSignatureGet(t *testing.T) {
t.Fatal(err)
}

os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", "localhost:5000")

ctx := context.Background()
ctx = withUserClient(ctx, osclient)
registryApp := NewApp(ctx, registryclient.NewFakeRegistryClient(imageClient), &configuration.Configuration{
Expand All @@ -82,7 +79,7 @@ func TestSignatureGet(t *testing.T) {
},
Middleware: map[string][]configuration.Middleware{
"registry": {{Name: "openshift"}},
"repository": {{Name: "openshift"}},
"repository": {{Name: "openshift", Options: configuration.Parameters{"dockerregistryurl": "localhost:5000"}}},
"storage": {{Name: "openshift"}},
},
}, &registryconfig.Configuration{}, nil)
Expand All @@ -93,7 +90,6 @@ func TestSignatureGet(t *testing.T) {
if err != nil {
t.Fatalf("error parsing server url: %v", err)
}
os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", serverURL.Host)

url := fmt.Sprintf("http://%s/extensions/v2/user/app/signatures/%s", serverURL.Host, testImage.Name)

Expand Down Expand Up @@ -165,8 +161,6 @@ func TestSignaturePut(t *testing.T) {
t.Fatal(err)
}

os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", "localhost:5000")

ctx := context.Background()
ctx = withUserClient(ctx, osclient)
registryApp := NewApp(ctx, registryclient.NewFakeRegistryClient(imageClient), &configuration.Configuration{
Expand All @@ -190,7 +184,7 @@ func TestSignaturePut(t *testing.T) {
},
Middleware: map[string][]configuration.Middleware{
"registry": {{Name: "openshift"}},
"repository": {{Name: "openshift"}},
"repository": {{Name: "openshift", Options: configuration.Parameters{"dockerregistryurl": "localhost:5000"}}},
"storage": {{Name: "openshift"}},
},
}, &registryconfig.Configuration{}, nil)
Expand All @@ -201,7 +195,6 @@ func TestSignaturePut(t *testing.T) {
if err != nil {
t.Fatalf("error parsing server url: %v", err)
}
os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", serverURL.Host)

signData, err := json.Marshal(testSignature)
if err != nil {
Expand Down

0 comments on commit f8d7d28

Please sign in to comment.