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

Log on new artifact and failure recovery #759

Merged
merged 1 commit into from
Jun 3, 2022
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: 4 additions & 2 deletions controllers/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/bucket_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions controllers/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/gitrepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions controllers/helmchart_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/helmchart_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions controllers/helmrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/helmrepository_controller_oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()

Expand Down
2 changes: 1 addition & 1 deletion controllers/helmrepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down