Skip to content

Commit f930d37

Browse files
committed
add initial grace period before triggering a failure due to missing components
1 parent ba18866 commit f930d37

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

internal/controller/appwrapper/appwrapper_controller.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,22 +267,27 @@ func (r *AppWrapperReconciler) Reconcile(ctx context.Context, req ctrl.Request)
267267
return ctrl.Result{}, err
268268
}
269269

270-
// Detect externally deleted components and transition to Failed with no GracePeriod or retry
271-
detailMsg := fmt.Sprintf("Only found %v deployed components, but was expecting %v", compStatus.deployed, compStatus.expected)
270+
// Detect externally deleted components
272271
if compStatus.deployed != compStatus.expected {
273-
meta.SetStatusCondition(&aw.Status.Conditions, metav1.Condition{
274-
Type: string(workloadv1beta2.Unhealthy),
275-
Status: metav1.ConditionTrue,
276-
Reason: "MissingComponent",
277-
Message: detailMsg,
278-
})
279-
r.Recorder.Event(aw, v1.EventTypeNormal, string(workloadv1beta2.Unhealthy), "MissingComponent: "+detailMsg)
280-
return ctrl.Result{}, r.transitionToPhase(ctx, orig, aw, workloadv1beta2.AppWrapperFailed)
272+
// There may be a lag before created resources become visible in the cache; don't react too quickly.
273+
whenDeployed := meta.FindStatusCondition(aw.Status.Conditions, string(workloadv1beta2.ResourcesDeployed)).LastTransitionTime
274+
graceDuration := r.admissionGraceDuration(ctx, aw)
275+
if time.Now().After(whenDeployed.Add(graceDuration)) {
276+
detailMsg := fmt.Sprintf("Only found %v deployed components, but was expecting %v", compStatus.deployed, compStatus.expected)
277+
meta.SetStatusCondition(&aw.Status.Conditions, metav1.Condition{
278+
Type: string(workloadv1beta2.Unhealthy),
279+
Status: metav1.ConditionTrue,
280+
Reason: "MissingComponent",
281+
Message: detailMsg,
282+
})
283+
r.Recorder.Event(aw, v1.EventTypeNormal, string(workloadv1beta2.Unhealthy), "MissingComponent: "+detailMsg)
284+
return ctrl.Result{}, r.transitionToPhase(ctx, orig, aw, workloadv1beta2.AppWrapperFailed)
285+
}
281286
}
282287

283288
// If a component's controller has put it into a failed state, we do not need
284289
// to allow a grace period. The situation will not self-correct.
285-
detailMsg = fmt.Sprintf("Found %v failed components", compStatus.failed)
290+
detailMsg := fmt.Sprintf("Found %v failed components", compStatus.failed)
286291
if compStatus.failed > 0 {
287292
meta.SetStatusCondition(&aw.Status.Conditions, metav1.Condition{
288293
Type: string(workloadv1beta2.Unhealthy),

0 commit comments

Comments
 (0)