Skip to content

Commit 04a3430

Browse files
chris-rockclaude
andcommitted
Set degraded condition instead of returning error for invalid annotations
Instead of returning an error (which causes infinite requeue with backoff), set MondooOperatorDegraded condition so users can see the problem via kubectl describe. The condition is cleared when annotations become valid. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 072c03e commit 04a3430

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

controllers/mondooauditconfig_controller.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,6 @@ func (r *MondooAuditConfigReconciler) Reconcile(ctx context.Context, req ctrl.Re
184184
return ctrl.Result{Requeue: true}, nil
185185
}
186186

187-
// Validate annotations before using them in inventory or CLI args
188-
if err := annotations.Validate(mondooAuditConfig.Spec.Annotations); err != nil {
189-
log.Error(err, "invalid annotations in MondooAuditConfig")
190-
return ctrl.Result{}, err
191-
}
192-
193187
mondooAuditConfigCopy := mondooAuditConfig.DeepCopy()
194188

195189
// Conditions might be updated before this reconciler reaches the end
@@ -228,6 +222,34 @@ func (r *MondooAuditConfigReconciler) Reconcile(ctx context.Context, req ctrl.Re
228222
}
229223
}()
230224

225+
// Validate annotations before using them in inventory or CLI args.
226+
// Set a degraded condition so users can see the problem via kubectl describe.
227+
if err := annotations.Validate(mondooAuditConfig.Spec.Annotations); err != nil {
228+
mondooAuditConfig.Status.Conditions = mondoo.SetMondooAuditCondition(
229+
mondooAuditConfig.Status.Conditions,
230+
v1alpha2.MondooOperatorDegraded,
231+
corev1.ConditionTrue,
232+
"InvalidAnnotations",
233+
fmt.Sprintf("Invalid annotations in MondooAuditConfig: %s", err),
234+
mondoo.UpdateConditionIfReasonOrMessageChange,
235+
nil, "",
236+
)
237+
log.Error(err, "invalid annotations in MondooAuditConfig, skipping reconciliation")
238+
return ctrl.Result{}, nil
239+
}
240+
// Clear any previous annotation validation error
241+
if cond := mondoo.FindMondooAuditConditions(mondooAuditConfig.Status.Conditions, v1alpha2.MondooOperatorDegraded); cond != nil && cond.Reason == "InvalidAnnotations" {
242+
mondooAuditConfig.Status.Conditions = mondoo.SetMondooAuditCondition(
243+
mondooAuditConfig.Status.Conditions,
244+
v1alpha2.MondooOperatorDegraded,
245+
corev1.ConditionFalse,
246+
"AnnotationsValid",
247+
"Annotations are valid",
248+
mondoo.UpdateConditionAlways,
249+
nil, "",
250+
)
251+
}
252+
231253
// If spec.MondooTokenSecretRef != "" and the Secret referenced in spec.MondooCredsSecretRef
232254
// does not exist, then attempt to trade the token for a Mondoo service account and save it
233255
// in the Secret referenced in .spec.MondooCredsSecretRef

0 commit comments

Comments
 (0)