From 29cb7ba2a61f697ddb39b55bf9057a33a2017f02 Mon Sep 17 00:00:00 2001 From: Michael Peter Lautrup Date: Tue, 10 Jun 2025 10:23:39 +0200 Subject: [PATCH] expand predicate to also trigger on annotation changes --- api/styra/v1beta1/system_types.go | 4 ++++ internal/controller/styra/system_controller.go | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/api/styra/v1beta1/system_types.go b/api/styra/v1beta1/system_types.go index a63ee542..105b028d 100644 --- a/api/styra/v1beta1/system_types.go +++ b/api/styra/v1beta1/system_types.go @@ -370,6 +370,10 @@ const ( // for the SLP used by the System. EventErrorGetStatefulSet EventType = "ErrorGetStatefulSet" + // EventErrorStatefulSetNotFound is an EventType used when a system with 'localPlane' enabled but which + // does not have a StatefulSet created for the SLP. + EventErrorStatefulSetNotFound EventType = "ErrorStatefulSetNotFound" + // EventErrorPatchStatefulSet is an EventType used when the controller fails to patch the StatefulSet // for the SLP used by the System. EventErrorPatchStatefulSet EventType = "ErrorPatchStatefulSet" diff --git a/internal/controller/styra/system_controller.go b/internal/controller/styra/system_controller.go index 6f26e3ae..508f1bb6 100644 --- a/internal/controller/styra/system_controller.go +++ b/internal/controller/styra/system_controller.go @@ -551,6 +551,12 @@ func (r *SystemReconciler) restartSLPs( nsName := types.NamespacedName{Name: system.Spec.LocalPlane.Name, Namespace: system.Namespace} var sts appsv1.StatefulSet if err := r.Get(ctx, nsName, &sts); err != nil { + if k8serrors.IsNotFound(err) { + log.Info("System has SLP but no SLP found with that name") + return ctrl.Result{}, ctrlerr.Wrap(err, "SLP statefulset not found for system with SLP enabled"). + WithEvent(v1beta1.EventErrorStatefulSetNotFound). + WithSystemCondition(v1beta1.ConditionTypeSLPUpToDate) + } return ctrl.Result{}, ctrlerr.Wrap(err, "Could not get StatefulSet"). WithEvent(v1beta1.EventErrorGetStatefulSet). WithSystemCondition(v1beta1.ConditionTypeSLPUpToDate) @@ -1573,7 +1579,10 @@ func (r *SystemReconciler) SetupWithManager(mgr ctrl.Manager, name string) error if err != nil { return errors.Wrap(err, "Could not build predicate") } - p = ctrlpred.And(p, ctrlpred.GenerationChangedPredicate{}) + + updatedPred := ctrlpred.Or(ctrlpred.GenerationChangedPredicate{}, ctrlpred.LabelChangedPredicate{}) + + p = ctrlpred.And(p, updatedPred) return ctrl.NewControllerManagedBy(mgr).Named(name). For(&v1beta1.System{}, builder.WithPredicates(p)).