Skip to content

Commit 45aba88

Browse files
committed
Update pkg/runtime to fix the error success log
Due to a bug in reconcile ResultFinalizer, the Ready=True condition on an ImageRepository object from the previous reconciliation wasn't getting updated even when the reconciliation failed, for example due to image scan failure. When the ResultFinalizer receives an object with stale Ready=True with message "successful scan: found x tags" from the previous successful reconciliation, Reconciling=True to indicate in-progress reconciliation and a reconciliation error, ResultFinalizer updates Ready value if it's True. But the check was performed using `conditions.IsReady()` which also takes into consideration the Reconciling and Stalled values in the status. Due to the presence of Reconciling=True, even though Ready was True, `conditions.IsReady()` returned False, and ResultFinalizer skips updating the Ready value, resulting in a fully reconciled final object status with Reconciling and Ready both True, which is an incorrect reconciliation status result. ResultFinalizer now uses `conditions.IsTrue(obj, meta.ReadyCondition)` to precisely check if only Ready=True is present. Also, remove ExternalEventRecorder from ImageRepositoryReconciler, which is no longer used and add a missing return on progressive status patching failure. Signed-off-by: Sunny <[email protected]>
1 parent 50b261c commit 45aba88

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

controllers/imagerepository_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import (
4949
"github.com/fluxcd/pkg/oci/auth/login"
5050
"github.com/fluxcd/pkg/runtime/conditions"
5151
helper "github.com/fluxcd/pkg/runtime/controller"
52-
"github.com/fluxcd/pkg/runtime/events"
5352
"github.com/fluxcd/pkg/runtime/patch"
5453
"github.com/fluxcd/pkg/runtime/predicates"
5554
"github.com/fluxcd/pkg/runtime/reconcile"
@@ -108,9 +107,8 @@ type ImageRepositoryReconciler struct {
108107
kuberecorder.EventRecorder
109108
helper.Metrics
110109

111-
ControllerName string
112-
ExternalEventRecorder *events.Recorder
113-
Database interface {
110+
ControllerName string
111+
Database interface {
114112
DatabaseWriter
115113
DatabaseReader
116114
}
@@ -286,6 +284,7 @@ func (r *ImageRepositoryReconciler) reconcile(ctx context.Context, sp *patch.Ser
286284
reconcile.ProgressiveStatus(false, obj, meta.ProgressingReason, "scanning: %s", reasonMsg)
287285
if err := sp.Patch(ctx, obj, r.patchOptions...); err != nil {
288286
result, retErr = ctrl.Result{}, err
287+
return
289288
}
290289

291290
tags, err := r.scan(ctx, obj, ref, opts)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/fluxcd/pkg/apis/event v0.4.1
1414
github.com/fluxcd/pkg/apis/meta v0.19.1
1515
github.com/fluxcd/pkg/oci v0.21.1
16-
github.com/fluxcd/pkg/runtime v0.31.0
16+
github.com/fluxcd/pkg/runtime v0.32.0
1717
github.com/fluxcd/pkg/version v0.2.1
1818
github.com/google/go-containerregistry v0.13.0
1919
github.com/google/go-containerregistry/pkg/authn/k8schain v0.0.0-20230307034325-57f010d26af8

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ github.com/fluxcd/pkg/apis/meta v0.19.1 h1:fCI5CnTXpAqr67UlaI9q0H+OztMKB5kDTr6xV
212212
github.com/fluxcd/pkg/apis/meta v0.19.1/go.mod h1:ZPPMYrPnWwPQYNEGM/Uc0N4SurUPS3xNI3IIpCQEfuM=
213213
github.com/fluxcd/pkg/oci v0.21.1 h1:9kn19wkabE2xB77NRlOtMJlSYhZmUjdloZCzlHdAS6s=
214214
github.com/fluxcd/pkg/oci v0.21.1/go.mod h1:9E2DBlQII7YmeWt2ieTh38wwkiBqx3yg5NEJ51uefaA=
215-
github.com/fluxcd/pkg/runtime v0.31.0 h1:addyXaANHl/A68bEjCbiR4HzcFKgfXv1eaG7B7ZHxOo=
216-
github.com/fluxcd/pkg/runtime v0.31.0/go.mod h1:toGOOubMo4ZC1aWhB8C3drdTglr1/A1dETeNwjiIv0g=
215+
github.com/fluxcd/pkg/runtime v0.32.0 h1:GwPyl27qs0jg95o8lGQD+FiAAxFPJMKs58L63AQRk50=
216+
github.com/fluxcd/pkg/runtime v0.32.0/go.mod h1:toGOOubMo4ZC1aWhB8C3drdTglr1/A1dETeNwjiIv0g=
217217
github.com/fluxcd/pkg/version v0.2.1 h1:RRH7+6qiWHdTvRNwpoBmilnubJ2C4FZYGgy5wTDVKVc=
218218
github.com/fluxcd/pkg/version v0.2.1/go.mod h1:UmUYHDz4BxHQMesMUx3gYVrT2Wf66H49JpTg/PW+/OY=
219219
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=

0 commit comments

Comments
 (0)