@@ -28,6 +28,8 @@ const (
28
28
infraCloudConfKey = "foo"
29
29
30
30
defaultAzureConfig = `{"cloud":"AzurePublicCloud","tenantId":"0000000-0000-0000-0000-000000000000","Entries":null,"subscriptionId":"0000000-0000-0000-0000-000000000000","vmType":"standard","putVMSSVMBatchSize":0,"enableMigrateToIPBasedBackendPoolAPI":false,"clusterServiceLoadBalancerHealthProbeMode":"shared"}`
31
+ defaultAWSConfig = `[Global]
32
+ `
31
33
)
32
34
33
35
func makeInfrastructureResource (platform configv1.PlatformType ) * configv1.Infrastructure {
@@ -84,8 +86,7 @@ func makeInfraStatus(platform configv1.PlatformType) configv1.InfrastructureStat
84
86
}
85
87
86
88
func makeInfraCloudConfig (platform configv1.PlatformType ) * corev1.ConfigMap {
87
- defaultConfig := `[Global]
88
- `
89
+ defaultConfig := defaultAWSConfig
89
90
90
91
if platform == configv1 .AzurePlatformType {
91
92
defaultConfig = defaultAzureConfig
@@ -98,8 +99,7 @@ func makeInfraCloudConfig(platform configv1.PlatformType) *corev1.ConfigMap {
98
99
}
99
100
100
101
func makeManagedCloudConfig (platform configv1.PlatformType ) * corev1.ConfigMap {
101
- defaultConfig := `[Global]
102
- `
102
+ defaultConfig := defaultAWSConfig
103
103
104
104
if platform == configv1 .AzurePlatformType {
105
105
defaultConfig = defaultAzureConfig
@@ -151,14 +151,6 @@ var _ = Describe("prepareSourceConfigMap reconciler method", func() {
151
151
Expect (reconciler .isCloudConfigEqual (preparedConfig , managedCloudConfig )).Should (BeTrue ())
152
152
})
153
153
154
- It ("config preparation should fail if key from infra resource does not found" , func () {
155
- brokenInfraConfig := infraCloudConfig .DeepCopy ()
156
- brokenInfraConfig .Data = map [string ]string {"hehehehehe" : "bar" }
157
- _ , err := reconciler .prepareSourceConfigMap (brokenInfraConfig , infra )
158
- Expect (err ).Should (Not (Succeed ()))
159
- Expect (err .Error ()).Should (BeEquivalentTo ("key foo specified in infra resource does not found in source configmap openshift-config/test-config" ))
160
- })
161
-
162
154
It ("config preparation should not touch extra fields in infra ConfigMap" , func () {
163
155
extendedInfraConfig := infraCloudConfig .DeepCopy ()
164
156
extendedInfraConfig .Data = map [string ]string {infraCloudConfKey : "{}" , "{}" : "{}" }
@@ -467,21 +459,28 @@ var _ = Describe("Cloud config sync reconciler", func() {
467
459
Expect (cl .Create (ctx , makeInfraCloudConfig (configv1 .AWSPlatformType ))).To (Succeed ())
468
460
})
469
461
470
- It ("should skip config sync for AWS platform if there is no reference in infra resource" , func () {
462
+ It ("should sync a default config AWS platform if there is no reference in infra resource" , func () {
471
463
infraResource := makeInfrastructureResource (configv1 .AWSPlatformType )
472
464
infraResource .Spec .CloudConfig .Name = ""
473
465
Expect (cl .Create (ctx , infraResource )).To (Succeed ())
474
466
475
467
infraResource .Status = makeInfraStatus (infraResource .Spec .PlatformSpec .Type )
476
468
Expect (cl .Status ().Update (ctx , infraResource .DeepCopy ())).To (Succeed ())
477
469
470
+ fetchedResource := & configv1.Infrastructure {}
471
+ Expect (cl .Get (ctx , client .ObjectKeyFromObject (infraResource ), fetchedResource )).To (Succeed ())
472
+ Expect (fetchedResource .Spec .CloudConfig .Name ).To (Equal ("" ))
473
+
478
474
_ , err := reconciler .Reconcile (context .TODO (), ctrl.Request {})
479
475
Expect (err ).To (BeNil ())
480
476
481
477
allCMs := & corev1.ConfigMapList {}
482
478
Expect (cl .List (ctx , allCMs , & client.ListOptions {Namespace : targetNamespaceName })).To (Succeed ())
483
479
484
- Expect (len (allCMs .Items )).To (BeZero ())
480
+ Expect (len (allCMs .Items )).To (BeEquivalentTo (1 ))
481
+ // Our code ensures that there is at a minimum a global section.
482
+ // The CCM itself may end up defaulting values for us, so don't use exact string matching.
483
+ Expect (allCMs .Items [0 ].Data [defaultConfigKey ]).To (HavePrefix (defaultAWSConfig ))
485
484
})
486
485
487
486
It ("should perform config sync for AWS platform if there is a reference in infra resource" , func () {
@@ -500,6 +499,19 @@ var _ = Describe("Cloud config sync reconciler", func() {
500
499
Expect (len (allCMs .Items )).NotTo (BeZero ())
501
500
Expect (len (allCMs .Items )).To (BeEquivalentTo (1 ))
502
501
})
502
+
503
+ It ("should error if a user-specified configmap key isn't present" , func () {
504
+ infraResource := makeInfrastructureResource (configv1 .AWSPlatformType )
505
+ infraResource .Spec .CloudConfig .Key = "notfound"
506
+ Expect (cl .Create (ctx , infraResource )).To (Succeed ())
507
+
508
+ infraResource .Status = makeInfraStatus (infraResource .Spec .PlatformSpec .Type )
509
+ Expect (cl .Status ().Update (ctx , infraResource .DeepCopy ())).To (Succeed ())
510
+
511
+ _ , err := reconciler .Reconcile (context .TODO (), ctrl.Request {})
512
+ Expect (err ).To (Not (BeNil ()))
513
+
514
+ })
503
515
})
504
516
505
517
Context ("On Azure platform" , func () {
0 commit comments