From 2441f1f0e951f8a06f6c45e94ca4b4d3a6b02345 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Fri, 3 Jun 2022 15:37:00 +0300 Subject: [PATCH] Log on new artifact and failure recovery Signed-off-by: Stefan Prodan --- controllers/bucket_controller.go | 6 ++++-- controllers/bucket_controller_test.go | 2 +- controllers/gitrepository_controller.go | 6 ++++-- controllers/gitrepository_controller_test.go | 2 +- controllers/helmchart_controller.go | 6 ++++-- controllers/helmchart_controller_test.go | 2 +- controllers/helmrepository_controller.go | 6 ++++-- controllers/helmrepository_controller_oci.go | 4 ++-- controllers/helmrepository_controller_test.go | 2 +- 9 files changed, 22 insertions(+), 14 deletions(-) diff --git a/controllers/bucket_controller.go b/controllers/bucket_controller.go index 5cfc9fe5..af5de296 100644 --- a/controllers/bucket_controller.go +++ b/controllers/bucket_controller.go @@ -370,13 +370,13 @@ func (r *BucketReconciler) reconcile(ctx context.Context, obj *sourcev1.Bucket, res = sreconcile.LowestRequeuingResult(res, recResult) } - r.notify(oldObj, obj, index, res, resErr) + r.notify(ctx, oldObj, obj, index, res, resErr) return res, resErr } // notify emits notification related to the reconciliation. -func (r *BucketReconciler) notify(oldObj, newObj *sourcev1.Bucket, index *etagIndex, res sreconcile.Result, resErr error) { +func (r *BucketReconciler) notify(ctx context.Context, oldObj, newObj *sourcev1.Bucket, index *etagIndex, res sreconcile.Result, resErr error) { // Notify successful reconciliation for new artifact and recovery from any // failure. if resErr == nil && res == sreconcile.ResultSuccess && newObj.Status.Artifact != nil { @@ -396,10 +396,12 @@ func (r *BucketReconciler) notify(oldObj, newObj *sourcev1.Bucket, index *etagIn if oldChecksum != newObj.GetArtifact().Checksum { r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal, "NewArtifact", message) + ctrl.LoggerFrom(ctx).Info(message) } else { if sreconcile.FailureRecovery(oldObj, newObj, bucketFailConditions) { r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal, meta.SucceededReason, message) + ctrl.LoggerFrom(ctx).Info(message) } } } diff --git a/controllers/bucket_controller_test.go b/controllers/bucket_controller_test.go index 0337df48..37cc33d9 100644 --- a/controllers/bucket_controller_test.go +++ b/controllers/bucket_controller_test.go @@ -1264,7 +1264,7 @@ func TestBucketReconciler_notify(t *testing.T) { "bbb": "ddd", }, } - reconciler.notify(oldObj, newObj, index, tt.res, tt.resErr) + reconciler.notify(ctx, oldObj, newObj, index, tt.res, tt.resErr) select { case x, ok := <-recorder.Events: diff --git a/controllers/gitrepository_controller.go b/controllers/gitrepository_controller.go index 531983b2..912b2898 100644 --- a/controllers/gitrepository_controller.go +++ b/controllers/gitrepository_controller.go @@ -286,13 +286,13 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G res = sreconcile.LowestRequeuingResult(res, recResult) } - r.notify(oldObj, obj, commit, res, resErr) + r.notify(ctx, oldObj, obj, commit, res, resErr) return res, resErr } // notify emits notification related to the result of reconciliation. -func (r *GitRepositoryReconciler) notify(oldObj, newObj *sourcev1.GitRepository, commit git.Commit, res sreconcile.Result, resErr error) { +func (r *GitRepositoryReconciler) notify(ctx context.Context, oldObj, newObj *sourcev1.GitRepository, commit git.Commit, res sreconcile.Result, resErr error) { // Notify successful reconciliation for new artifact, no-op reconciliation // and recovery from any failure. if r.shouldNotify(oldObj, newObj, res, resErr) { @@ -319,10 +319,12 @@ func (r *GitRepositoryReconciler) notify(oldObj, newObj *sourcev1.GitRepository, if oldChecksum != newObj.GetArtifact().Checksum { r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal, "NewArtifact", message) + ctrl.LoggerFrom(ctx).Info(message) } else { if sreconcile.FailureRecovery(oldObj, newObj, gitRepositoryFailConditions) { r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal, meta.SucceededReason, message) + ctrl.LoggerFrom(ctx).Info(message) } } } diff --git a/controllers/gitrepository_controller_test.go b/controllers/gitrepository_controller_test.go index 50a9463f..c02e1320 100644 --- a/controllers/gitrepository_controller_test.go +++ b/controllers/gitrepository_controller_test.go @@ -1928,7 +1928,7 @@ func TestGitRepositoryReconciler_notify(t *testing.T) { EventRecorder: recorder, features: features.FeatureGates(), } - reconciler.notify(oldObj, newObj, tt.commit, tt.res, tt.resErr) + reconciler.notify(ctx, oldObj, newObj, tt.commit, tt.res, tt.resErr) select { case x, ok := <-recorder.Events: diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index 21c96102..50000d47 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -287,13 +287,13 @@ func (r *HelmChartReconciler) reconcile(ctx context.Context, obj *sourcev1.HelmC res = sreconcile.LowestRequeuingResult(res, recResult) } - r.notify(oldObj, obj, &build, res, resErr) + r.notify(ctx, oldObj, obj, &build, res, resErr) return res, resErr } // notify emits notification related to the reconciliation. -func (r *HelmChartReconciler) notify(oldObj, newObj *sourcev1.HelmChart, build *chart.Build, res sreconcile.Result, resErr error) { +func (r *HelmChartReconciler) notify(ctx context.Context, oldObj, newObj *sourcev1.HelmChart, build *chart.Build, res sreconcile.Result, resErr error) { // Notify successful reconciliation for new artifact and recovery from any // failure. if resErr == nil && res == sreconcile.ResultSuccess && newObj.Status.Artifact != nil { @@ -311,10 +311,12 @@ func (r *HelmChartReconciler) notify(oldObj, newObj *sourcev1.HelmChart, build * if oldChecksum != newObj.GetArtifact().Checksum { r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal, reasonForBuild(build), build.Summary()) + ctrl.LoggerFrom(ctx).Info(build.Summary()) } else { if sreconcile.FailureRecovery(oldObj, newObj, helmChartFailConditions) { r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal, reasonForBuild(build), build.Summary()) + ctrl.LoggerFrom(ctx).Info(build.Summary()) } } } diff --git a/controllers/helmchart_controller_test.go b/controllers/helmchart_controller_test.go index dfd33437..262627da 100644 --- a/controllers/helmchart_controller_test.go +++ b/controllers/helmchart_controller_test.go @@ -1917,7 +1917,7 @@ func TestHelmChartReconciler_notify(t *testing.T) { Path: "some/path", Packaged: true, } - reconciler.notify(oldObj, newObj, build, tt.res, tt.resErr) + reconciler.notify(ctx, oldObj, newObj, build, tt.res, tt.resErr) select { case x, ok := <-recorder.Events: diff --git a/controllers/helmrepository_controller.go b/controllers/helmrepository_controller.go index a7a6ac72..6254ca6c 100644 --- a/controllers/helmrepository_controller.go +++ b/controllers/helmrepository_controller.go @@ -250,13 +250,13 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1. res = sreconcile.LowestRequeuingResult(res, recResult) } - r.notify(oldObj, obj, chartRepo, res, resErr) + r.notify(ctx, oldObj, obj, chartRepo, res, resErr) return res, resErr } // notify emits notification related to the reconciliation. -func (r *HelmRepositoryReconciler) notify(oldObj, newObj *sourcev1.HelmRepository, chartRepo repository.ChartRepository, res sreconcile.Result, resErr error) { +func (r *HelmRepositoryReconciler) notify(ctx context.Context, oldObj, newObj *sourcev1.HelmRepository, chartRepo repository.ChartRepository, res sreconcile.Result, resErr error) { // Notify successful reconciliation for new artifact and recovery from any // failure. if resErr == nil && res == sreconcile.ResultSuccess && newObj.Status.Artifact != nil { @@ -281,11 +281,13 @@ func (r *HelmRepositoryReconciler) notify(oldObj, newObj *sourcev1.HelmRepositor if oldChecksum != newObj.GetArtifact().Checksum { r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal, "NewArtifact", message) + ctrl.LoggerFrom(ctx).Info(message) } else { if sreconcile.FailureRecovery(oldObj, newObj, helmRepositoryFailConditions) { r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal, meta.SucceededReason, message) } + ctrl.LoggerFrom(ctx).Info(message) } } } diff --git a/controllers/helmrepository_controller_oci.go b/controllers/helmrepository_controller_oci.go index 7f46c958..6053cf8c 100644 --- a/controllers/helmrepository_controller_oci.go +++ b/controllers/helmrepository_controller_oci.go @@ -229,11 +229,11 @@ func (r *HelmRepositoryOCIReconciler) reconcile(ctx context.Context, obj *v1beta ready := conditions.Get(obj, meta.ReadyCondition) // Became ready from not ready. if !conditions.IsReady(oldObj) && conditions.IsReady(obj) { - r.Eventf(obj, corev1.EventTypeNormal, ready.Reason, ready.Message) + r.eventLogf(ctx, obj, corev1.EventTypeNormal, ready.Reason, ready.Message) } // Became not ready from ready. if conditions.IsReady(oldObj) && !conditions.IsReady(obj) { - r.Eventf(obj, corev1.EventTypeWarning, ready.Reason, ready.Message) + r.eventLogf(ctx, obj, corev1.EventTypeWarning, ready.Reason, ready.Message) } }() diff --git a/controllers/helmrepository_controller_test.go b/controllers/helmrepository_controller_test.go index c8c188d6..3ca34d6e 100644 --- a/controllers/helmrepository_controller_test.go +++ b/controllers/helmrepository_controller_test.go @@ -1069,7 +1069,7 @@ func TestHelmRepositoryReconciler_notify(t *testing.T) { chartRepo := repository.ChartRepository{ URL: "some-address", } - reconciler.notify(oldObj, newObj, chartRepo, tt.res, tt.resErr) + reconciler.notify(ctx, oldObj, newObj, chartRepo, tt.res, tt.resErr) select { case x, ok := <-recorder.Events: