Skip to content

Commit d30a2cf

Browse files
committed
docs+test(apps/kubernetes): align nodeGroups default docs with actual zero-worker topology + regression-guard the replicas fix
Follow-ups from the self-review of #3233: - `values.yaml` / helper docstring / regenerated README + schema + cozyrds openAPISchema + Go type doc: the previous "one ingress-nginx worker" contract was already misleading (helper default carried `minReplicas: 0` but the chart hardcoded `spec.replicas: 2`), and the replicas fix makes the docstring strictly false — an empty-nodeGroups install now provisions zero workers until either the cluster-autoscaler responds to an unschedulable Pod or the operator explicitly scales the group. Update the docstrings to describe the actual behaviour and to spell out the ingress-nginx-addon implication so operators are not surprised at addon-install time. - `tests/nodegroups_default_test.yaml`: two regression cases pinning `MachineDeployment.spec.replicas == $group.minReplicas` for `minReplicas: 0` (the render-side OIDC bats path — zero worker DataVolumes provisioned) and for `minReplicas: 2` (the kubernetes-latest / kubernetes-previous bats path — byte- identical to pre-PR behaviour). Without these a future refactor can silently re-hardcode `replicas: 2` and turn no tests red. helm-unittest suite grows from 171 to 173, both new cases pass. Ref: #3231. Signed-off-by: IvanHunters <[email protected]>
1 parent 6fd98dc commit d30a2cf

7 files changed

Lines changed: 108 additions & 27 deletions

File tree

‎api/apps/v1alpha1/kubernetes/types.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/apps/kubernetes/README.md‎

Lines changed: 23 additions & 23 deletions
Large diffs are not rendered by default.

‎packages/apps/kubernetes/templates/_helpers.tpl‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ re-add a baked-in default md0 on top of the user's groups, and because
124124
Kubernetes strips null values the default could never be removed. With the
125125
default applied only when the map is empty, users can freely choose their own
126126
node groups (and omit md0).
127+
128+
The default carries `minReplicas: 0`, which now propagates through to
129+
`MachineDeployment.spec.replicas: 0` (see the templates/cluster.yaml comment
130+
next to that field). Consequence: an empty-`nodeGroups` install provisions
131+
NO workers until either the cluster-autoscaler responds to an unschedulable
132+
Pod or an operator explicitly scales the group up. If the operator plans to
133+
enable the ingress-nginx addon, either supply an explicit nodeGroup with
134+
`roles: [ingress-nginx]` and `minReplicas >= 1`, or accept that the
135+
autoscaler will bring the default md0 up in response to the ingress-nginx
136+
controller Pods becoming Pending on install.
127137
*/}}
128138
{{- define "kubernetes.nodeGroups" -}}
129139
{{- if .Values.nodeGroups -}}

