Skip to content

Commit 8af844e

Browse files
committed
Address PR review feedback for workload condition detection
- Add "after successful rollout" to flapping Ready condition test names - Add a young pod to the stably ready test case - Always call PodContainersStatus when reporting UnavailablePod
1 parent e1a9fe8 commit 8af844e

2 files changed

Lines changed: 24 additions & 14 deletions

File tree

pkg/operator/apiserver/controller/workload/workload.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,13 @@ func (c *Controller) updateOperatorStatus(ctx context.Context, previousStatus *o
346346
errs = append(errs, err)
347347
}
348348
if hasFailing || workload.Status.AvailableReplicas == 0 {
349+
containerMessages, err := deployment.PodContainersStatus(workload, c.podsLister)
350+
if err != nil {
351+
errs = append(errs, err)
352+
}
349353
var failureDescription string
350-
// Only fetch container details when pods actually exist and are failing.
351-
// When entering via AvailableReplicas==0 alone, no pods exist to inspect.
352-
if hasFailing {
353-
containerMessages, err := deployment.PodContainersStatus(workload, c.podsLister)
354-
if err != nil {
355-
errs = append(errs, err)
356-
}
357-
if len(containerMessages) > 0 {
358-
failureDescription = ` (` + strings.Join(containerMessages, ", ") + `)`
359-
}
354+
if len(containerMessages) > 0 {
355+
failureDescription = ` (` + strings.Join(containerMessages, ", ") + `)`
360356
}
361357

362358
numUnavailable := desiredReplicas - workload.Status.AvailableReplicas

pkg/operator/apiserver/controller/workload/workload_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,11 @@ func TestUpdateOperatorStatus(t *testing.T) {
707707
},
708708
Spec: appsv1.DeploymentSpec{
709709
Replicas: ptr.To[int32](3),
710+
Template: corev1.PodTemplateSpec{
711+
ObjectMeta: metav1.ObjectMeta{
712+
Labels: map[string]string{"app": "apiserver"},
713+
},
714+
},
710715
},
711716
Status: appsv1.DeploymentStatus{
712717
AvailableReplicas: 0,
@@ -734,7 +739,7 @@ func TestUpdateOperatorStatus(t *testing.T) {
734739
Type: fmt.Sprintf("%sDeploymentDegraded", defaultControllerName),
735740
Status: operatorv1.ConditionTrue,
736741
Reason: "UnavailablePod",
737-
Message: "3 of 3 requested instances are unavailable for apiserver.openshift-apiserver",
742+
Message: `3 of 3 requested instances are unavailable for apiserver.openshift-apiserver (no pods found with labels "app=apiserver")`,
738743
},
739744
{
740745
Type: fmt.Sprintf("%sDeployment%s", defaultControllerName, operatorv1.OperatorStatusTypeProgressing),
@@ -861,7 +866,7 @@ func TestUpdateOperatorStatus(t *testing.T) {
861866
// Combined deadline: 600+60 = 660s (11m).
862867
// Pod created 15m ago → past combined deadline → check is relevant.
863868
// LastTransitionTime 10s ago < MinReadySeconds (60s) → flapping → degraded.
864-
name: "scenario: pod with flapping Ready condition detected as failing",
869+
name: "scenario: pod with flapping Ready condition after successful rollout detected as failing",
865870
workload: &appsv1.Deployment{
866871
ObjectMeta: metav1.ObjectMeta{
867872
Name: "apiserver",
@@ -925,7 +930,7 @@ func TestUpdateOperatorStatus(t *testing.T) {
925930
// MinReadySeconds=300, ProgressDeadlineSeconds defaults to 600.
926931
// Combined deadline: 600+300 = 900s (15m).
927932
// Pod created 8m ago → still within combined deadline → check not relevant → not degraded.
928-
name: "scenario: pod with flapping Ready condition within combined deadline not flagged",
933+
name: "scenario: pod with flapping Ready condition after successful rollout within combined deadline not flagged",
929934
workload: &appsv1.Deployment{
930935
ObjectMeta: metav1.ObjectMeta{
931936
Name: "apiserver",
@@ -986,7 +991,7 @@ func TestUpdateOperatorStatus(t *testing.T) {
986991
// Combined deadline: 600+60 = 660s (11m).
987992
// Pod created 15m ago → past combined deadline → check is relevant.
988993
// LastTransitionTime 5m ago > MinReadySeconds (60s) → stable → not degraded.
989-
name: "scenario: stably ready pod past combined deadline not flagged as flapping",
994+
name: "scenario: stably ready pod after successful rollout past combined deadline not flagged as flapping",
990995
workload: &appsv1.Deployment{
991996
ObjectMeta: metav1.ObjectMeta{
992997
Name: "apiserver",
@@ -1016,6 +1021,15 @@ func TestUpdateOperatorStatus(t *testing.T) {
10161021
},
10171022
},
10181023
},
1024+
{
1025+
ObjectMeta: metav1.ObjectMeta{Name: "apiserver-2", Namespace: "openshift-apiserver", CreationTimestamp: metav1.NewTime(time.Now().Add(-10 * time.Second))},
1026+
Status: corev1.PodStatus{
1027+
Phase: corev1.PodRunning,
1028+
Conditions: []corev1.PodCondition{
1029+
{Type: corev1.PodReady, Status: corev1.ConditionTrue, LastTransitionTime: metav1.NewTime(time.Now().Add(-10 * time.Second))},
1030+
},
1031+
},
1032+
},
10191033
},
10201034
validateOperatorStatus: func(actualStatus *operatorv1.OperatorStatus) error {
10211035
expectedConditions := []operatorv1.OperatorCondition{

0 commit comments

Comments
 (0)