@@ -115,12 +115,13 @@ func (r *CloudConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
115115 Namespace : OpenshiftConfigNamespace ,
116116 }
117117 if err := r .Get (ctx , openshiftUnmanagedCMKey , sourceCM ); errors .IsNotFound (err ) {
118- klog .Warningf ("unmanaged cloud-config is not found, falling back to default cloud config." )
118+ klog .Warningf ("managed cloud-config is not found, falling back to default cloud config." )
119119 } else if err != nil {
120- klog .Errorf ("unable to get cloud-config for sync" )
120+ klog .Errorf ("unable to get cloud-config for sync: %v" , err )
121121 if err := r .setDegradedCondition (ctx ); err != nil {
122122 return ctrl.Result {}, fmt .Errorf ("failed to set conditions for cloud config controller: %v" , err )
123123 }
124+ return ctrl.Result {}, err
124125 }
125126 }
126127
@@ -206,6 +207,9 @@ func (r *CloudConfigReconciler) isCloudConfigSyncNeeded(platformStatus *configv1
206207
207208// prepareSourceConfigMap creates a usable ConfigMap for further processing into a cloud.conf file.
208209func (r * CloudConfigReconciler ) prepareSourceConfigMap (source * corev1.ConfigMap , infra * configv1.Infrastructure ) (* corev1.ConfigMap , error ) {
210+ if source == nil {
211+ return nil , fmt .Errorf ("received empty configmap for cloud config" )
212+ }
209213 cloudConfCm := source .DeepCopy ()
210214 // We might have an empty ConfigMap in clusters created before 4.14.
211215 if cloudConfCm .Data == nil {
@@ -216,24 +220,27 @@ func (r *CloudConfigReconciler) prepareSourceConfigMap(source *corev1.ConfigMap,
216220 // Always use "cloud.conf" which is default one across openshift
217221 if _ , ok := cloudConfCm .Data [defaultConfigKey ]; ok {
218222 return cloudConfCm , nil
223+ } else {
224+ // Make an entry for the default key even if it didn't exist.
225+ cloudConfCm .Data [defaultConfigKey ] = ""
219226 }
220227
221- // If a user provides their own cloud config, copy that over into the default key .
228+ // If a user provides their own cloud config.. .
222229 infraConfigKey := infra .Spec .CloudConfig .Key
223- if val , ok := cloudConfCm .Data [infraConfigKey ]; ok {
224- cloudConfCm .Data [defaultConfigKey ] = val
225- delete (cloudConfCm .Data , infraConfigKey )
226- return cloudConfCm , nil
227- } else if ! ok && len (cloudConfCm .Data ) > 0 {
228- // Return an error if they provided a non-existent one and there was a cloud.conf specified.
229- return nil , fmt .Errorf ("key %s specified in infra resource does not exist in source configmap %s" ,
230- infraConfigKey , client .ObjectKeyFromObject (source ),
231- )
230+ if infraConfigKey != "" {
231+ if val , ok := cloudConfCm .Data [infraConfigKey ]; ok {
232+ // ..., copy that over into the default key.
233+ cloudConfCm .Data [defaultConfigKey ] = val
234+ delete (cloudConfCm .Data , infraConfigKey )
235+ return cloudConfCm , nil
236+ } else if ! ok {
237+ // Return an error if they provided a non-existent one and there was a cloud.conf specified.
238+ return nil , fmt .Errorf ("key %s specified in infra resource does not exist in source configmap %s" ,
239+ infraConfigKey , client .ObjectKeyFromObject (source ),
240+ )
241+ }
232242 }
233243
234- // If there was no data in the configmap and the user didn't specify their own make a default entry for it.
235- cloudConfCm .Data [defaultConfigKey ] = ""
236-
237244 return cloudConfCm , nil
238245}
239246
0 commit comments