Skip to content

Commit

Permalink
Set observed generation when recording status
Browse files Browse the repository at this point in the history
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
  • Loading branch information
somtochiama committed Oct 13, 2021
1 parent 7eac4bd commit 209d01e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions api/v1beta1/alert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions api/v1beta1/provider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions api/v1beta1/receiver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions controllers/alert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,15 @@ 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
}
return ctrl.Result{Requeue: true}, err
}

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
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/provider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ 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
}
return ctrl.Result{Requeue: true}, err
}

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
}
Expand Down
1 change: 0 additions & 1 deletion controllers/receiver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 209d01e

Please sign in to comment.