Skip to content

Commit e253e4c

Browse files
committed
reconcile: Add support for progressive status
Replace the patch Helper with SerialPatcher which is used for progressive status patching. Update the tests to use progressive status reasons in tests. Add ProgressingWithRetry Reconciling reason for failed reconciliation result to indicate a finished failure operation. Signed-off-by: Sunny <[email protected]>
1 parent b044c6b commit e253e4c

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

internal/reconcile/reconcile.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ func ComputeReconcileResult(obj conditions.Setter, res Result, recErr error, rb
124124
conditions.Delete(obj, meta.ReconcilingCondition)
125125
}
126126

127+
// Presence of reconciling means that the reconciliation didn't succeed.
128+
// Set the Reconciling reason to ProgressingWithRetry to indicate a failure
129+
// retry.
130+
if conditions.IsReconciling(obj) {
131+
reconciling := conditions.Get(obj, meta.ReconcilingCondition)
132+
reconciling.Reason = meta.ProgressingWithRetryReason
133+
conditions.Set(obj, reconciling)
134+
}
135+
127136
// Analyze the reconcile error.
128137
switch t := recErr.(type) {
129138
case *serror.Stalling:

internal/reconcile/reconcile_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,21 @@ func TestComputeReconcileResult(t *testing.T) {
206206
t.Expect(conditions.IsUnknown(obj, meta.StalledCondition)).To(BeTrue())
207207
},
208208
},
209+
{
210+
name: "failed with Reconciling=True adds ProgressingWithRetry reason",
211+
beforeFunc: func(obj conditions.Setter) {
212+
conditions.MarkReconciling(obj, meta.ProgressingReason, "some msg")
213+
},
214+
result: ResultEmpty,
215+
recErr: fmt.Errorf("some error"),
216+
wantResult: ctrl.Result{},
217+
wantErr: true,
218+
afterFunc: func(t *WithT, obj conditions.Setter, patchOpts *patch.HelperOptions) {
219+
},
220+
assertConditions: []metav1.Condition{
221+
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingWithRetryReason, "some msg"),
222+
},
223+
},
209224
}
210225

