Files
cozystack/packages/apps/kubernetes/tests/nodegroups_default_test.yaml
Myasnikov DaniilandClaude Opus 4.8 c818ece25b test(kubernetes): cover md0 removability with user-defined nodeGroups
The existing case pins the empty-nodeGroups -> default md0 path (the helper's
else-branch). This adds the complementary if-branch: when a user supplies their
own nodeGroups, they are authoritative and the built-in md0 is NOT merged in, so
md0 is removable. The assertion selects every rendered MachineDeployment and
requires it to be the user's own group, so a regressed md0 leak surfaces as a
second MachineDeployment named <release>-md0 that fails the assertion.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
2026-06-30 12:08:18 +05:00

129 lines
4.3 KiB
YAML

suite: default md0 node group rendering
# When nodeGroups is left empty (chart default `nodeGroups: {}`), the
# kubernetes.nodeGroups helper must emit the built-in md0 group — this is the
# else-branch that makes md0 removable (an operator can drop md0 from their own
# nodeGroups) while a cluster that sets nothing still gets the default topology.
# A minimal VirtualMachineClusterInstancetype is mocked so the per-group
# instanceType lookup (u1.medium) returns non-nil; with no spec the template
# falls back to the default kubelet reservations, which is all this test needs.
templates:
- templates/cluster.yaml
kubernetesProvider:
scheme:
"instancetype.kubevirt.io/v1beta1/VirtualMachineClusterInstancetype":
gvr:
group: instancetype.kubevirt.io
version: v1beta1
resource: virtualmachineclusterinstancetypes
namespaced: false
"cluster.x-k8s.io/v1beta1/MachineSet":
gvr:
group: cluster.x-k8s.io
version: v1beta1
resource: machinesets
namespaced: true
"infrastructure.cluster.x-k8s.io/v1alpha1/KubevirtMachineTemplate":
gvr:
group: infrastructure.cluster.x-k8s.io
version: v1alpha1
resource: kubevirtmachinetemplates
namespaced: true
objects:
- kind: VirtualMachineClusterInstancetype
apiVersion: instancetype.kubevirt.io/v1beta1
metadata:
name: u1.medium
# Dummy CAPI objects so the MachineSet / KubevirtMachineTemplate LIST kinds
# are registered with the fake client. Shaped to be ignored by the
# old-template preservation loop (MachineSet infraRef is not a
# KubevirtMachineTemplate; the KubevirtMachineTemplate has no Cluster owner).
- kind: MachineSet
apiVersion: cluster.x-k8s.io/v1beta1
metadata:
name: ignored-ms
namespace: tenant-test
spec:
template:
spec:
infrastructureRef:
kind: Other
name: ignored
- kind: KubevirtMachineTemplate
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
metadata:
name: ignored-kmt
namespace: tenant-test
tests:
- it: renders the default md0 group when nodeGroups is empty
release:
name: test-k8s
namespace: tenant-test
set:
_namespace:
etcd: etcd
ingress: nginx
host: example.com
_cluster:
cluster-domain: cozy.local
# nodeGroups intentionally left at the chart default ({}) so the helper
# emits the built-in md0.
asserts:
# The default md0 MachineDeployment renders (helper else-branch).
- equal:
path: metadata.name
value: test-k8s-md0
documentSelector:
path: kind
value: MachineDeployment
# Default values flow through (e.g. the built-in 20Gi system disk).
- equal:
path: spec.template.spec.virtualMachineTemplate.spec.dataVolumeTemplates[0].spec.storage.resources.requests.storage
value: "20Gi"
documentSelector:
path: kind
value: KubevirtMachineTemplate
- it: drops md0 when the user defines their own node groups (md0 is removable)
release:
name: test-k8s
namespace: tenant-test
set:
_namespace:
etcd: etcd
ingress: nginx
host: example.com
_cluster:
cluster-domain: cozy.local
# A user-supplied nodeGroups map is authoritative — it is NOT merged with
# the built-in md0 (the helper's if-branch). This is the removability the
# PR exists for: a cluster that names only its own group no longer carries
# md0.
nodeGroups:
worker0:
minReplicas: 1
maxReplicas: 3
instanceType: "u1.medium"
diskSize: 20Gi
storageClass: ""
roles:
- ingress-nginx
resources: {}
gpus: []
kubelet: {}
asserts:
# Every rendered MachineDeployment must be the user's own group. The
# selector matches *all* MachineDeployments, so a leaked default md0
# would surface here as a second doc named test-k8s-md0 that fails the
# equal — proving md0 is gone (removable) when the user names their own.
- equal:
path: metadata.name
value: test-k8s-worker0
documentSelector:
path: kind
value: MachineDeployment
matchMany: true