Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set observed generation when recording status #261

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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