211226
for _, tt := range tests {

internal/reconcile/summarize/summary.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ type Conditions struct {
5050

5151
// Helper is SummarizeAndPatch helper.
5252
type Helper struct {
53-
recorder kuberecorder.EventRecorder
54-
patchHelper *patch.Helper
53+
recorder kuberecorder.EventRecorder
54+
serialPatcher *patch.SerialPatcher
5555
}
5656

5757
// NewHelper returns an initialized Helper.
58-
func NewHelper(recorder kuberecorder.EventRecorder, patchHelper *patch.Helper) *Helper {
58+
func NewHelper(recorder kuberecorder.EventRecorder, serialPatcher *patch.SerialPatcher) *Helper {
5959
return &Helper{
60-
recorder: recorder,
61-
patchHelper: patchHelper,
60+
recorder: recorder,
61+
serialPatcher: serialPatcher,
6262
}
6363
}
6464

@@ -250,7 +250,7 @@ func (h *Helper) SummarizeAndPatch(ctx context.Context, obj conditions.Setter, o
250250
}
251251

252252
// Finally, patch the resource.
253-
if err := h.patchHelper.Patch(ctx, obj, patchOpts...); err != nil {
253+
if err := h.serialPatcher.Patch(ctx, obj, patchOpts...); err != nil {
254254
// Ignore patch error "not found" when the object is being deleted.
255255
if opts.IgnoreNotFound && !obj.GetDeletionTimestamp().IsZero() {
256256
err = kerrors.FilterOut(err, func(e error) bool { return apierrors.IsNotFound(e) })

internal/reconcile/summarize/summary_test.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func TestSummarizeAndPatch(t *testing.T) {
128128
name: "Success, removes reconciling for successful result",
129129
generation: 2,
130130
beforeFunc: func(obj conditions.Setter) {
131-
conditions.MarkReconciling(obj, "NewRevision", "new index version")
131+
conditions.MarkReconciling(obj, meta.ProgressingReason, "new index version")
132132
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason, "stored artifact")
133133
},
134134
conditions: []Conditions{testReadyConditions},
@@ -167,15 +167,15 @@ func TestSummarizeAndPatch(t *testing.T) {
167167
generation: 7,
168168
beforeFunc: func(obj conditions.Setter) {
169169
conditions.MarkTrue(obj, sourcev1.ArtifactOutdatedCondition, "NewRevision", "new index revision")
170-
conditions.MarkReconciling(obj, "NewRevision", "new index revision")
170+
conditions.MarkReconciling(obj, meta.ProgressingReason, "new index revision")
171171
},
172172
conditions: []Conditions{testReadyConditions},
173173
reconcileErr: fmt.Errorf("failed to create dir"),
174174
wantErr: true,
175175
assertConditions: []metav1.Condition{
176176
*conditions.FalseCondition(meta.ReadyCondition, "NewRevision", "new index revision"),
177177
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new index revision"),
178-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new index revision"),
178+
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingWithRetryReason, "new index revision"),
179179
},
180180
afterFunc: func(t *WithT, obj client.Object) {
181181
t.Expect(obj).ToNot(HaveStatusObservedGeneration(7))
@@ -264,7 +264,7 @@ func TestSummarizeAndPatch(t *testing.T) {
264264
name: "Fail, reconciling with bipolar condition False, Ready gets bipolar failure value",
265265
generation: 2,
266266
beforeFunc: func(obj conditions.Setter) {
267-
conditions.MarkReconciling(obj, "NewRevision", "new index revision")
267+
conditions.MarkReconciling(obj, meta.ProgressingReason, "new index revision")
268268
conditions.MarkFalse(obj, sourcev1.SourceVerifiedCondition, "VerifyFailed", "verify failed")
269269
},
270270
result: reconcile.ResultEmpty,
@@ -275,14 +275,14 @@ func TestSummarizeAndPatch(t *testing.T) {
275275
assertConditions: []metav1.Condition{
276276
*conditions.FalseCondition(meta.ReadyCondition, "VerifyFailed", "verify failed"),
277277
*conditions.FalseCondition(sourcev1.SourceVerifiedCondition, "VerifyFailed", "verify failed"),
278-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewRevision", "new index revision"),
278+
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingWithRetryReason, "new index revision"),
279279
},
280280
},
281281
{
282282
name: "Fail, bipolar condition True, negative polarity True, Ready gets negative polarity value",
283283
generation: 2,
284284
beforeFunc: func(obj conditions.Setter) {
285-
conditions.MarkReconciling(obj, "NewGeneration", "new obj gen")
285+
conditions.MarkReconciling(obj, meta.ProgressingReason, "new obj gen")
286286
conditions.MarkTrue(obj, sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest")
287287
conditions.MarkTrue(obj, sourcev1.SourceVerifiedCondition, "Success", "verified")
288288
},
@@ -294,7 +294,7 @@ func TestSummarizeAndPatch(t *testing.T) {
294294
assertConditions: []metav1.Condition{
295295
*conditions.FalseCondition(meta.ReadyCondition, "NewRevision", "new digest"),
296296
*conditions.TrueCondition(sourcev1.ArtifactOutdatedCondition, "NewRevision", "new digest"),
297-
*conditions.TrueCondition(meta.ReconcilingCondition, "NewGeneration", "new obj gen"),
297+
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingWithRetryReason, "new obj gen"),
298298
*conditions.TrueCondition(sourcev1.SourceVerifiedCondition, "Success", "verified"),
299299
},
300300
},
@@ -345,10 +345,9 @@ func TestSummarizeAndPatch(t *testing.T) {
345345

346346
ctx := context.TODO()
347347
g.Expect(client.Create(ctx, obj)).To(Succeed())
348-
patchHelper, err := patch.NewHelper(obj, client)
349-
g.Expect(err).ToNot(HaveOccurred())
348+
serialPatcher := patch.NewSerialPatcher(obj, client)
350349

351-
summaryHelper := NewHelper(record.NewFakeRecorder(32), patchHelper)
350+
summaryHelper := NewHelper(record.NewFakeRecorder(32), serialPatcher)
352351
summaryOpts := []Option{
353352
WithReconcileResult(tt.result),
354353
WithReconcileError(tt.reconcileErr),
@@ -471,15 +470,14 @@ func TestSummarizeAndPatch_Intermediate(t *testing.T) {
471470

472471
ctx := context.TODO()
473472
g.Expect(kclient.Create(ctx, obj)).To(Succeed())
474-
patchHelper, err := patch.NewHelper(obj, kclient)
475-
g.Expect(err).ToNot(HaveOccurred())
473+
serialPatcher := patch.NewSerialPatcher(obj, kclient)
476474

477-
summaryHelper := NewHelper(record.NewFakeRecorder(32), patchHelper)
475+
summaryHelper := NewHelper(record.NewFakeRecorder(32), serialPatcher)
478476
summaryOpts := []Option{
479477
WithConditions(tt.conditions...),
480478
WithResultBuilder(reconcile.AlwaysRequeueResultBuilder{RequeueAfter: interval}),
481479
}
482-
_, err = summaryHelper.SummarizeAndPatch(ctx, obj, summaryOpts...)
480+
_, err := summaryHelper.SummarizeAndPatch(ctx, obj, summaryOpts...)
483481
g.Expect(err).ToNot(HaveOccurred())
484482

485483
g.Expect(obj.Status.Conditions).To(conditions.MatchConditions(tt.assertConditions))

0 commit comments

Comments
 (0)