@@ -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,29 @@ 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 = ""
465+ infraResource .Spec .CloudConfig .Key = ""
473466 Expect (cl .Create (ctx , infraResource )).To (Succeed ())
474467
475468 infraResource .Status = makeInfraStatus (infraResource .Spec .PlatformSpec .Type )
476469 Expect (cl .Status ().Update (ctx , infraResource .DeepCopy ())).To (Succeed ())
477470
471+ fetchedResource := & configv1.Infrastructure {}
472+ Expect (cl .Get (ctx , client .ObjectKeyFromObject (infraResource ), fetchedResource )).To (Succeed ())
473+ Expect (fetchedResource .Spec .CloudConfig .Name ).To (Equal ("" ))
474+
478475 _ , err := reconciler .Reconcile (context .TODO (), ctrl.Request {})
479476 Expect (err ).To (BeNil ())
480477
481478 allCMs := & corev1.ConfigMapList {}
482479 Expect (cl .List (ctx , allCMs , & client.ListOptions {Namespace : targetNamespaceName })).To (Succeed ())
483480
484- Expect (len (allCMs .Items )).To (BeZero ())
481+ Expect (len (allCMs .Items )).To (BeEquivalentTo (1 ))
482+ // Our code ensures that there is at a minimum a global section.
483+ // The CCM itself may end up defaulting values for us, so don't use exact string matching.
484+ Expect (allCMs .Items [0 ].Data [defaultConfigKey ]).To (HavePrefix (defaultAWSConfig ))
485485 })
486486
487487 It ("should perform config sync for AWS platform if there is a reference in infra resource" , func () {
@@ -500,6 +500,19 @@ var _ = Describe("Cloud config sync reconciler", func() {
500500 Expect (len (allCMs .Items )).NotTo (BeZero ())
501501 Expect (len (allCMs .Items )).To (BeEquivalentTo (1 ))
502502 })
503+
504+ It ("should error if a user-specified configmap key isn't present" , func () {
505+ infraResource := makeInfrastructureResource (configv1 .AWSPlatformType )
506+ infraResource .Spec .CloudConfig .Key = "notfound"
507+ Expect (cl .Create (ctx , infraResource )).To (Succeed ())
508+
509+ infraResource .Status = makeInfraStatus (infraResource .Spec .PlatformSpec .Type )
510+ Expect (cl .Status ().Update (ctx , infraResource .DeepCopy ())).To (Succeed ())
511+
512+ _ , err := reconciler .Reconcile (context .TODO (), ctrl.Request {})
513+ Expect (err .Error ()).To (ContainSubstring ("specified in infra resource does not exist in source configmap" ))
514+
515+ })
503516 })
504517
505518 Context ("On Azure platform" , func () {
0 commit comments