Skip to content

Commit 6372c1a

Browse files
author
Xin Li
authored
Fix create configmap (#54)
1 parent 0842ebc commit 6372c1a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

controllers/namespacescope_controller.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,22 @@ func (r *NamespaceScopeReconciler) UpdateConfigMap(instance *operatorv1.Namespac
158158

159159
if err := r.Get(ctx, cmKey, cm); err != nil {
160160
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, ",")}
164165
// Set NamespaceScope instance as the owner of the ConfigMap.
165166
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)
167168
return err
168169
}
170+
169171
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)
171173
return err
172174
}
173-
klog.Infof("Created ConfigMap %s in namespace %s", cmName, cmNamespace)
175+
klog.Infof("Created ConfigMap %s", cmKey.String())
176+
174177
if err := r.RestartPods(instance.Spec.RestartLabels, instance.Namespace); err != nil {
175178
return err
176179
}
@@ -189,14 +192,15 @@ func (r *NamespaceScopeReconciler) UpdateConfigMap(instance *operatorv1.Namespac
189192
}
190193

191194
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)
193196
return err
194197
}
195198

196199
if err := r.Update(ctx, cm); err != nil {
197200
klog.Errorf("Failed to update ConfigMap %s : %v", cmKey.String(), err)
198201
return err
199202
}
203+
klog.Infof("Updated ConfigMap %s", cmKey.String())
200204

201205
// When the configmap updated, restart all the pods with the RestartLabels
202206
if restartpod {

0 commit comments

Comments
 (0)