Skip to content

Commit 2441f1f

Browse files
committed
Log on new artifact and failure recovery
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
1 parent b7281de commit 2441f1f

9 files changed

+22
-14
lines changed

controllers/bucket_controller.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,13 @@ func (r *BucketReconciler) reconcile(ctx context.Context, obj *sourcev1.Bucket,
370370
res = sreconcile.LowestRequeuingResult(res, recResult)
371371
}
372372

373-
r.notify(oldObj, obj, index, res, resErr)
373+
r.notify(ctx, oldObj, obj, index, res, resErr)
374374

375375
return res, resErr
376376
}
377377

378378
// notify emits notification related to the reconciliation.
379-
func (r *BucketReconciler) notify(oldObj, newObj *sourcev1.Bucket, index *etagIndex, res sreconcile.Result, resErr error) {
379+
func (r *BucketReconciler) notify(ctx context.Context, oldObj, newObj *sourcev1.Bucket, index *etagIndex, res sreconcile.Result, resErr error) {
380380
// Notify successful reconciliation for new artifact and recovery from any
381381
// failure.
382382
if resErr == nil && res == sreconcile.ResultSuccess && newObj.Status.Artifact != nil {
@@ -396,10 +396,12 @@ func (r *BucketReconciler) notify(oldObj, newObj *sourcev1.Bucket, index *etagIn
396396
if oldChecksum != newObj.GetArtifact().Checksum {
397397
r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal,
398398
"NewArtifact", message)
399+
ctrl.LoggerFrom(ctx).Info(message)
399400
} else {
400401
if sreconcile.FailureRecovery(oldObj, newObj, bucketFailConditions) {
401402
r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal,
402403
meta.SucceededReason, message)
404+
ctrl.LoggerFrom(ctx).Info(message)
403405
}
404406
}
405407
}

controllers/bucket_controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ func TestBucketReconciler_notify(t *testing.T) {
12641264
"bbb": "ddd",
12651265
},
12661266
}
1267-
reconciler.notify(oldObj, newObj, index, tt.res, tt.resErr)
1267+
reconciler.notify(ctx, oldObj, newObj, index, tt.res, tt.resErr)
12681268

12691269
select {
12701270
case x, ok := <-recorder.Events:

controllers/gitrepository_controller.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,13 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G
286286
res = sreconcile.LowestRequeuingResult(res, recResult)
287287
}
288288

289-
r.notify(oldObj, obj, commit, res, resErr)
289+
r.notify(ctx, oldObj, obj, commit, res, resErr)
290290

291291
return res, resErr
292292
}
293293