‎packages/apps/kubernetes/tests/nodegroups_default_test.yaml‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,74 @@ tests:
126126
path: kind
127127
value: MachineDeployment
128128
matchMany: true
129+
130+
# Regression guard for cozystack/cozystack#3231 — spec.replicas MUST reflect
131+
# the nodeGroup's minReplicas, not a hardcoded 2. Two matched cases so a
132+
# future refactor to a literal cannot silently regress both sides:
133+
# * minReplicas: 0 renders spec.replicas: 0 (the render-side OIDC test
134+
# path — no worker DataVolumes provisioned).
135+
# * minReplicas: 2 renders spec.replicas: 2 (the kubernetes-latest /
136+
# kubernetes-previous bats path — byte-identical to pre-PR behaviour).
137+
- it: MachineDeployment.spec.replicas equals nodeGroup.minReplicas — zero case
138+
release:
139+
name: test-k8s
140+
namespace: tenant-test
141+
set:
142+
_namespace:
143+
etcd: etcd
144+
ingress: nginx
145+
host: example.com
146+
_cluster:
147+
cluster-domain: cozy.local
148+
nodeGroups:
149+
worker0:
150+
minReplicas: 0
151+
maxReplicas: 10
152+
instanceType: "u1.medium"
153+
diskSize: 20Gi
154+
storageClass: ""
155+
roles:
156+
- worker
157+
resources: {}
158+
gpus: []
159+
kubelet: {}
160+
asserts:
161+
- equal:
162+
path: spec.replicas
163+
value: 0
164+
documentSelector:
165+
path: kind
166+
value: MachineDeployment
167+
matchMany: true
168+
169+
- it: MachineDeployment.spec.replicas equals nodeGroup.minReplicas — nonzero case
170+
release:
171+
name: test-k8s
172+
namespace: tenant-test
173+
set:
174+
_namespace:
175+
etcd: etcd
176+
ingress: nginx
177+
host: example.com
178+
_cluster:
179+
cluster-domain: cozy.local
180+
nodeGroups:
181+
worker0:
182+
minReplicas: 2
183+
maxReplicas: 10
184+
instanceType: "u1.medium"
185+
diskSize: 20Gi
186+
storageClass: ""
187+
roles:
188+
- worker
189+
resources: {}
190+
gpus: []
191+
kubelet: {}
192+
asserts:
193+
- equal:
194+
path: spec.replicas
195+
value: 2
196+
documentSelector:
197+
path: kind
198+
value: MachineDeployment
199+
matchMany: true

‎packages/apps/kubernetes/values.schema.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
},
1919
"nodeGroups": {
20-
"description": "Worker nodes configuration map. When left empty, a single default node group `md0` (one `ingress-nginx` worker) is provisioned. Provide your own groups to take full control — they are not merged with the default, so you may name and omit groups freely.",
20+
"description": "Worker nodes configuration map. When left empty, a default node group `md0` is emitted with `minReplicas: 0` and `roles: [ingress-nginx]` — the MachineDeployment renders but provisions no workers until an unschedulable Pod triggers the cluster-autoscaler (or an operator scales the group manually). Enabling `addons.ingressNginx.enabled: true` on a CR with default `nodeGroups: {}` therefore requires either supplying a nodeGroup with `roles: [ingress-nginx]` and `minReplicas \u003e= 1`, or waiting for the autoscaler to bring up the default md0 in response to the ingress-nginx controller Pods becoming Pending. Provide your own groups to take full control — they are not merged with the default, so you may name and omit groups freely.",
2121
"type": "object",
2222
"default": {},
2323
"additionalProperties": {

‎packages/apps/kubernetes/values.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ storageClass: replicated
8989
## @field {[]GPU} gpus - List of GPUs to attach (NVIDIA driver requires at least 4 GiB RAM).
9090
## @field {Kubelet} [kubelet] - Kubelet resource reservations for this node group.
9191

92-
## @param {map[string]NodeGroup} nodeGroups - Worker nodes configuration map. When left empty, a single default node group `md0` (one `ingress-nginx` worker) is provisioned. Provide your own groups to take full control — they are not merged with the default, so you may name and omit groups freely.
92+
## @param {map[string]NodeGroup} nodeGroups - Worker nodes configuration map. When left empty, a default node group `md0` is emitted with `minReplicas: 0` and `roles: [ingress-nginx]` — the MachineDeployment renders but provisions no workers until an unschedulable Pod triggers the cluster-autoscaler (or an operator scales the group manually). Enabling `addons.ingressNginx.enabled: true` on a CR with default `nodeGroups: {}` therefore requires either supplying a nodeGroup with `roles: [ingress-nginx]` and `minReplicas >= 1`, or waiting for the autoscaler to bring up the default md0 in response to the ingress-nginx controller Pods becoming Pending. Provide your own groups to take full control — they are not merged with the default, so you may name and omit groups freely.
9393
nodeGroups: {}
9494

9595
##

‎packages/system/kubernetes-rd/cozyrds/kubernetes.yaml‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)