Skip to content

fix: don't default null replicas/readyReplicas in Readiness checks - #4905

Merged
kubernetes-prow[bot] merged 2 commits into
kubernetes-client:masterfrom
sureshmelvinsigera:fix/readiness-null-replicas
Oct 5, 2026
Merged

kubernetes-prow[bot] merged 2 commits into
kubernetes-client:masterfrom
sureshmelvinsigera:fix/readiness-null-replicas

Conversation

@sureshmelvinsigera

Copy link
Copy Markdown
Contributor

isReplicaSetReady and isReplicationControllerReady silently treated a null spec.replicas as 1 and null status.readyReplicas as 0, which can misreport readiness. isStatefulSetReady already had this exact issue fixed by a maintainer in a prior review - this applies the same fix to the two remaining copy-pasted methods, plus regression tests.

See bc40df9 ("Addressed comment") for the original StatefulSet fix this mirrors.

@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 11, 2026
@sureshmelvinsigera
sureshmelvinsigera force-pushed the fix/readiness-null-replicas branch from 27ea3a3 to ae9a305 Compare September 11, 2026 03:15
@sureshmelvinsigera

Copy link
Copy Markdown
Contributor Author

Fixed two of the regression tests (nullReadyReplicas cases). They used replicas=3, which passed under both old and new code and didn't actually catch the bug. Changed to replicas=0, which is the case where the old default (readyReplicas=null becomes 0) would wrongly report ready.

isReplicaSetReady and isReplicationControllerReady silently treated a
null spec.replicas as 1 and null status.readyReplicas as 0, which can
misreport readiness. isStatefulSetReady already had this exact issue
fixed by a maintainer in a prior review - this applies the same fix
to the two remaining copy-pasted methods, plus regression tests.
@sureshmelvinsigera
sureshmelvinsigera force-pushed the fix/readiness-null-replicas branch from ae9a305 to b9afedb Compare September 11, 2026 03:29
@brendandburns

Copy link
Copy Markdown
Contributor

Some of this is philosophical, I guess. Is a replica set with zero replicas "ready" or not?

Can you check what client-go does in this case? That's probably as close to a spec as there exists for this question.

@sureshmelvinsigera

Copy link
Copy Markdown
Contributor Author

Checked client-go's WaitForReadyReplicaSet - it does *(rs.Spec.Replicas) == rs.Status.ReadyReplicas, so a 0-replica RS is ready there (0 == 0).

But: ReadyReplicas is omitempty on a plain int32 in the real API, so it's omitted from JSON whenever it's 0, not just when unset. We can't tell those apart - both show up as null. So the previous fix was too strict: a genuinely zero-replica RS would show null and we'd say "not ready," disagreeing with client-go.

Pushed an update: null spec.replicas still returns false (client-go doesn't guard against that either, so we're just safer there), but null readyReplicas is now treated as 0, matching what it actually means on the wire. Added tests for both cases.

readyReplicas is omitempty on a plain int in the real API, so it's
omitted from JSON whenever it's genuinely 0 - not just when unreported.
Treating null as 0 (rather than 'not ready') matches client-go's own
WaitForReadyReplicaSet check and fixes a case flagged in review where
a zero-replica ReplicaSet was incorrectly reported not-ready.
@sureshmelvinsigera
sureshmelvinsigera force-pushed the fix/readiness-null-replicas branch from ed42a60 to 0c31c25 Compare September 20, 2026 02:53
@sureshmelvinsigera

Copy link
Copy Markdown
Contributor Author

Pushed the client-go matching fix and formatting cleanup - ready for another look whenever you have a chance. Thanks!

@brendandburns

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 5, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, sureshmelvinsigera

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 5, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit af5d347 into kubernetes-client:master Oct 5, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants