Skip to content

Commit c28550b

Browse files
committed
Add ProgressingWithRetry reason to Reconciling condition
ProgressingWithRetry signals that the controller is going to retry the last failed reconciliation at a later time. Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
1 parent 933a8db commit c28550b

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

api/v1beta2/condition_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ const (
4848
// ReconciliationFailedReason represents the fact that
4949
// the reconciliation failed.
5050
ReconciliationFailedReason string = "ReconciliationFailed"
51+
52+
// ProgressingWithRetryReason represents the fact that
53+
// the reconciliation encountered an error that will be retried.
54+
ProgressingWithRetryReason string = "ProgressingWithRetry"
5155
)

controllers/kustomization_controller.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
182182
obj.Status.ObservedGeneration = obj.Generation
183183
}
184184

185+
// Set the Reconciling reason to ProgressingWithRetry if the
186+
// reconciliation has failed.
187+
if conditions.IsFalse(obj, meta.ReadyCondition) &&
188+
conditions.Has(obj, meta.ReconcilingCondition) {
189+
rc := conditions.Get(obj, meta.ReconcilingCondition)
190+
rc.Reason = kustomizev1.ProgressingWithRetryReason
191+
conditions.Set(obj, rc)
192+
}
193+
185194
// Patch metadata, status and conditions.
186195
retErr = r.patch(ctx, obj, patcher)
187196

@@ -221,7 +230,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
221230

222231
// Set reconciling condition.
223232
if obj.Generation != obj.Status.ObservedGeneration {
224-
conditions.MarkReconciling(obj, "NewGeneration", "Reconciling new object generation (%d)", obj.Generation)
233+
conditions.MarkReconciling(obj, meta.ProgressingReason, "Reconciling new object generation (%d)", obj.Generation)
225234
}
226235

227236
// Resolve the source reference and requeue the reconciliation if the source is not found.
@@ -465,7 +474,7 @@ func (r *KustomizationReconciler) checkDependencies(ctx context.Context,
465474
var k kustomizev1.Kustomization
466475
err := r.Get(ctx, dName, &k)
467476
if err != nil {
468-
return fmt.Errorf("unable to get '%s' dependency: %w", dName, err)
477+
return fmt.Errorf("dependency '%s' not found: %w", dName, err)
469478
}
470479

471480
if len(k.Status.Conditions) == 0 || k.Generation != k.Status.ObservedGeneration {
@@ -480,7 +489,7 @@ func (r *KustomizationReconciler) checkDependencies(ctx context.Context,
480489
k.Spec.SourceRef.Namespace == obj.Spec.SourceRef.Namespace &&
481490
k.Spec.SourceRef.Kind == obj.Spec.SourceRef.Kind &&
482491
source.GetArtifact().Revision != k.Status.LastAppliedRevision {
483-
return fmt.Errorf("dependency '%s' is not updated yet", dName)
492+
return fmt.Errorf("dependency '%s' revision is not up to date", dName)
484493
}
485494
}
486495

controllers/kustomization_wait_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ parameters:
154154

155155
g.Eventually(func() bool {
156156
_ = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(kustomization), resultK)
157-
return conditions.IsReconciling(resultK)
157+
return isReconcileRunning(resultK)
158158
}, timeout, time.Second).Should(BeTrue())
159159
logStatus(t, resultK)
160160

@@ -183,7 +183,7 @@ parameters:
183183
}
184184

185185
expectedMessage := "Running health checks"
186-
g.Expect(conditions.GetReason(resultK, meta.ReconcilingCondition)).To(BeIdenticalTo(meta.ProgressingReason))
186+
g.Expect(conditions.GetReason(resultK, meta.ReconcilingCondition)).To(BeIdenticalTo(kustomizev1.ProgressingWithRetryReason))
187187
g.Expect(conditions.GetMessage(resultK, meta.ReconcilingCondition)).To(ContainSubstring(expectedMessage))
188188

189189
g.Expect(resultK.Status.LastHandledReconcileAt).To(BeIdenticalTo(reconcileRequestAt))

controllers/suite_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ func randStringRunes(n int) string {
196196
return string(b)
197197
}
198198

199+
func isReconcileRunning(k *kustomizev1.Kustomization) bool {
200+
return conditions.IsReconciling(k) &&
201+
conditions.GetReason(k, meta.ReconcilingCondition) != kustomizev1.ProgressingWithRetryReason
202+
}
203+
199204
func isReconcileSuccess(k *kustomizev1.Kustomization) bool {
200205
return conditions.IsReady(k) &&
201206
conditions.GetObservedGeneration(k, meta.ReadyCondition) == k.Generation &&
@@ -204,14 +209,19 @@ func isReconcileSuccess(k *kustomizev1.Kustomization) bool {
204209
}
205210

206211
func isReconcileFailure(k *kustomizev1.Kustomization) bool {
212+
if conditions.IsStalled(k) {
213+
return true
214+
}
215+
207216
isHandled := true
208217
if v, ok := meta.ReconcileAnnotationValue(k.GetAnnotations()); ok {
209218
isHandled = k.Status.LastHandledReconcileAt == v
210219
}
211220

212221
return isHandled && conditions.IsReconciling(k) &&
213222
conditions.IsFalse(k, meta.ReadyCondition) &&
214-
conditions.GetObservedGeneration(k, meta.ReadyCondition) == k.Generation
223+
conditions.GetObservedGeneration(k, meta.ReadyCondition) == k.Generation &&
224+
conditions.GetReason(k, meta.ReconcilingCondition) == kustomizev1.ProgressingWithRetryReason
215225
}
216226

217227
func logStatus(t *testing.T, k *kustomizev1.Kustomization) {

0 commit comments

Comments
 (0)