294294
// notify emits notification related to the result of reconciliation.
295-
func (r *GitRepositoryReconciler) notify(oldObj, newObj *sourcev1.GitRepository, commit git.Commit, res sreconcile.Result, resErr error) {
295+
func (r *GitRepositoryReconciler) notify(ctx context.Context, oldObj, newObj *sourcev1.GitRepository, commit git.Commit, res sreconcile.Result, resErr error) {
296296
// Notify successful reconciliation for new artifact, no-op reconciliation
297297
// and recovery from any failure.
298298
if r.shouldNotify(oldObj, newObj, res, resErr) {
@@ -319,10 +319,12 @@ func (r *GitRepositoryReconciler) notify(oldObj, newObj *sourcev1.GitRepository,
319319
if oldChecksum != newObj.GetArtifact().Checksum {
320320
r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal,
321321
"NewArtifact", message)
322+
ctrl.LoggerFrom(ctx).Info(message)
322323
} else {
323324
if sreconcile.FailureRecovery(oldObj, newObj, gitRepositoryFailConditions) {
324325
r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal,
325326
meta.SucceededReason, message)
327+
ctrl.LoggerFrom(ctx).Info(message)
326328
}
327329
}
328330
}

controllers/gitrepository_controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ func TestGitRepositoryReconciler_notify(t *testing.T) {
19281928
EventRecorder: recorder,
19291929
features: features.FeatureGates(),
19301930
}
1931-
reconciler.notify(oldObj, newObj, tt.commit, tt.res, tt.resErr)
1931+
reconciler.notify(ctx, oldObj, newObj, tt.commit, tt.res, tt.resErr)
19321932

19331933
select {
19341934
case x, ok := <-recorder.Events:

controllers/helmchart_controller.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,13 @@ func (r *HelmChartReconciler) reconcile(ctx context.Context, obj *sourcev1.HelmC
287287
res = sreconcile.LowestRequeuingResult(res, recResult)
288288
}
289289

290-
r.notify(oldObj, obj, &build, res, resErr)
290+
r.notify(ctx, oldObj, obj, &build, res, resErr)
291291

292292
return res, resErr
293293
}
294294

295295
// notify emits notification related to the reconciliation.
296-
func (r *HelmChartReconciler) notify(oldObj, newObj *sourcev1.HelmChart, build *chart.Build, res sreconcile.Result, resErr error) {
296+
func (r *HelmChartReconciler) notify(ctx context.Context, oldObj, newObj *sourcev1.HelmChart, build *chart.Build, res sreconcile.Result, resErr error) {
297297
// Notify successful reconciliation for new artifact and recovery from any
298298
// failure.
299299
if resErr == nil && res == sreconcile.ResultSuccess && newObj.Status.Artifact != nil {
@@ -311,10 +311,12 @@ func (r *HelmChartReconciler) notify(oldObj, newObj *sourcev1.HelmChart, build *
311311
if oldChecksum != newObj.GetArtifact().Checksum {
312312
r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal,
313313
reasonForBuild(build), build.Summary())
314+
ctrl.LoggerFrom(ctx).Info(build.Summary())
314315
} else {
315316
if sreconcile.FailureRecovery(oldObj, newObj, helmChartFailConditions) {
316317
r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal,
317318
reasonForBuild(build), build.Summary())
319+
ctrl.LoggerFrom(ctx).Info(build.Summary())
318320
}
319321
}
320322
}

controllers/helmchart_controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ func TestHelmChartReconciler_notify(t *testing.T) {
19171917
Path: "some/path",
19181918
Packaged: true,
19191919
}
1920-
reconciler.notify(oldObj, newObj, build, tt.res, tt.resErr)
1920+
reconciler.notify(ctx, oldObj, newObj, build, tt.res, tt.resErr)
19211921

19221922
select {
19231923
case x, ok := <-recorder.Events:

controllers/helmrepository_controller.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.
250250
res = sreconcile.LowestRequeuingResult(res, recResult)
251251
}
252252

253-
r.notify(oldObj, obj, chartRepo, res, resErr)
253+
r.notify(ctx, oldObj, obj, chartRepo, res, resErr)
254254

255255
return res, resErr
256256
}
257257

258258
// notify emits notification related to the reconciliation.
259-
func (r *HelmRepositoryReconciler) notify(oldObj, newObj *sourcev1.HelmRepository, chartRepo repository.ChartRepository, res sreconcile.Result, resErr error) {
259+
func (r *HelmRepositoryReconciler) notify(ctx context.Context, oldObj, newObj *sourcev1.HelmRepository, chartRepo repository.ChartRepository, res sreconcile.Result, resErr error) {
260260
// Notify successful reconciliation for new artifact and recovery from any
261261
// failure.
262262
if resErr == nil && res == sreconcile.ResultSuccess && newObj.Status.Artifact != nil {
@@ -281,11 +281,13 @@ func (r *HelmRepositoryReconciler) notify(oldObj, newObj *sourcev1.HelmRepositor
281281
if oldChecksum != newObj.GetArtifact().Checksum {
282282
r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal,
283283
"NewArtifact", message)
284+
ctrl.LoggerFrom(ctx).Info(message)
284285
} else {
285286
if sreconcile.FailureRecovery(oldObj, newObj, helmRepositoryFailConditions) {
286287
r.AnnotatedEventf(newObj, annotations, corev1.EventTypeNormal,
287288
meta.SucceededReason, message)
288289
}
290+
ctrl.LoggerFrom(ctx).Info(message)
289291
}
290292
}
291293
}

controllers/helmrepository_controller_oci.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ func (r *HelmRepositoryOCIReconciler) reconcile(ctx context.Context, obj *v1beta
229229
ready := conditions.Get(obj, meta.ReadyCondition)
230230
// Became ready from not ready.
231231
if !conditions.IsReady(oldObj) && conditions.IsReady(obj) {
232-
r.Eventf(obj, corev1.EventTypeNormal, ready.Reason, ready.Message)
232+
r.eventLogf(ctx, obj, corev1.EventTypeNormal, ready.Reason, ready.Message)
233233
}
234234
// Became not ready from ready.
235235
if conditions.IsReady(oldObj) && !conditions.IsReady(obj) {
236-
r.Eventf(obj, corev1.EventTypeWarning, ready.Reason, ready.Message)
236+
r.eventLogf(ctx, obj, corev1.EventTypeWarning, ready.Reason, ready.Message)
237237
}
238238
}()
239239

controllers/helmrepository_controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ func TestHelmRepositoryReconciler_notify(t *testing.T) {
10691069
chartRepo := repository.ChartRepository{
10701070
URL: "some-address",
10711071
}
1072-
reconciler.notify(oldObj, newObj, chartRepo, tt.res, tt.resErr)
1072+
reconciler.notify(ctx, oldObj, newObj, chartRepo, tt.res, tt.resErr)
10731073

10741074
select {
10751075
case x, ok := <-recorder.Events:

0 commit comments

Comments
 (0)