Skip to content

Commit c907900

Browse files
authored
Merge pull request #118 from phillebaba/feature/succeeded-event
Send event when reconcile succeeds with update metadata
2 parents ac340ef + 8fed231 commit c907900

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

controllers/kustomization_controller.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
9797
// Our finalizer is still present, so lets handle garbage collection
9898
if kustomization.Spec.Prune && !kustomization.Spec.Suspend {
9999
if err := r.prune(kustomization, kustomization.Status.Snapshot, true); err != nil {
100-
r.event(kustomization, kustomization.Status.LastAppliedRevision, recorder.EventSeverityError, "pruning for deleted resource failed")
100+
r.event(kustomization, kustomization.Status.LastAppliedRevision, recorder.EventSeverityError, "pruning for deleted resource failed", map[string]string{})
101101
// Return the error so we retry the failed garbage collection
102102
return ctrl.Result{}, err
103103
}
@@ -182,7 +182,7 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
182182
// instead we requeue on a fix interval.
183183
msg := fmt.Sprintf("Dependencies do not meet ready condition, retrying in %s", r.requeueDependency.String())
184184
log.Error(err, msg)
185-
r.event(kustomization, source.GetArtifact().Revision, recorder.EventSeverityInfo, msg)
185+
r.event(kustomization, source.GetArtifact().Revision, recorder.EventSeverityInfo, msg, map[string]string{})
186186
return ctrl.Result{RequeueAfter: r.requeueDependency}, nil
187187
}
188188
log.Info("All dependencies area ready, proceeding with reconciliation")
@@ -192,7 +192,7 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
192192
reconciledKustomization, reconcileErr := r.reconcile(*kustomization.DeepCopy(), source)
193193
if reconcileErr != nil {
194194
// broadcast the error
195-
r.event(kustomization, source.GetArtifact().Revision, recorder.EventSeverityError, reconcileErr.Error())
195+
r.event(kustomization, source.GetArtifact().Revision, recorder.EventSeverityError, reconcileErr.Error(), map[string]string{})
196196
}
197197

198198
// update status
@@ -213,6 +213,8 @@ func (r *KustomizationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
213213
// record the reconciliation error
214214
return ctrl.Result{RequeueAfter: kustomization.Spec.Interval.Duration}, reconcileErr
215215
}
216+
217+
r.event(reconciledKustomization, source.GetArtifact().Revision, recorder.EventSeverityInfo, "Update completed", map[string]string{"commit_status": "update"})
216218
return ctrl.Result{RequeueAfter: kustomization.Spec.Interval.Duration}, nil
217219
}
218220

@@ -573,15 +575,15 @@ func (r *KustomizationReconciler) applyWithRetry(kustomization kustomizev1.Kusto
573575
return err
574576
} else {
575577
if changeSet != "" {
576-
r.event(kustomization, revision, recorder.EventSeverityInfo, changeSet)
578+
r.event(kustomization, revision, recorder.EventSeverityInfo, changeSet, map[string]string{})
577579
}
578580
}
579581
} else {
580582
return err
581583
}
582584
} else {
583585
if changeSet != "" && kustomization.Status.LastAppliedRevision != revision {
584-
r.event(kustomization, revision, recorder.EventSeverityInfo, changeSet)
586+
r.event(kustomization, revision, recorder.EventSeverityInfo, changeSet, map[string]string{})
585587
}
586588
}
587589
return nil
@@ -610,7 +612,7 @@ func (r *KustomizationReconciler) prune(kustomization kustomizev1.Kustomization,
610612
strings.ToLower(kustomization.Kind),
611613
fmt.Sprintf("%s/%s", kustomization.GetNamespace(), kustomization.GetName()),
612614
).Info(fmt.Sprintf("garbage collection completed: %s", output))
613-
r.event(kustomization, snapshot.Checksum, recorder.EventSeverityInfo, output)
615+
r.event(kustomization, snapshot.Checksum, recorder.EventSeverityInfo, output, map[string]string{})
614616
}
615617
}
616618
return nil
@@ -628,7 +630,7 @@ func (r *KustomizationReconciler) checkHealth(kustomization kustomizev1.Kustomiz
628630
}
629631

630632
if kustomization.Status.LastAppliedRevision != revision {
631-
r.event(kustomization, revision, recorder.EventSeverityInfo, "Health check passed")
633+
r.event(kustomization, revision, recorder.EventSeverityInfo, "Health check passed", map[string]string{})
632634
}
633635
return nil
634636
}
@@ -686,7 +688,7 @@ func (r *KustomizationReconciler) checkDependencies(kustomization kustomizev1.Ku
686688
return nil
687689
}
688690

689-
func (r *KustomizationReconciler) event(kustomization kustomizev1.Kustomization, revision, severity, msg string) {
691+
func (r *KustomizationReconciler) event(kustomization kustomizev1.Kustomization, revision, severity, msg string, meta map[string]string) {
690692
r.EventRecorder.Event(&kustomization, "Normal", severity, msg)
691693
objRef, err := reference.GetReference(r.Scheme, &kustomization)
692694
if err != nil {
@@ -698,9 +700,8 @@ func (r *KustomizationReconciler) event(kustomization kustomizev1.Kustomization,
698700
}
699701

700702
if r.ExternalEventRecorder != nil {
701-
var meta map[string]string
702703
if revision != "" {
703-
meta = map[string]string{"revision": revision}
704+
meta["revision"] = revision
704705
}
705706

706707
reason := severity

0 commit comments

Comments
 (0)