Skip to content

Commit 15cdaf6

Browse files
committed
pkg/storage/azure: inject infra lister into GetConfig
1 parent f18db5b commit 15cdaf6

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

pkg/storage/azure/azure.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
configv1 "github.com/openshift/api/config/v1"
3131
imageregistryv1 "github.com/openshift/api/imageregistry/v1"
3232
operatorapiv1 "github.com/openshift/api/operator/v1"
33+
configlisters "github.com/openshift/client-go/config/listers/config/v1"
3334

3435
regopclient "github.com/openshift/cluster-image-registry-operator/pkg/client"
3536
"github.com/openshift/cluster-image-registry-operator/pkg/defaults"
@@ -82,7 +83,7 @@ func (e *errDoesNotExist) Error() string {
8283
// load credentials from ImageRegistryPrivateConfigurationUser secret, if this secret is not
8384
// present this function loads credentials from cluster wide config present on secret
8485
// CloudCredentialsName.
85-
func GetConfig(secLister kcorelisters.SecretNamespaceLister) (*Azure, error) {
86+
func GetConfig(secLister kcorelisters.SecretNamespaceLister, infraLister configlisters.InfrastructureLister) (*Azure, error) {
8687
sec, err := secLister.Get(defaults.ImageRegistryPrivateConfigurationUser)
8788
if err != nil {
8889
if !errors.IsNotFound(err) {
@@ -361,7 +362,7 @@ func (d *driver) CABundle() (string, bool, error) {
361362
// ConfigEnv configures the environment variables that will be used in the
362363
// image registry deployment.
363364
func (d *driver) ConfigEnv() (envs envvar.List, err error) {
364-
cfg, err := GetConfig(d.Listers.Secrets)
365+
cfg, err := GetConfig(d.Listers.Secrets, d.Listers.Infrastructures)
365366
if err != nil {
366367
return nil, err
367368
}
@@ -449,7 +450,7 @@ func (d *driver) StorageExists(cr *imageregistryv1.Config) (bool, error) {
449450
return false, nil
450451
}
451452

452-
cfg, err := GetConfig(d.Listers.Secrets)
453+
cfg, err := GetConfig(d.Listers.Secrets, d.Listers.Infrastructures)
453454
if err != nil {
454455
util.UpdateCondition(cr, defaults.StorageExists, operatorapiv1.ConditionUnknown, storageExistsReasonConfigError, fmt.Sprintf("Unable to get configuration: %s", err))
455456
return false, err
@@ -649,7 +650,7 @@ func (d *driver) processUPI(cr *imageregistryv1.Config) {
649650

650651
// CreateStorage attempts to create a storage account and a storage container.
651652
func (d *driver) CreateStorage(cr *imageregistryv1.Config) error {
652-
cfg, err := GetConfig(d.Listers.Secrets)
653+
cfg, err := GetConfig(d.Listers.Secrets, d.Listers.Infrastructures)
653654
if err != nil {
654655
util.UpdateCondition(
655656
cr,
@@ -749,7 +750,7 @@ func (d *driver) RemoveStorage(cr *imageregistryv1.Config) (retry bool, err erro
749750
return false, nil
750751
}
751752

752-
cfg, err := GetConfig(d.Listers.Secrets)
753+
cfg, err := GetConfig(d.Listers.Secrets, d.Listers.Infrastructures)
753754
if err != nil {
754755
util.UpdateCondition(cr, defaults.StorageExists, operatorapiv1.ConditionUnknown, storageExistsReasonConfigError, fmt.Sprintf("Unable to get configuration: %s", err))
755756
return false, err

pkg/storage/azure/azure_test.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/Azure/go-autorest/autorest/mocks"
1919
"github.com/google/go-cmp/cmp"
2020

21+
configlisters "github.com/openshift/client-go/config/listers/config/v1"
2122
corev1 "k8s.io/api/core/v1"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/runtime"
@@ -159,8 +160,9 @@ func TestGetConfig(t *testing.T) {
159160
_ = indexer.Add(o)
160161
}
161162
lister := corev1listers.NewSecretLister(indexer)
163+
infraLister := fakeInfrastructureLister("resource-group-123")
162164

163-
result, err := GetConfig(lister.Secrets("test"))
165+
result, err := GetConfig(lister.Secrets("test"), infraLister)
164166
if len(tt.err) != 0 {
165167
if err == nil {
166168
t.Errorf("expected err %q, nil received instead", tt.err)
@@ -182,6 +184,29 @@ func TestGetConfig(t *testing.T) {
182184
}
183185
}
184186

187+
func fakeInfrastructureLister(resourceGroup string) configlisters.InfrastructureLister {
188+
fakeIndexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{})
189+
err := fakeIndexer.Add(&configv1.Infrastructure{
190+
ObjectMeta: metav1.ObjectMeta{
191+
Name: "cluster",
192+
},
193+
Status: configv1.InfrastructureStatus{
194+
InfrastructureName: "user-j45xj",
195+
Platform: configv1.OpenStackPlatformType,
196+
PlatformStatus: &configv1.PlatformStatus{
197+
Type: configv1.AzurePlatformType,
198+
Azure: &configv1.AzurePlatformStatus{
199+
ResourceGroupName: resourceGroup,
200+
},
201+
},
202+
},
203+
})
204+
if err != nil {
205+
panic(err) // should never happen
206+
}
207+
return configlisters.NewInfrastructureLister(fakeIndexer)
208+
}
209+
185210
func TestGenerateAccountName(t *testing.T) {
186211
re := regexp.MustCompile(`^[0-9a-z]{3,24}$`)
187212
for _, infrastructureName := range []string{

0 commit comments

Comments
 (0)