diff --git a/packages/apps/kubernetes-nodes/templates/_helpers.tpl b/packages/apps/kubernetes-nodes/templates/_helpers.tpl index 08a74b7ce..a727a1043 100644 --- a/packages/apps/kubernetes-nodes/templates/_helpers.tpl +++ b/packages/apps/kubernetes-nodes/templates/_helpers.tpl @@ -208,13 +208,13 @@ clusters in one namespace from colliding on a pool named e.g. `md0`. {{/* Fail early with a clear message if this pool's MachineDeployment already exists -under a different Helm release — i.e. the pool name collides with a nodeGroup -still managed by the parent kubernetes chart (most likely the default `md0`). +under a different Helm release: a worker pool migration 56 left with the parent +cluster's release, or another pool whose - split reconstructs +the same object name (cluster `a` with pool `b-c`, cluster `a-b` with pool `c`). Without this guard the collision surfaces as a cryptic Helm "invalid ownership metadata" error at install time. Inert under `helm template`/unittest (lookup -returns nil with no cluster) and a no-op during the Phase 2b adoption -migration, which re-annotates the MachineDeployment onto this release before -it reconciles. +returns nil with no cluster) and a no-op for a pool migration 56 adopted, which +re-annotates the MachineDeployment onto this release before it reconciles. */}} {{- define "kubernetes-nodes.assertNoForeignPool" -}} {{- $clusterName := include "kubernetes-nodes.clusterName" . -}} @@ -224,7 +224,7 @@ it reconciles. {{- if $existing -}} {{- $owner := dig "annotations" "meta.helm.sh/release-name" "" $existing.metadata -}} {{- if and $owner (ne $owner .Release.Name) -}} -{{- fail (printf "kubernetes-nodes: MachineDeployment %q in namespace %q is already managed by release %q, not this pool release %q — the pool name collides with a nodeGroup still managed by the parent kubernetes chart. Rename the pool or remove it from the parent Kubernetes CR's nodeGroups first." $mdName .Release.Namespace $owner .Release.Name) -}} +{{- fail (printf "kubernetes-nodes: MachineDeployment %q in namespace %q is already managed by release %q, not this pool release %q — two pools cannot share the object name kubernetes--: give this pool a name whose object name is free, or remove the existing pool from release %q first." $mdName .Release.Namespace $owner .Release.Name $owner) -}} {{- end -}} {{- /* clusterName-drift guard. The release name kubernetes-nodes-- does not encode where ends and begins: for one release diff --git a/packages/apps/kubernetes-nodes/tests/clustername_drift_test.yaml b/packages/apps/kubernetes-nodes/tests/clustername_drift_test.yaml index 57c4f79ff..8d0b56cf6 100644 --- a/packages/apps/kubernetes-nodes/tests/clustername_drift_test.yaml +++ b/packages/apps/kubernetes-nodes/tests/clustername_drift_test.yaml @@ -1,7 +1,7 @@ suite: worker pool clusterName-drift guard (assertNoForeignPool) # assertNoForeignPool reconstructs the pool MachineDeployment name -# kubernetes-- and looks it up. Beyond the pre-existing +# kubernetes-- and looks it up. Beyond the # foreign-owner branch, it refuses the render when a live MD of that name is # owned by this release but its spec.clusterName disagrees with the clusterName # this pool renders: that is the fingerprint of a post-create .Values.cluster @@ -126,3 +126,28 @@ tests: value: MachineDeployment exists: path: metadata.name + + # The other branch of the same guard: a live MachineDeployment of this name + # that another release owns, here the cluster's own release, which is what a + # pool migration 56 did not adopt still carries. The message has to point at + # a remedy the operator can act on; the cluster's Kubernetes CR renders no + # worker pool, so editing it cannot clear the conflict. + - it: refuses to render over a MachineDeployment another release owns + kubernetesProvider: + scheme: *scheme + objects: + - *kcp + - *schemeMachineSet + - *schemeKmt + - kind: MachineDeployment + apiVersion: cluster.x-k8s.io/v1beta1 + metadata: + name: kubernetes-myk8s-md0 + namespace: tenant-test + annotations: + meta.helm.sh/release-name: kubernetes-myk8s + spec: + clusterName: kubernetes-myk8s + asserts: + - failedTemplate: + errorPattern: 'already managed by release "kubernetes-myk8s", not this pool release "kubernetes-nodes-myk8s-md0" — two pools cannot share the object name kubernetes--: give this pool a name whose object name is free, or remove the existing pool from release "kubernetes-myk8s" first\.'