Skip to content

fix(slime): render spec.replicas correctly when Values.replicas is 0#335

Merged
kb-yusukekimura merged 1 commit into
masterfrom
fix/slime-replicas-zero
May 14, 2026
Merged

fix(slime): render spec.replicas correctly when Values.replicas is 0#335
kb-yusukekimura merged 1 commit into
masterfrom
fix/slime-replicas-zero

Conversation

@kb-yusukekimura
Copy link
Copy Markdown
Contributor

@kb-yusukekimura kb-yusukekimura commented May 14, 2026

Summary

Fix a bug in the slime chart where Values.replicas: 0 is silently ignored and the Deployment is rendered without spec.replicas, causing Kubernetes to default the replica count to 1.

Root cause

Go template truthiness treats the numeric value 0 as falsy. The condition at templates/deployment.yaml:18 used .Values.replicas directly, so when replicas: 0 was set the and short-circuited to false and the entire replicas: block was skipped during rendering.

-  {{- if and (not .Values.autoscaling.enabled) .Values.replicas }}
+  {{- if and (not .Values.autoscaling.enabled) (ne .Values.replicas nil) }}

The same pattern is already used in php/templates/deployment.yaml:16 (ne .Values.replicaCount nil); this PR aligns slime with that precedent.

Changes

  • slime/templates/deployment.yaml: switch the replicas guard to a nil comparison.
  • slime/Chart.yaml: bump version from 1.3.1 to 1.3.2 (semver patch / bugfix).

Behavior matrix

Case Before After
replicas unset no spec.replicas no spec.replicas (unchanged)
replicas: 2 spec.replicas: 2 spec.replicas: 2 (unchanged)
replicas: 0 (bug) no spec.replicas → K8s defaults to 1 spec.replicas: 0
autoscaling.enabled: true + replicas: 2 no spec.replicas (HPA wins) no spec.replicas (unchanged)
autoscaling.enabled: true + replicas: 0 no spec.replicas (HPA wins) no spec.replicas (unchanged)

Verification

Test values used for helm template runs:

# /tmp/replicas-zero.yaml
deployment:
  enabled: true
replicas: 0
containers:
  - name: app
    image:
      repository: nginx
      tag: latest

1. Before the fix — bug reproduced (no spec.replicas)

$ helm template -f /tmp/replicas-zero.yaml slime/
...
spec:
  selector:               # <-- replicas line is missing
    matchLabels:
      app.kubernetes.io/name: slime
...

2. After the fix — replicas: 0 is rendered correctly

$ helm template -f /tmp/replicas-zero.yaml slime/
...
spec:
  replicas: 0             # <-- rendered as expected
  selector:
    matchLabels:
      app.kubernetes.io/name: slime
...

3. After the fix — autoscaling.enabled: true + replicas: 0 still omits spec.replicas (HPA wins)

$ helm template -f /tmp/replicas-zero-hpa.yaml slime/
...
spec:
  selector:               # <-- no replicas (HPA owns scaling)
    matchLabels:
      app.kubernetes.io/name: slime
...
---
# Source: slime/templates/hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
...

4. helm lint --strict passes on all examples

Ran helm lint --strict -f examples/<name>.yaml slime/ against deployment, deployment-hpa, deployment-ingress, cronjob, and cronjob-advanced. All five passed:

==> Linting slime
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, 0 chart(s) failed

Note: kubeval was not installed locally, so the kubeval portion of make lint is delegated to CI.

Test plan

  • helm template renders spec.replicas: 0 when replicas: 0 is set
  • helm template omits spec.replicas when autoscaling.enabled: true + replicas: 0
  • helm lint --strict passes for all five example values files
  • CI runs make lint (kubeval included) successfully

Go template truthiness treats numeric 0 as falsy, so the previous
`.Values.replicas` check skipped the `replicas:` block when replicas
was explicitly set to 0. Kubernetes then defaulted the Deployment to
1 replica.

Switch to `(ne .Values.replicas nil)` to distinguish "unset" from
"explicitly 0", matching the existing pattern in the php chart.

Bump chart version 1.3.1 -> 1.3.2 (patch / bugfix).

Refs: SREP-4455
@kb-yusukekimura kb-yusukekimura requested a review from tasuku43 May 14, 2026 01:15
Copy link
Copy Markdown
Contributor

@tasuku43 tasuku43 left a comment

Choose a reason for hiding this comment

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

LGTM!!

@kb-yusukekimura kb-yusukekimura merged commit ad99a2a into master May 14, 2026
2 checks passed
@kb-yusukekimura kb-yusukekimura deleted the fix/slime-replicas-zero branch May 14, 2026 01:19
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.

2 participants