Skip to content

Commit fea4a6f

Browse files
authored
fix: support Kubernetes 1.21 by handling missing availableReplicas field (#950)
The operator claims to support Kubernetes 1.21+ but fails to set RisingWave clusters to running=true on K8s 1.21. Root cause: The availableReplicas field was added to StatefulSet in Kubernetes 1.22 as an alpha feature (KEP-2599). On K8s 1.21, this field doesn't exist and defaults to 0, causing readiness checks to always fail. Solution: Fall back to readyReplicas (available since K8s 1.9) when availableReplicas is not available. This ensures backward compatibility with K8s 1.21 while maintaining optimal behavior on K8s 1.22+. Changes: - pkg/utils/apps.go: Add fallback logic in IsStatefulSetRolledOut() - pkg/utils/apps.go: Add fallback logic in IsAdvancedStatefulSetRolledOut() Tested on Kubernetes 1.21.13 - clusters now correctly show running=true. Fixes: #949
1 parent bce1c4e commit fea4a6f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

pkg/utils/apps.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ func IsStatefulSetRolledOut(statefulSet *appsv1.StatefulSet) bool {
7373
return false
7474
}
7575

76-
if statefulSet.Status.AvailableReplicas < statefulSet.Status.UpdatedReplicas {
76+
// Use availableReplicas if available (K8s 1.22+), otherwise fall back to readyReplicas.
77+
// The availableReplicas field was added in K8s 1.22 alpha (KEP-2599).
78+
// For backward compatibility with K8s 1.21, we check readyReplicas instead.
79+
readyCount := statefulSet.Status.AvailableReplicas
80+
if readyCount == 0 && statefulSet.Status.ReadyReplicas > 0 {
81+
// availableReplicas is not available (K8s 1.21), use readyReplicas
82+
readyCount = statefulSet.Status.ReadyReplicas
83+
}
84+
if readyCount < statefulSet.Status.UpdatedReplicas {
7785
return false
7886
}
7987

@@ -135,7 +143,14 @@ func IsAdvancedStatefulSetRolledOut(statefulSet *kruiseappsv1beta1.StatefulSet)
135143
return false
136144
}
137145

138-
if statefulSet.Status.AvailableReplicas < statefulSet.Status.UpdatedReplicas {
146+
// Use availableReplicas if available, otherwise fall back to readyReplicas.
147+
// This ensures compatibility with different OpenKruise versions.
148+
readyCount := statefulSet.Status.AvailableReplicas
149+
if readyCount == 0 && statefulSet.Status.ReadyReplicas > 0 {
150+
// availableReplicas is not available, use readyReplicas
151+
readyCount = statefulSet.Status.ReadyReplicas
152+
}
153+
if readyCount < statefulSet.Status.UpdatedReplicas {
139154
return false
140155
}
141156

0 commit comments

Comments
 (0)