Skip to content

fix(kro): default omitted replicas to 1 instead of 0 - #1278

Open
magic-peach wants to merge 1 commit into
headlamp-k8s:mainfrom
magic-peach:fix/kro-replicas-default
Open

magic-peach wants to merge 1 commit into
headlamp-k8s:mainfrom
magic-peach:fix/kro-replicas-default

Conversation

@magic-peach

Copy link
Copy Markdown

Summary

Fixes the kro plugin's sub-resource health check treating a healthy Deployment or StatefulSet as unhealthy when spec.replicas is omitted from the manifest.

Related Issue

Fixes #1259

Changes

  • kro/src/resources/subResources.ts: default desired replicas to 1 instead of 0 for the Deployment and StatefulSet cases in both getSubResourceHealth and getResolvedValues, matching Kubernetes' own default for an omitted spec.replicas.
  • kro/src/resources/subResources.test.ts: added coverage for a Deployment/StatefulSet with spec.replicas omitted and one ready replica, asserting a success status and "1/1 ready" instead of the previous "1/0 ready" error.

Steps to Test

  1. cd kro && npm install
  2. npx vitest run src/resources/subResources.test.ts - all tests pass, including the new cases.
  3. Optionally, create a kro ResourceGraphDefinition with a Deployment that omits spec.replicas, create an instance, and check the Instance Detail page's Sub-resources section shows a green success badge with "1/1 ready" once the pod is up, instead of a red error badge showing "1/0 ready".

Screenshots (if applicable)

N/A, no visual change beyond the badge color/label for this specific case, and I did not have a live cluster to capture a screenshot against.

Notes for the Reviewer

  • The existing test asserting spec.replicas: 0 still returns an error status is unchanged and still passes, since ?? 1 only applies when the field is missing/undefined, not when it is explicitly 0.

Deployments and StatefulSets without an explicit spec.replicas are
healthy with 1 running pod, since Kubernetes defaults the field to 1.
The sub-resource health and resolved values helpers were defaulting
to 0 instead, so a healthy single replica resource showed a red error
badge and 1/0 ready.

Signed-off-by: Akanksha Trehun <akankshatrehun@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation matches Kubernetes defaults and includes focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes kro health reporting when Kubernetes defaults omitted Deployment or StatefulSet replicas to one.

Changes:

  • Default omitted replica counts to 1.
  • Add regression coverage for health and resolved-value labels.
File Description
kro/​src/​resources/​subResources.ts Applies Kubernetes replica defaults.
kro/​src/​resources/​subResources.test.ts Tests omitted-replica behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kro: Healthy Deployments show red "error" badge and "1/0 ready" when spec.replicas is omitted

2 participants