Skip to content

Commit 6ac0ca0

Browse files
committed
fix: support Kubernetes 1.21-1.26 by handling missing availableReplicas field
The operator claims to support Kubernetes 1.21+ but fails to set RisingWave clusters to running=true on K8s versions 1.21-1.26. Root cause: The availableReplicas field was added to StatefulSet in Kubernetes 1.27 (KEP-3017). On older versions, 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-1.26 while maintaining optimal behavior on K8s 1.27+. 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: #XXX
1 parent bce1c4e commit 6ac0ca0

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.27+), otherwise fall back to readyReplicas.
77+
// The availableReplicas field was added in K8s 1.27 (KEP-3017).
78+
// For backward compatibility with K8s 1.21-1.26, we check readyReplicas instead.
79+
readyCount := statefulSet.Status.AvailableReplicas
80+
if readyCount == 0 && statefulSet.Status.ReadyReplicas > 0 {
81+
// availableReplicas is not available (K8s < 1.27), 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)