@@ -24,6 +24,7 @@ import (
24
24
"os"
25
25
"time"
26
26
27
+ "github.com/google/go-containerregistry/pkg/authn"
27
28
helmgetter "helm.sh/helm/v3/pkg/getter"
28
29
helmreg "helm.sh/helm/v3/pkg/registry"
29
30
corev1 "k8s.io/api/core/v1"
@@ -45,7 +46,7 @@ import (
45
46
helper "github.com/fluxcd/pkg/runtime/controller"
46
47
"github.com/fluxcd/pkg/runtime/patch"
47
48
"github.com/fluxcd/pkg/runtime/predicates"
48
- "github.com/google/go-containerregistry/ pkg/authn "
49
+ rreconcile "github.com/fluxcd/ pkg/runtime/reconcile "
49
50
50
51
"github.com/fluxcd/source-controller/api/v1beta2"
51
52
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
@@ -79,6 +80,8 @@ type HelmRepositoryOCIReconciler struct {
79
80
Getters helmgetter.Providers
80
81
ControllerName string
81
82
RegistryClientGenerator RegistryClientGeneratorFunc
83
+
84
+ patchOptions []patch.Option
82
85
}
83
86
84
87
// RegistryClientGeneratorFunc is a function that returns a registry client
@@ -92,6 +95,8 @@ func (r *HelmRepositoryOCIReconciler) SetupWithManager(mgr ctrl.Manager) error {
92
95
}
93
96
94
97
func (r * HelmRepositoryOCIReconciler ) SetupWithManagerAndOptions (mgr ctrl.Manager , opts HelmRepositoryReconcilerOptions ) error {
98
+ r .patchOptions = getPatchOptions (helmRepositoryOCIOwnedConditions , r .ControllerName )
99
+
95
100
return ctrl .NewControllerManagedBy (mgr ).
96
101
For (& sourcev1.HelmRepository {}).
97
102
WithEventFilter (
@@ -122,34 +127,26 @@ func (r *HelmRepositoryOCIReconciler) Reconcile(ctx context.Context, req ctrl.Re
122
127
r .RecordSuspend (ctx , obj , obj .Spec .Suspend )
123
128
124
129
// Initialize the patch helper with the current version of the object.
125
- patchHelper , err := patch .NewHelper (obj , r .Client )
126
- if err != nil {
127
- return ctrl.Result {}, err
128
- }
130
+ serialPatcher := patch .NewSerialPatcher (obj , r .Client )
129
131
130
132
// Always attempt to patch the object after each reconciliation.
131
133
defer func () {
132
- // Patch the object, prioritizing the conditions owned by the controller in
133
- // case of any conflicts.
134
- patchOpts := []patch.Option {
135
- patch.WithOwnedConditions {
136
- Conditions : helmRepositoryOCIOwnedConditions ,
137
- },
138
- }
139
- patchOpts = append (patchOpts , patch .WithFieldOwner (r .ControllerName ))
140
134
// If a reconcile annotation value is found, set it in the object status
141
135
// as status.lastHandledReconcileAt.
142
136
if v , ok := meta .ReconcileAnnotationValue (obj .GetAnnotations ()); ok {
143
137
object .SetStatusLastHandledReconcileAt (obj , v )
144
138
}
145
139
140
+ patchOpts := []patch.Option {}
141
+ patchOpts = append (patchOpts , r .patchOptions ... )
142
+
146
143
// Set status observed generation option if the object is stalled, or
147
144
// if the object is ready.
148
145
if conditions .IsStalled (obj ) || conditions .IsReady (obj ) {
149
146
patchOpts = append (patchOpts , patch.WithStatusObservedGeneration {})
150
147
}
151
148
152
- if err = patchHelper .Patch (ctx , obj , patchOpts ... ); err != nil {
149
+ if err := serialPatcher .Patch (ctx , obj , patchOpts ... ); err != nil {
153
150
// Ignore patch error "not found" when the object is being deleted.
154
151
if ! obj .GetDeletionTimestamp ().IsZero () {
155
152
err = kerrors .FilterOut (err , func (e error ) bool { return apierrors .IsNotFound (e ) })
@@ -188,7 +185,7 @@ func (r *HelmRepositoryOCIReconciler) Reconcile(ctx context.Context, req ctrl.Re
188
185
return ctrl.Result {}, nil
189
186
}
190
187
191
- result , retErr = r .reconcile (ctx , obj )
188
+ result , retErr = r .reconcile (ctx , serialPatcher , obj )
192
189
return
193
190
}
194
191
@@ -198,7 +195,7 @@ func (r *HelmRepositoryOCIReconciler) Reconcile(ctx context.Context, req ctrl.Re
198
195
// status conditions and the returned results are evaluated in the deferred
199
196
// block at the very end to summarize the conditions to be in a consistent
200
197
// state.
201
- func (r * HelmRepositoryOCIReconciler ) reconcile (ctx context.Context , obj * v1beta2.HelmRepository ) (result ctrl.Result , retErr error ) {
198
+ func (r * HelmRepositoryOCIReconciler ) reconcile (ctx context.Context , sp * patch. SerialPatcher , obj * v1beta2.HelmRepository ) (result ctrl.Result , retErr error ) {
202
199
ctxTimeout , cancel := context .WithTimeout (ctx , obj .Spec .Timeout .Duration )
203
200
defer cancel ()
204
201
@@ -224,6 +221,15 @@ func (r *HelmRepositoryOCIReconciler) reconcile(ctx context.Context, obj *v1beta
224
221
}
225
222
}
226
223
224
+ // Presence of reconciling means that the reconciliation didn't succeed.
225
+ // Set the Reconciling reason to ProgressingWithRetry to indicate a
226
+ // failure retry.
227
+ if conditions .IsReconciling (obj ) {
228
+ reconciling := conditions .Get (obj , meta .ReconcilingCondition )
229
+ reconciling .Reason = meta .ProgressingWithRetryReason
230
+ conditions .Set (obj , reconciling )
231
+ }
232
+
227
233
// If it's still a successful reconciliation and it's not reconciling or
228
234
// stalled, mark Ready=True.
229
235
if ! conditions .IsReconciling (obj ) && ! conditions .IsStalled (obj ) &&
@@ -244,8 +250,26 @@ func (r *HelmRepositoryOCIReconciler) reconcile(ctx context.Context, obj *v1beta
244
250
}()
245
251
246
252
// Set reconciling condition.
247
- if obj .Generation != obj .Status .ObservedGeneration {
248
- conditions .MarkReconciling (obj , "NewGeneration" , "reconciling new object generation (%d)" , obj .Generation )
253
+ rreconcile .ProgressiveStatus (false , obj , meta .ProgressingReason , "reconciliation in progress" )
254
+
255
+ var reconcileAtVal string
256
+ if v , ok := meta .ReconcileAnnotationValue (obj .GetAnnotations ()); ok {
257
+ reconcileAtVal = v
258
+ }
259
+
260
+ // Persist reconciling if generation differs or reconciliation is requested.
261
+ switch {
262
+ case obj .Generation != obj .Status .ObservedGeneration :
263
+ rreconcile .ProgressiveStatus (false , obj , meta .ProgressingReason , "processing object: new generation (%d)" , obj .Generation )
264
+ if err := sp .Patch (ctx , obj , r .patchOptions ... ); err != nil {
265
+ result , retErr = ctrl.Result {}, err
266
+ return
267
+ }
268
+ case reconcileAtVal != obj .Status .GetLastHandledReconcileRequest ():
269
+ if err := sp .Patch (ctx , obj , r .patchOptions ... ); err != nil {
270
+ result , retErr = ctrl.Result {}, err
271
+ return
272
+ }
249
273
}
250
274
251
275
// Ensure that it's an OCI URL before continuing.
0 commit comments