@@ -28,6 +28,8 @@ const (
2828 infraCloudConfKey = "foo"
2929
3030 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+ `
3133)
3234
3335func makeInfrastructureResource (platform configv1.PlatformType ) * configv1.Infrastructure {
@@ -84,8 +86,7 @@ func makeInfraStatus(platform configv1.PlatformType) configv1.InfrastructureStat
8486}
8587
8688func makeInfraCloudConfig (platform configv1.PlatformType ) * corev1.ConfigMap {
87- defaultConfig := `[Global]
88- `
89+ defaultConfig := defaultAWSConfig
8990
9091 if platform == configv1 .AzurePlatformType {
9192 defaultConfig = defaultAzureConfig
@@ -98,8 +99,7 @@ func makeInfraCloudConfig(platform configv1.PlatformType) *corev1.ConfigMap {
9899}
99100
100101func makeManagedCloudConfig (platform configv1.PlatformType ) * corev1.ConfigMap {
101- defaultConfig := `[Global]
102- `
102+ defaultConfig := defaultAWSConfig
103103
104104 if platform == configv1 .AzurePlatformType {
105105 defaultConfig = defaultAzureConfig
@@ -151,14 +151,6 @@ var _ = Describe("prepareSourceConfigMap reconciler method", func() {
151151 Expect (reconciler .isCloudConfigEqual (preparedConfig , managedCloudConfig )).Should (BeTrue ())
152152 })
153153
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-
162154 It ("config preparation should not touch extra fields in infra ConfigMap" , func () {
163155 extendedInfraConfig := infraCloudConfig .DeepCopy ()
164156 extendedInfraConfig .Data = map [string ]string {infraCloudConfKey : "{}" , "{}" : "{}" }
@@ -467,21 +459,28 @@ var _ = Describe("Cloud config sync reconciler", func() {
467459 Expect (cl .Create (ctx , makeInfraCloudConfig (configv1 .AWSPlatformType ))).To (Succeed ())
468460 })
469461
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 () {
471463 infraResource := makeInfrastructureResource (configv1 .AWSPlatformType )
472464 infraResource .Spec .CloudConfig .Name = ""
473465 Expect (cl .Create (ctx , infraResource )).To (Succeed ())
474466
475467 infraResource .Status = makeInfraStatus (infraResource .Spec .PlatformSpec .Type )
476468 Expect (cl .Status ().Update (ctx , infraResource .DeepCopy ())).To (Succeed ())
477469
470+ fetchedResource := & configv1.Infrastructure {}
471+ Expect (cl .Get (ctx , client .ObjectKeyFromObject (infraResource ), fetchedResource )).To (Succeed ())
472+ Expect (fetchedResource .Spec .CloudConfig .Name ).To (Equal ("" ))
473+
478474 _ , err := reconciler .Reconcile (context .TODO (), ctrl.Request {})
479475 Expect (err ).To (BeNil ())
480476
481477 allCMs := & corev1.ConfigMapList {}
482478 Expect (cl .List (ctx , allCMs , & client.ListOptions {Namespace : targetNamespaceName })).To (Succeed ())
483479
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 ))
485484 })
486485
487486 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() {
500499 Expect (len (allCMs .Items )).NotTo (BeZero ())
501500 Expect (len (allCMs .Items )).To (BeEquivalentTo (1 ))
502501 })
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+ })
503515 })
504516
505517 Context ("On Azure platform" , func () {
0 commit comments