diff --git a/packages/apps/kubernetes-nodes/templates/nodegroup.yaml b/packages/apps/kubernetes-nodes/templates/nodegroup.yaml index 5bf3eaa51..85c8633bc 100644 --- a/packages/apps/kubernetes-nodes/templates/nodegroup.yaml +++ b/packages/apps/kubernetes-nodes/templates/nodegroup.yaml @@ -473,6 +473,17 @@ spec: {{- end }} - metadata: name: disk-system + {{- /* The worker WorkloadMonitor selects PVCs by these labels. CAPK + stamps cluster-name and role on the VM and its VMI template + only, copying dataVolumeTemplates verbatim, and CDI copies a + DataVolume's labels onto the PVC it creates -- so without them + here the disk is never tracked as a Workload. cluster-name must + NOT be added: the Kubernetes backup strategy selects DataVolumes + and PVCs by it, and would then back up and restore-in-place + every worker root disk as cluster data. */}} + labels: + cluster.x-k8s.io/deployment-name: {{ .clusterName }}-{{ .groupName }} + cluster.x-k8s.io/role: worker {{- /* usePopulator=false stays ONLY on the HTTP/import path: it preserves the legacy import behaviour and keeps an image-omitted DV — hence the KMT hash — byte-identical to the pre-feature render, so those workers @@ -1138,8 +1149,11 @@ spec: {{- end }} kind: kubernetes type: worker + {{- /* No cluster-name here: deployment-name already names one + MachineDeployment in the namespace, and requiring cluster-name would + force it onto the worker disk, which the Kubernetes backup strategy + would then select (see the disk-system labels above). */}} selector: - cluster.x-k8s.io/cluster-name: {{ $clusterName }} cluster.x-k8s.io/deployment-name: {{ $clusterName }}-{{ $groupName }} cluster.x-k8s.io/role: worker version: {{ $.Chart.Version }} diff --git a/packages/apps/kubernetes-nodes/tests/__snapshot__/render_snapshot_test.yaml.snap b/packages/apps/kubernetes-nodes/tests/__snapshot__/render_snapshot_test.yaml.snap index c8e990a9c..232cffa02 100644 --- a/packages/apps/kubernetes-nodes/tests/__snapshot__/render_snapshot_test.yaml.snap +++ b/packages/apps/kubernetes-nodes/tests/__snapshot__/render_snapshot_test.yaml.snap @@ -3,7 +3,7 @@ matches the golden render of a GPU pool: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: KubevirtMachineTemplate metadata: - name: kubernetes-myk8s-md0-8ed0ab + name: kubernetes-myk8s-md0-26667b namespace: tenant-test spec: template: @@ -19,6 +19,9 @@ matches the golden render of a GPU pool: - metadata: annotations: cdi.kubevirt.io/storage.usePopulator: "false" + labels: + cluster.x-k8s.io/deployment-name: kubernetes-myk8s-md0 + cluster.x-k8s.io/role: worker name: disk-system spec: source: @@ -115,7 +118,7 @@ matches the golden render of a GPU pool: infrastructureRef: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: KubevirtMachineTemplate - name: kubernetes-myk8s-md0-8ed0ab + name: kubernetes-myk8s-md0-26667b namespace: tenant-test version: v1.35.6 3: | @@ -149,7 +152,6 @@ matches the golden render of a GPU pool: kind: kubernetes minReplicas: 0 selector: - cluster.x-k8s.io/cluster-name: kubernetes-myk8s cluster.x-k8s.io/deployment-name: kubernetes-myk8s-md0 cluster.x-k8s.io/role: worker type: worker @@ -159,7 +161,7 @@ matches the golden render of a kubelet-override pool: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: KubevirtMachineTemplate metadata: - name: kubernetes-myk8s-md0-2d362e + name: kubernetes-myk8s-md0-04d5d9 namespace: tenant-test spec: template: @@ -175,6 +177,9 @@ matches the golden render of a kubelet-override pool: - metadata: annotations: cdi.kubevirt.io/storage.usePopulator: "false" + labels: + cluster.x-k8s.io/deployment-name: kubernetes-myk8s-md0 + cluster.x-k8s.io/role: worker name: disk-system spec: source: @@ -268,7 +273,7 @@ matches the golden render of a kubelet-override pool: infrastructureRef: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: KubevirtMachineTemplate - name: kubernetes-myk8s-md0-2d362e + name: kubernetes-myk8s-md0-04d5d9 namespace: tenant-test version: v1.35.6 3: | @@ -302,7 +307,6 @@ matches the golden render of a kubelet-override pool: kind: kubernetes minReplicas: 0 selector: - cluster.x-k8s.io/cluster-name: kubernetes-myk8s cluster.x-k8s.io/deployment-name: kubernetes-myk8s-md0 cluster.x-k8s.io/role: worker type: worker @@ -312,7 +316,7 @@ matches the golden render of the pool objects: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: KubevirtMachineTemplate metadata: - name: kubernetes-myk8s-md0-a6ac3e + name: kubernetes-myk8s-md0-57ef01 namespace: tenant-test spec: template: @@ -329,6 +333,9 @@ matches the golden render of the pool objects: - metadata: annotations: cdi.kubevirt.io/storage.usePopulator: "false" + labels: + cluster.x-k8s.io/deployment-name: kubernetes-myk8s-md0 + cluster.x-k8s.io/role: worker name: disk-system spec: source: @@ -424,7 +431,7 @@ matches the golden render of the pool objects: infrastructureRef: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 kind: KubevirtMachineTemplate - name: kubernetes-myk8s-md0-a6ac3e + name: kubernetes-myk8s-md0-57ef01 namespace: tenant-test version: v1.35.6 3: | @@ -458,7 +465,6 @@ matches the golden render of the pool objects: kind: kubernetes minReplicas: 0 selector: - cluster.x-k8s.io/cluster-name: kubernetes-myk8s cluster.x-k8s.io/deployment-name: kubernetes-myk8s-md0 cluster.x-k8s.io/role: worker type: worker diff --git a/packages/apps/kubernetes-nodes/tests/nodegroup_test.yaml b/packages/apps/kubernetes-nodes/tests/nodegroup_test.yaml index e14bb480d..071f916f5 100644 --- a/packages/apps/kubernetes-nodes/tests/nodegroup_test.yaml +++ b/packages/apps/kubernetes-nodes/tests/nodegroup_test.yaml @@ -115,8 +115,35 @@ tests: path: spec.type value: worker - equal: - path: spec.selector["cluster.x-k8s.io/cluster-name"] - value: kubernetes-myk8s + path: spec.selector + value: + cluster.x-k8s.io/deployment-name: kubernetes-myk8s-md0 + cluster.x-k8s.io/role: worker + + # CDI copies the DataVolume's labels onto the PVC it creates, and CAPK does + # not label dataVolumeTemplates, so the worker disk only joins the + # WorkloadMonitor above if the template carries its whole selector. + - it: labels the worker disk with the WorkloadMonitor selector + documentSelector: + path: kind + value: KubevirtMachineTemplate + asserts: + - equal: + path: spec.template.spec.virtualMachineTemplate.spec.dataVolumeTemplates[0].metadata.labels + value: + cluster.x-k8s.io/deployment-name: kubernetes-myk8s-md0 + cluster.x-k8s.io/role: worker + + # The Kubernetes backup strategy selects DataVolumes and PVCs by + # cluster-name, so carrying it would back up every worker root disk and make + # an in-place restore delete and restore it as cluster data. + - it: keeps cluster-name off the worker disk + documentSelector: + path: kind + value: KubevirtMachineTemplate + asserts: + - notExists: + path: spec.template.spec.virtualMachineTemplate.spec.dataVolumeTemplates[0].metadata.labels["cluster.x-k8s.io/cluster-name"] --- suite: worker node pool validation templates: diff --git a/packages/apps/kubernetes-nodes/tests/resources_cpu_test.yaml b/packages/apps/kubernetes-nodes/tests/resources_cpu_test.yaml index 6bc9e31d7..b31ddd11d 100644 --- a/packages/apps/kubernetes-nodes/tests/resources_cpu_test.yaml +++ b/packages/apps/kubernetes-nodes/tests/resources_cpu_test.yaml @@ -246,7 +246,7 @@ tests: value: KubevirtMachineTemplate - equal: path: metadata.name - value: kubernetes-myk8s-md0-ce2335 + value: kubernetes-myk8s-md0-d5921f documentSelector: path: kind value: KubevirtMachineTemplate @@ -314,7 +314,7 @@ tests: asserts: - equal: path: metadata.name - value: kubernetes-myk8s-md0-ce2335 + value: kubernetes-myk8s-md0-d5921f # KubeVirt declares cores as uint32, so a count past its ceiling cannot size # the guest even though it is a whole number.