diff --git a/api/v1beta1/alert_types.go b/api/v1beta1/alert_types.go index 0e8c30f04..db58ba3e2 100644 --- a/api/v1beta1/alert_types.go +++ b/api/v1beta1/alert_types.go @@ -101,3 +101,9 @@ type AlertList struct { func init() { SchemeBuilder.Register(&Alert{}, &AlertList{}) } + +func SetAlertReadiness(alert Alert, status metav1.ConditionStatus, reason, message string) Alert { + meta.SetResourceCondition(&alert, meta.ReadyCondition, status, reason, message) + alert.Status.ObservedGeneration = alert.Generation + return alert +} diff --git a/api/v1beta1/provider_types.go b/api/v1beta1/provider_types.go index 76a560c39..ee7f759a4 100644 --- a/api/v1beta1/provider_types.go +++ b/api/v1beta1/provider_types.go @@ -127,3 +127,9 @@ type ProviderList struct { func init() { SchemeBuilder.Register(&Provider{}, &ProviderList{}) } + +func SetProviderReadiness(provider Provider, status metav1.ConditionStatus, reason, message string) Provider { + meta.SetResourceCondition(&provider, meta.ReadyCondition, status, reason, message) + provider.Status.ObservedGeneration = provider.Generation + return provider +} diff --git a/api/v1beta1/receiver_types.go b/api/v1beta1/receiver_types.go index a87b23bdb..b07c695f0 100644 --- a/api/v1beta1/receiver_types.go +++ b/api/v1beta1/receiver_types.go @@ -82,12 +82,14 @@ const ( func ReceiverReady(receiver Receiver, reason, message, url string) Receiver { meta.SetResourceCondition(&receiver, meta.ReadyCondition, metav1.ConditionTrue, reason, message) + receiver.Status.ObservedGeneration = receiver.Generation receiver.Status.URL = url return receiver } func ReceiverNotReady(receiver Receiver, reason, message string) Receiver { meta.SetResourceCondition(&receiver, meta.ReadyCondition, metav1.ConditionFalse, reason, message) + receiver.Status.ObservedGeneration = receiver.Generation return receiver } diff --git a/controllers/alert_controller.go b/controllers/alert_controller.go index 90b0d47b9..5acaac71c 100644 --- a/controllers/alert_controller.go +++ b/controllers/alert_controller.go @@ -71,7 +71,7 @@ func (r *AlertReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl // validate alert spec and provider if err := r.validate(ctx, alert); err != nil { - meta.SetResourceCondition(&alert, meta.ReadyCondition, metav1.ConditionFalse, meta.ReconciliationFailedReason, err.Error()) + alert = v1beta1.SetAlertReadiness(alert, metav1.ConditionFalse, meta.ReconciliationFailedReason, err.Error()) if err := r.patchStatus(ctx, req, alert.Status); err != nil { return ctrl.Result{Requeue: true}, err } @@ -79,8 +79,7 @@ func (r *AlertReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl } if !apimeta.IsStatusConditionTrue(alert.Status.Conditions, meta.ReadyCondition) || alert.Status.ObservedGeneration != alert.Generation { - meta.SetResourceCondition(&alert, meta.ReadyCondition, metav1.ConditionTrue, v1beta1.InitializedReason, v1beta1.InitializedReason) - alert.Status.ObservedGeneration = alert.Generation + alert = v1beta1.SetAlertReadiness(alert, metav1.ConditionTrue, v1beta1.InitializedReason, v1beta1.InitializedReason) if err := r.patchStatus(ctx, req, alert.Status); err != nil { return ctrl.Result{Requeue: true}, err } diff --git a/controllers/provider_controller.go b/controllers/provider_controller.go index a7e9105d9..1528fffd3 100644 --- a/controllers/provider_controller.go +++ b/controllers/provider_controller.go @@ -71,7 +71,7 @@ func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c // validate provider spec and credentials if err := r.validate(ctx, provider); err != nil { - meta.SetResourceCondition(&provider, meta.ReadyCondition, metav1.ConditionFalse, meta.ReconciliationFailedReason, err.Error()) + provider = v1beta1.SetProviderReadiness(provider, metav1.ConditionFalse, meta.ReconciliationFailedReason, err.Error()) if err := r.patchStatus(ctx, req, provider.Status); err != nil { return ctrl.Result{Requeue: true}, err } @@ -79,7 +79,7 @@ func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c } if !apimeta.IsStatusConditionTrue(provider.Status.Conditions, meta.ReadyCondition) { - meta.SetResourceCondition(&provider, meta.ReadyCondition, metav1.ConditionTrue, v1beta1.InitializedReason, v1beta1.InitializedReason) + provider = v1beta1.SetProviderReadiness(provider, metav1.ConditionTrue, v1beta1.InitializedReason, v1beta1.InitializedReason) if err := r.patchStatus(ctx, req, provider.Status); err != nil { return ctrl.Result{Requeue: true}, err } diff --git a/controllers/receiver_controller.go b/controllers/receiver_controller.go index 795df0714..b4f45490c 100644 --- a/controllers/receiver_controller.go +++ b/controllers/receiver_controller.go @@ -85,7 +85,6 @@ func (r *ReceiverReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c v1beta1.InitializedReason, "Receiver initialised with URL: "+receiverURL, receiverURL) - receiver.Status.ObservedGeneration = receiver.Generation if err := r.patchStatus(ctx, req, receiver.Status); err != nil { return ctrl.Result{Requeue: true}, err }