fix(cluster-api): pin the ConfigMap version in every provider selector

capi-operator v0.30 refuses a provider whose fetchConfig.selector matches
more than one ConfigMap, and it decides that before it reads spec.version
(processProviderConfigMaps). Talos bootstrap, KubeVirt, Kamaji, Proxmox and
in-cluster IPAM selected their bundle by a provider-kind label alone, so a
version bump left the old and the new ConfigMap matching for the length of
the Helm upgrade and failed that reconcile. Core and kubeadm already carry
provider.cluster.x-k8s.io/version in both the ConfigMap and the selector;
this brings the remaining five packages in line.

Each package now defines that version once, in templates/_helpers.tpl, and
the ConfigMap name, its version label, the selector and spec.version all
include it. Hard-coding the value in four places per provider meant a bump
could move the ConfigMap name and leave the label behind, and two bumps in
flight in the same package (as #5243 does for capmox and in-cluster IPAM)
would then disagree with each other. With one definition a bump is one line
and the four references cannot drift. The Talos pair uses its own define
because it tracks CABPT, while the kubeadm pair keeps the chart appVersion.

The comment in the Proxmox ConfigMap claiming the operator would still pick
the right one described the v0.30-or-earlier behaviour and is replaced with
what the operator does now.

Refs: #5394
Assisted-by: LLM
Signed-off-by: Goldloli <39011904+Goldloli@users.noreply.github.com>
This commit is contained in:
Goldloli authored and Aleksei Sviridkin committed 2026-12-02 03:43:19 +03:00
1 parent d27f8c950f
commit 7a94e202ca
16 files changed
+220 -18

No files matched your search

+126
View File
@@ -317,3 +317,129 @@ check_bootstrap_version() {
jq --exit-status '.httpGet.path == "/healthz" and .httpGet.port == "healthz" and .failureThreshold * .periodSeconds >= 300' <<< "$probe"
done
}
# capi-operator refuses a provider when its selector matches more than one
# ConfigMap, and it does that before it reads spec.version
# (processProviderConfigMaps in v0.30). During a Helm upgrade that renames the
# ConfigMap the old and the new one coexist for the length of the release, so a
# selector that does not pin the version matches both and the reconcile fails.
# Every selector therefore carries provider.cluster.x-k8s.io/version, and every
# ConfigMap carries it with the value the operator compares against.
#
# The old and new ConfigMaps are synthesised here rather than waiting for a
# bump: adding the retained copy of the current release beside the rendered one
# is the same state the upgrade window creates.
check_selectors_pin_the_version() {
local pkg="$1" provider_kind="$2"
local dir="$REPO_ROOT/packages/system/$pkg" rendered="$BATS_TEST_TMPDIR/$pkg.yaml"
helm template provider "$dir" --namespace cozy-cluster-api --kube-version 1.33.0 > "$rendered" \
|| { echo "$pkg: does not render" >&2; return 1; }
# One provider object and one components bundle, both carrying the same
# non-empty version label, and the selector's version equal to that label.
# Only ConfigMaps marked compressed are bundles: capi-providers-core also
# ships its upgrade script in one, which no selector matches.
yq --output-format=json --no-doc '.' "$rendered" | jq --slurp --exit-status --arg kind "$provider_kind" --arg pkg "$pkg" '
[.[] | select(.kind == $kind)] as $providers
| [.[] | select(.kind == "ConfigMap"
and .metadata.annotations["provider.cluster.x-k8s.io/compressed"] == "true")] as $maps
| ($providers | length) == 1
and ($maps | length) == 1
and ($maps[0].metadata.labels["provider.cluster.x-k8s.io/version"] // "") != ""
and $providers[0].spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"]
== $maps[0].metadata.labels["provider.cluster.x-k8s.io/version"]
and $providers[0].spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"]
== $providers[0].spec.version
' > /dev/null || { echo "$pkg: selector does not pin the ConfigMap version" >&2; return 1; }
}
@test "every provider selector pins the ConfigMap version" {
check_selectors_pin_the_version capi-providers-infraprovider InfrastructureProvider
check_selectors_pin_the_version capi-providers-infraprovider-proxmox InfrastructureProvider
check_selectors_pin_the_version capi-providers-cpprovider ControlPlaneProvider
check_selectors_pin_the_version capi-providers-ipam-in-cluster IPAMProvider
check_selectors_pin_the_version capi-providers-core CoreProvider
}
# The upgrade window itself: with the previous release's ConfigMap still in the
# namespace, the selector must still match exactly one object. Reverting the
# version label out of both the selector and the ConfigMap reproduces the bug
# this guard is for, so the fixture below proves the assertion can fail.
check_one_match_during_upgrade() {
local pkg="$1" provider_kind="$2" drop_version="$3"
local dir="$REPO_ROOT/packages/system/$pkg" rendered="$BATS_TEST_TMPDIR/$pkg-upgrade.yaml"
local objects="$BATS_TEST_TMPDIR/$pkg-upgrade.json"
helm template provider "$dir" --namespace cozy-cluster-api --kube-version 1.33.0 > "$rendered" \
|| { echo "$pkg: does not render" >&2; return 1; }
yq --output-format=json --no-doc '.' "$rendered" | jq --slurp --arg kind "$provider_kind" \
--arg drop "$drop_version" '
# The components bundle the previous release left behind, one version lower.
. + [([.[] | select(.kind == "ConfigMap"
and .metadata.annotations["provider.cluster.x-k8s.io/compressed"] == "true")][0]
| .metadata.name = "v0.0.1-previous"
| if $drop == "true" then del(.metadata.labels["provider.cluster.x-k8s.io/version"])
else .metadata.labels["provider.cluster.x-k8s.io/version"] = "v0.0.1-previous" end)]
| if $drop == "true" then
map(if (.kind == $kind) then del(.spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"]) else . end)
else . end
' > "$objects"
jq --slurp --exit-status --arg kind "$provider_kind" --arg pkg "$pkg" --arg drop "$drop_version" '
.[0] as $all
| [$all[] | select(.kind == $kind)][0] as $provider
| [$all[] | select(.kind == "ConfigMap"
and .metadata.annotations["provider.cluster.x-k8s.io/compressed"] == "true")
| select(.metadata.labels as $labels
| $provider.spec.fetchConfig.selector.matchLabels | to_entries | all(.[]; $labels[.key] == .value))]
| if $drop == "true" then
# The regression: without the version in the selector both ConfigMaps
# match, which is what the operator rejects.
length != 1
else
length == 1
end
' "$objects" > /dev/null || {
if [ "$drop_version" = "true" ]; then
echo "$pkg: fixture no longer reproduces a double match" >&2
else
echo "$pkg: an upgrade matches more than one ConfigMap" >&2
fi
return 1
}
}
@test "an upgrade with the previous ConfigMap present still matches one bundle" {
check_one_match_during_upgrade capi-providers-infraprovider InfrastructureProvider false
check_one_match_during_upgrade capi-providers-infraprovider-proxmox InfrastructureProvider false
check_one_match_during_upgrade capi-providers-cpprovider ControlPlaneProvider false
check_one_match_during_upgrade capi-providers-ipam-in-cluster IPAMProvider false
}
@test "the double-match fixture fails when the version label is removed" {
check_one_match_during_upgrade capi-providers-infraprovider-proxmox InfrastructureProvider true
}
# capi-providers-bootstrap carries two providers and two ConfigMaps, so the
# single-provider helpers above do not fit it. Each pair has to pin its own
# version, and selects exactly one bundle while the other provider's ConfigMap
# is present.
@test "both bootstrap providers pin their own ConfigMap version" {
local rendered="$BATS_TEST_TMPDIR/capi-providers-bootstrap.yaml" objects="$BATS_TEST_TMPDIR/capi-providers-bootstrap.json"
helm template provider "$REPO_ROOT/packages/system/capi-providers-bootstrap" --namespace cozy-cluster-api --kube-version 1.33.0 > "$rendered"
yq --output-format=json --no-doc '.' "$rendered" | jq --slurp '.' > "$objects"
for provider in kubeadm talos; do
jq --slurp --exit-status --arg provider "$provider" '
.[0] as $all
| [$all[] | select(.kind == "BootstrapProvider" and .metadata.name == $provider)][0] as $p
| $p.spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"] == $p.spec.version
and ([$all[] | select(.kind == "ConfigMap")
| select(.metadata.labels as $labels
| $p.spec.fetchConfig.selector.matchLabels | to_entries | all(.[]; $labels[.key] == .value))] | length) == 1
' "$objects" > /dev/null || { echo "capi-providers-bootstrap: $provider does not select exactly one bundle" >&2; return 1; }
done
}
@@ -14,3 +14,16 @@
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
The Talos bootstrap ConfigMap's version, defined once so the ConfigMap name, its
version label and the Talos provider's spec.version cannot drift apart. The
version label is what keeps a renamed ConfigMap from matching twice:
capi-operator lists every ConfigMap the selector matches and refuses a provider
while more than one is returned, before it reads spec.version
(processProviderConfigMaps). The kubeadm pair uses the chart appVersion instead
because it tracks the upstream Cluster API release.
*/}}
{{- define "capi-providers-bootstrap.talosVersion" -}}
v0.6.13-bootstrap-talos
{{- end -}}
@@ -16,8 +16,9 @@ data:
apiVersion: v1
kind: ConfigMap
metadata:
name: v0.6.13-bootstrap-talos
name: {{ include "capi-providers-bootstrap.talosVersion" . }}
labels:
provider.cluster.x-k8s.io/version: {{ include "capi-providers-bootstrap.talosVersion" . }}
bootstrap-components: cozy
bootstrap-provider: talos
annotations:
@@ -29,9 +29,10 @@ metadata:
name: talos
spec:
# https://github.com/siderolabs/cluster-api-bootstrap-provider-talos
version: v0.6.13-bootstrap-talos
version: {{ include "capi-providers-bootstrap.talosVersion" . }}
fetchConfig:
selector:
matchLabels:
provider.cluster.x-k8s.io/version: {{ include "capi-providers-bootstrap.talosVersion" . }}
bootstrap-components: cozy
bootstrap-provider: talos
@@ -0,0 +1,12 @@
{{/*
The version the ConfigMap, its version label and the provider's spec.version all
carry, defined once so a bump moves one line. The version label is what keeps a
renamed ConfigMap from matching twice: capi-operator lists every ConfigMap the
selector matches and refuses a provider while more than one is returned, before
it reads spec.version (processProviderConfigMaps). During a Helm upgrade that
renames the ConfigMap the old and the new one coexist for the length of the
release, so a selector without this label matches both and the reconcile fails.
*/}}
{{- define "capi-providers-cpprovider.version" -}}
v0.19.0-cozystack.0
{{- end -}}
@@ -3,8 +3,9 @@ kind: ConfigMap
metadata:
# Must match spec.version in templates/providers.yaml so the
# ControlPlaneProvider operator selects this components bundle.
name: v0.19.0-cozystack.0
name: {{ include "capi-providers-cpprovider.version" . }}
labels:
provider.cluster.x-k8s.io/version: {{ include "capi-providers-cpprovider.version" . }}
cp-components: cozy
annotations:
provider.cluster.x-k8s.io/compressed: "true"
@@ -9,10 +9,11 @@ spec:
# upstream master ships v1alpha2 only with no v1alpha1 conversion
# webhook. Bump along with UPSTREAM_VERSION / COZYSTACK_REV in the
# package Makefile.
version: v0.19.0-cozystack.0
version: {{ include "capi-providers-cpprovider.version" . }}
fetchConfig:
selector:
matchLabels:
provider.cluster.x-k8s.io/version: {{ include "capi-providers-cpprovider.version" . }}
cp-components: cozy
deployment:
containers:
@@ -0,0 +1,15 @@
{{/*
The version the ConfigMap, its version label and the provider's spec.version all
carry. capi-operator lists every ConfigMap the selector matches and refuses a
provider while more than one is returned, before it reads spec.version
(processProviderConfigMaps). During a Helm upgrade that renames the ConfigMap the
old and the new one coexist for the length of the release, so a selector without
this label matches both and the reconcile fails.
Define it once here: a bump then moves one line, and the four references below
cannot drift apart. `make components` in this package rewrites the vendored
files, not this value.
*/}}
{{- define "capi-providers-infraprovider-proxmox.version" -}}
v0.7.7-infraprovider-proxmox
{{- end -}}
@@ -1,20 +1,23 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: v0.7.7-infraprovider-proxmox
name: {{ include "capi-providers-infraprovider-proxmox.version" . }}
{{- /*
NOT 'infraprovider-components: cozy'. That label already identifies the
KubeVirt provider's ConfigMap, and a shared label would put both in the
same match. The operator would still install the right one — it keys every
matched ConfigMap by its name as the version and takes the one equal to
spec.version — but it builds that repository in a single pass and returns
an error for the whole list as soon as one match is malformed: a name that
does not parse as semver, or missing metadata. Sharing the label would let
a broken ConfigMap of one provider stop the other from being installed.
The kubeadm/talos bootstrap packages separate on a 'bootstrap-provider'
key for the same reason; this mirrors that.
same match. The kubeadm/talos bootstrap packages separate on a
'bootstrap-provider' key for the same reason; this mirrors that.
The version label is what keeps a renamed ConfigMap from matching twice.
capi-operator lists every ConfigMap the selector matches and refuses a
provider while more than one is returned, before it reads spec.version
(processProviderConfigMaps). During a Helm upgrade that bumps the version
the old and the new ConfigMap coexist for the length of the release, so a
selector without the version matches both and the reconcile fails until
Helm deletes the old one. With it, each upgrade sees exactly one.
*/}}
labels:
provider.cluster.x-k8s.io/version: {{ include "capi-providers-infraprovider-proxmox.version" . }}
infraprovider-provider: proxmox
annotations:
provider.cluster.x-k8s.io/compressed: "true"
@@ -9,13 +9,14 @@ spec:
# stores v1alpha2. v1alpha1 is still served through conversion, but that has
# not been tested with the kubernetes-nodes templates, and in-cluster IPAM
# should move to v1.1 at the same time. Bump the two together.
version: v0.7.7-infraprovider-proxmox
version: {{ include "capi-providers-infraprovider-proxmox.version" . }}
configSecret:
name: {{ .Values.credentialsSecretName | quote }}
namespace: {{ .Release.Namespace }}
fetchConfig:
selector:
matchLabels:
provider.cluster.x-k8s.io/version: {{ include "capi-providers-infraprovider-proxmox.version" . }}
infraprovider-provider: proxmox
deployment:
containers:
@@ -0,0 +1,12 @@
{{/*
The version the ConfigMap, its version label and the provider's spec.version all
carry, defined once so a bump moves one line. The version label is what keeps a
renamed ConfigMap from matching twice: capi-operator lists every ConfigMap the
selector matches and refuses a provider while more than one is returned, before
it reads spec.version (processProviderConfigMaps). During a Helm upgrade that
renames the ConfigMap the old and the new one coexist for the length of the
release, so a selector without this label matches both and the reconcile fails.
*/}}
{{- define "capi-providers-infraprovider.version" -}}
v0.1.10-infraprovider
{{- end -}}
@@ -1,8 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: v0.1.10-infraprovider
name: {{ include "capi-providers-infraprovider.version" . }}
labels:
provider.cluster.x-k8s.io/version: {{ include "capi-providers-infraprovider.version" . }}
infraprovider-components: cozy
annotations:
provider.cluster.x-k8s.io/compressed: "true"
@@ -4,10 +4,11 @@ metadata:
name: kubevirt
spec:
# https://github.com/kubernetes-sigs/cluster-api-provider-kubevirt
version: v0.1.10-infraprovider
version: {{ include "capi-providers-infraprovider.version" . }}
fetchConfig:
selector:
matchLabels:
provider.cluster.x-k8s.io/version: {{ include "capi-providers-infraprovider.version" . }}
infraprovider-components: cozy
deployment:
containers:
@@ -0,0 +1,12 @@
{{/*
The version the ConfigMap, its version label and the provider's spec.version all
carry, defined once so a bump moves one line. The version label is what keeps a
renamed ConfigMap from matching twice: capi-operator lists every ConfigMap the
selector matches and refuses a provider while more than one is returned, before
it reads spec.version (processProviderConfigMaps). During a Helm upgrade that
renames the ConfigMap the old and the new one coexist for the length of the
release, so a selector without this label matches both and the reconcile fails.
*/}}
{{- define "capi-providers-ipam-in-cluster.version" -}}
v1.0.3-ipam-in-cluster
{{- end -}}
@@ -1,8 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: v1.0.3-ipam-in-cluster
name: {{ include "capi-providers-ipam-in-cluster.version" . }}
labels:
provider.cluster.x-k8s.io/version: {{ include "capi-providers-ipam-in-cluster.version" . }}
ipamprovider-provider: in-cluster
annotations:
provider.cluster.x-k8s.io/compressed: "true"
@@ -11,10 +11,11 @@ spec:
# v1.0.x, not v1.1: both serve InClusterIPPool v1alpha2, but v1.1 moves to the
# v1beta2 contract and its IPAddressClaim API, while capmox v0.7, the only
# consumer here, is a v1beta1-contract provider. Move the two together.
version: v1.0.3-ipam-in-cluster
version: {{ include "capi-providers-ipam-in-cluster.version" . }}
fetchConfig:
selector:
matchLabels:
provider.cluster.x-k8s.io/version: {{ include "capi-providers-ipam-in-cluster.version" . }}
ipamprovider-provider: in-cluster
deployment:
containers: