From 1c72f2b9def5ddddbaaf721ab6bca32b86784d6d Mon Sep 17 00:00:00 2001 From: Cole Mickens Date: Thu, 19 Jan 2017 04:22:12 -0800 Subject: [PATCH] azure: acr fix login server --- pkg/credentialprovider/azure/azure_credentials.go | 10 +++++++--- .../azure/azure_credentials_test.go | 11 ++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/credentialprovider/azure/azure_credentials.go b/pkg/credentialprovider/azure/azure_credentials.go index b0191567f64..771c41780b5 100644 --- a/pkg/credentialprovider/azure/azure_credentials.go +++ b/pkg/credentialprovider/azure/azure_credentials.go @@ -17,7 +17,6 @@ limitations under the License. package azure import ( - "fmt" "io/ioutil" "time" @@ -133,12 +132,17 @@ func (a *acrProvider) Provide() credentialprovider.DockerConfig { return cfg } for ix := range *res.Value { - // TODO: I don't think this will work for national clouds - cfg[fmt.Sprintf("%s.azurecr.io", *(*res.Value)[ix].Name)] = entry + loginServer := getLoginServer((*res.Value)[ix]) + glog.V(4).Infof("Adding Azure Container Registry docker credential for %s", loginServer) + cfg[loginServer] = entry } return cfg } +func getLoginServer(registry containerregistry.Registry) string { + return *(*registry.RegistryProperties).LoginServer +} + func (a *acrProvider) LazyProvide() *credentialprovider.DockerConfigEntry { return nil } diff --git a/pkg/credentialprovider/azure/azure_credentials_test.go b/pkg/credentialprovider/azure/azure_credentials_test.go index d034f90e4d4..8f697387768 100644 --- a/pkg/credentialprovider/azure/azure_credentials_test.go +++ b/pkg/credentialprovider/azure/azure_credentials_test.go @@ -41,12 +41,21 @@ func Test(t *testing.T) { Value: &[]containerregistry.Registry{ { Name: to.StringPtr("foo"), + RegistryProperties: &containerregistry.RegistryProperties{ + LoginServer: to.StringPtr("foo-microsoft.azurecr.io"), + }, }, { Name: to.StringPtr("bar"), + RegistryProperties: &containerregistry.RegistryProperties{ + LoginServer: to.StringPtr("bar-microsoft.azurecr.io"), + }, }, { Name: to.StringPtr("baz"), + RegistryProperties: &containerregistry.RegistryProperties{ + LoginServer: to.StringPtr("baz-microsoft.azurecr.io"), + }, }, }, } @@ -73,7 +82,7 @@ func Test(t *testing.T) { } } for _, val := range *result.Value { - registryName := *val.Name + ".azurecr.io" + registryName := getLoginServer(val) if _, found := creds[registryName]; !found { t.Errorf("Missing expected registry: %s", registryName) }