chore(kubernetes-nodes): name a remedy that works in the foreign-pool error

When a MachineDeployment named after the pool already belongs to
another Helm release, the render failed with advice to remove the pool
from the parent Kubernetes CR's nodeGroups. The parent renders no
worker pool any more, so that edit cannot clear the conflict. The cases
that do reach this guard are a pool migration 56 left with the
cluster's release and two pools whose <cluster>-<pool> split builds
the same object name; the message now says so and points at renaming
the pool or removing the other one.

The foreign-owner branch had no test, so a case pins it, including the
message, against a MachineDeployment owned by the cluster's release.

Assisted-by: LLM
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
Myasnikov Daniil committed 2026-11-12 18:03:43 +05:00
1 parent 8a45b3dd94
commit 3c519c7d6f
2 files changed
+32 -7

No files matched your search

@@ -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 <cluster>-<pool> 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-<cluster>-<pool>: 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-<cluster>-<pool>
does not encode where <cluster> ends and <pool> begins: for one release
@@ -1,7 +1,7 @@
suite: worker pool clusterName-drift guard (assertNoForeignPool)
# assertNoForeignPool reconstructs the pool MachineDeployment name
# kubernetes-<cluster>-<pool> and looks it up. Beyond the pre-existing
# kubernetes-<cluster>-<pool> 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-<cluster>-<pool>: give this pool a name whose object name is free, or remove the existing pool from release "kubernetes-myk8s" first\.'