Fix: Support Kubernetes 1.21 by handling missing availableReplicas field #950
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Support Kubernetes 1.21 by handling missing availableReplicas field
Problem
This PR fixes a critical compatibility issue where the operator fails to set RisingWave clusters to
running=trueon Kubernetes 1.21, despite claiming support for K8s 1.21+ in the README.Root Cause
The
status.availableReplicasfield was added to StatefulSet in Kubernetes 1.22 as an alpha feature (KEP-2599). The operator's readiness checks inpkg/utils/apps.gounconditionally use this field:On Kubernetes 1.21:
availableReplicasdoesn't exist and defaults to0updatedReplicas= actual replica count (e.g., 1)0 < 1→ always returnsfalseFound not-ready groups, keep waiting... action=WaitBeforeMetaStatefulSetsReadyrunning=falseforeverSolution
This PR implements backward compatibility by falling back to
readyReplicas(available since K8s 1.9) whenavailableReplicasis not available:Detection Logic
The fallback is triggered when:
availableReplicas == 0(field missing or truly zero)readyReplicas > 0(pods are actually ready)This ensures:
availableReplicas(more accurate)readyReplicas(backward compatible)Changes
Modified Files
pkg/utils/apps.goIsStatefulSetRolledOut(): Added fallback logic for StatefulSet (line 76-86)IsAdvancedStatefulSetRolledOut(): Added fallback logic for OpenKruise AdvancedStatefulSet (line 146-156)Testing
Tested on:
running=trueavailableReplicasfield)Behavior Changes
Before:
running=falseforever (broken)running=true(works)After:
running=true(fixed)running=true(still works, uses better field)Verification
On a K8s 1.21 cluster with this fix:
Background: KEP-2599 Timeline
availableReplicasfield in StatefulSetavailableReplicasadded as alpha (KEP-2599, enabled by default)Reference: KEP-2599: MinReadySeconds for StatefulSets
Related
Fixes issue #949
Checklist
apps.go)Note: This fix ensures the operator works as documented in the README compatibility matrix (K8s 1.21+). The fallback approach is safe and commonly used in the Kubernetes ecosystem for handling API evolution.