@@ -158,19 +158,22 @@ func (r *NamespaceScopeReconciler) UpdateConfigMap(instance *operatorv1.Namespac
158
158
159
159
if err := r .Get (ctx , cmKey , cm ); err != nil {
160
160
if errors .IsNotFound (err ) {
161
- cm .Labels = map [string ]string {constant .NamespaceScopeLabel : "true" }
162
- cm .Data = make (map [string ]string )
163
- cm .Data ["namespaces" ] = strings .Join (validatedMembers , "," )
161
+ cm .SetName (cmName )
162
+ cm .SetNamespace (cmNamespace )
163
+ cm .SetLabels (map [string ]string {constant .NamespaceScopeLabel : "true" })
164
+ cm .Data = map [string ]string {"namespaces" : strings .Join (validatedMembers , "," )}
164
165
// Set NamespaceScope instance as the owner of the ConfigMap.
165
166
if err := controllerutil .SetOwnerReference (instance , cm , r .Scheme ); err != nil {
166
- klog .Errorf ("Failed to set owner reference for ConfigMap %s/%s : %v" , cmNamespace , cmName , err )
167
+ klog .Errorf ("Failed to set owner reference for ConfigMap %s: %v" , cmKey . String () , err )
167
168
return err
168
169
}
170
+
169
171
if err := r .Create (ctx , cm ); err != nil {
170
- klog .Errorf ("Failed to create ConfigMap %s in namespace %s : %v" , cmName , cmNamespace , err )
172
+ klog .Errorf ("Failed to create ConfigMap %s: %v" , cmKey . String () , err )
171
173
return err
172
174
}
173
- klog .Infof ("Created ConfigMap %s in namespace %s" , cmName , cmNamespace )
175
+ klog .Infof ("Created ConfigMap %s" , cmKey .String ())
176
+
174
177
if err := r .RestartPods (instance .Spec .RestartLabels , instance .Namespace ); err != nil {
175
178
return err
176
179
}
@@ -189,14 +192,15 @@ func (r *NamespaceScopeReconciler) UpdateConfigMap(instance *operatorv1.Namespac
189
192
}
190
193
191
194
if err := controllerutil .SetOwnerReference (instance , cm , r .Scheme ); err != nil {
192
- klog .Errorf ("Failed to set owner reference for ConfigMap %s/%s : %v" , cm . Namespace , cm . Name , err )
195
+ klog .Errorf ("Failed to set owner reference for ConfigMap %s: %v" , cmKey . String () , err )
193
196
return err
194
197
}
195
198
196
199
if err := r .Update (ctx , cm ); err != nil {
197
200
klog .Errorf ("Failed to update ConfigMap %s : %v" , cmKey .String (), err )
198
201
return err
199
202
}
203
+ klog .Infof ("Updated ConfigMap %s" , cmKey .String ())
200
204
201
205
// When the configmap updated, restart all the pods with the RestartLabels
202
206
if restartpod {
0 commit comments