Log and emit events on successful reconciliation
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
parent
caec764ccc
commit
012faa2a08
|
|
@ -117,13 +117,23 @@ func (r *AlertReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resu
|
|||
r.Metrics.RecordDuration(ctx, obj, reconcileStart)
|
||||
r.Metrics.RecordSuspend(ctx, obj, obj.Spec.Suspend)
|
||||
|
||||
// Issue warning event if the reconciliation failed.
|
||||
// Emit warning event if the reconciliation failed.
|
||||
if retErr != nil {
|
||||
r.Event(obj, corev1.EventTypeWarning, meta.FailedReason, retErr.Error())
|
||||
}
|
||||
|
||||
// Log and emit success event.
|
||||
if retErr == nil && conditions.IsReady(obj) {
|
||||
msg := fmt.Sprintf("Reconciliation finished in %s",
|
||||
time.Since(reconcileStart).String())
|
||||
log.Info(msg)
|
||||
r.Event(obj, corev1.EventTypeNormal, meta.SucceededReason, msg)
|
||||
}
|
||||
|
||||
// Patch finalizers, status and conditions.
|
||||
retErr = r.patch(ctx, obj, patcher)
|
||||
if err := r.patch(ctx, obj, patcher); err != nil {
|
||||
retErr = kerrors.NewAggregate([]error{retErr, err})
|
||||
}
|
||||
}()
|
||||
|
||||
if !controllerutil.ContainsFinalizer(obj, apiv1.NotificationFinalizer) {
|
||||
|
|
@ -158,7 +168,6 @@ func (r *AlertReconciler) reconcile(ctx context.Context, alert *apiv1.Alert) (ct
|
|||
}
|
||||
|
||||
conditions.MarkTrue(alert, meta.ReadyCondition, meta.SucceededReason, apiv1.InitializedReason)
|
||||
ctrl.LoggerFrom(ctx).Info("Alert initialized")
|
||||
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,13 +99,23 @@ func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r
|
|||
r.Metrics.RecordDuration(ctx, obj, reconcileStart)
|
||||
r.Metrics.RecordSuspend(ctx, obj, obj.Spec.Suspend)
|
||||
|
||||
// Issue warning event if the reconciliation failed.
|
||||
// Emit warning event if the reconciliation failed.
|
||||
if retErr != nil {
|
||||
r.Event(obj, corev1.EventTypeWarning, meta.FailedReason, retErr.Error())
|
||||
}
|
||||
|
||||
// Log and emit success event.
|
||||
if retErr == nil && conditions.IsReady(obj) {
|
||||
msg := fmt.Sprintf("Reconciliation finished in %s, next run in %s",
|
||||
time.Since(reconcileStart).String(), obj.Spec.Interval.Duration.String())
|
||||
log.Info(msg)
|
||||
r.Event(obj, corev1.EventTypeNormal, meta.SucceededReason, msg)
|
||||
}
|
||||
|
||||
// Patch finalizers, status and conditions.
|
||||
retErr = r.patch(ctx, obj, patcher)
|
||||
if err := r.patch(ctx, obj, patcher); err != nil {
|
||||
retErr = kerrors.NewAggregate([]error{retErr, err})
|
||||
}
|
||||
}()
|
||||
|
||||
if !controllerutil.ContainsFinalizer(obj, apiv1.NotificationFinalizer) {
|
||||
|
|
@ -140,7 +150,6 @@ func (r *ProviderReconciler) reconcile(ctx context.Context, obj *apiv1.Provider)
|
|||
}
|
||||
|
||||
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason, apiv1.InitializedReason)
|
||||
ctrl.LoggerFrom(ctx).Info("Provider initialized")
|
||||
|
||||
return ctrl.Result{RequeueAfter: obj.Spec.Interval.Duration}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,13 +106,23 @@ func (r *ReceiverReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r
|
|||
r.Metrics.RecordDuration(ctx, obj, reconcileStart)
|
||||
r.Metrics.RecordSuspend(ctx, obj, obj.Spec.Suspend)
|
||||
|
||||
// Issue warning event if the reconciliation failed.
|
||||
// Emit warning event if the reconciliation failed.
|
||||
if retErr != nil {
|
||||
r.Event(obj, corev1.EventTypeWarning, meta.FailedReason, retErr.Error())
|
||||
}
|
||||
|
||||
// Log and emit success event.
|
||||
if retErr == nil && conditions.IsReady(obj) {
|
||||
msg := fmt.Sprintf("Reconciliation finished in %s, next run in %s",
|
||||
time.Since(reconcileStart).String(), obj.Spec.Interval.Duration.String())
|
||||
log.Info(msg)
|
||||
r.Event(obj, corev1.EventTypeNormal, meta.SucceededReason, msg)
|
||||
}
|
||||
|
||||
// Patch finalizers, status and conditions.
|
||||
retErr = r.patch(ctx, obj, patcher)
|
||||
if err := r.patch(ctx, obj, patcher); err != nil {
|
||||
retErr = kerrors.NewAggregate([]error{retErr, err})
|
||||
}
|
||||
}()
|
||||
|
||||
if !controllerutil.ContainsFinalizer(obj, apiv1.NotificationFinalizer) {
|
||||
|
|
@ -145,6 +155,7 @@ func (r *ReceiverReconciler) reconcile(ctx context.Context, obj *apiv1.Receiver)
|
|||
token, err := r.token(ctx, obj)
|
||||
if err != nil {
|
||||
conditions.MarkFalse(obj, meta.ReadyCondition, apiv1.TokenNotFoundReason, err.Error())
|
||||
obj.Status.URL = ""
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
}
|
||||
|
||||
|
|
@ -153,9 +164,11 @@ func (r *ReceiverReconciler) reconcile(ctx context.Context, obj *apiv1.Receiver)
|
|||
|
||||
// Mark the resource as ready and set the URL
|
||||
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason, msg)
|
||||
obj.Status.URL = receiverURL
|
||||
|
||||
ctrl.LoggerFrom(ctx).Info(msg)
|
||||
if obj.Status.URL != receiverURL {
|
||||
obj.Status.URL = receiverURL
|
||||
ctrl.LoggerFrom(ctx).Info(msg)
|
||||
}
|
||||
|
||||
return ctrl.Result{RequeueAfter: obj.Spec.Interval.Duration}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue