Skip to content

Commit 16c6890

Browse files
committed
Refactor label value parsing for ConfigMap controller
1 parent 5050084 commit 16c6890

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

controllers/configmap_controller.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,25 @@ func (r *ConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
8888
}
8989
ok, err = strconv.ParseBool(inject)
9090
if err != nil {
91-
l.Info("Failed to parse label value as boolean", "value", inject)
91+
l.V(1).Info("Failed to parse label value as boolean", "value", inject)
92+
// don't requeue
93+
return ctrl.Result{}, nil
9294
}
93-
if ok {
94-
origCM := cm.DeepCopy()
95-
if cm.Data == nil {
96-
cm.Data = map[string]string{}
97-
}
98-
cm.Data["ca.crt"] = serviceCA
99-
if !reflect.DeepEqual(cm.Data, origCM.Data) {
100-
// Only update CM if we're actually making changes
101-
l.Info("Updating Service CA in key `ca.crt`")
102-
r.Update(ctx, &cm)
103-
}
104-
} else {
105-
l.Info("Label value is `false`, not injecting CA")
95+
if !ok {
96+
l.V(1).Info("Label value is `false`, not injecting CA")
97+
// don't requeue
98+
return ctrl.Result{}, nil
99+
}
100+
101+
origCM := cm.DeepCopy()
102+
if cm.Data == nil {
103+
cm.Data = map[string]string{}
104+
}
105+
cm.Data["ca.crt"] = serviceCA
106+
if !reflect.DeepEqual(cm.Data, origCM.Data) {
107+
// Only update CM if we're actually making changes
108+
l.Info("Updating Service CA in key `ca.crt`")
109+
r.Update(ctx, &cm)
106110
}
107111

108112
return ctrl.Result{}, nil

0 commit comments

Comments
 (0)