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

## What this PR does

Closes #5394.

capi-operator v0.30 lists every ConfigMap a provider's
`fetchConfig.selector` matches and returns an error when more than one
comes back, before it reads `spec.version`
(`processProviderConfigMaps`). Five of the six provider packages here
selected their bundle on a provider-kind label alone, so a version bump
— which renames the ConfigMap — left the old and the new ConfigMap
matching for the length of the Helm upgrade and failed that reconcile.
Helm deletes the old one in the same upgrade, so the next reconcile
succeeds: an error window rather than data loss, but one that hits every
upgrade of those providers.

`capi-providers-core` and the kubeadm half of `capi-providers-bootstrap`
already put `provider.cluster.x-k8s.io/version` on the ConfigMap and in
the selector. This does the same for the remaining five pairs:

| package | provider | version pinned |
|---|---|---|
| `capi-providers-bootstrap` | talos | `v0.6.13-bootstrap-talos` |
| `capi-providers-infraprovider` | kubevirt | `v0.1.10-infraprovider` |
| `capi-providers-infraprovider-proxmox` | proxmox |
`v0.7.7-infraprovider-proxmox` |
| `capi-providers-cpprovider` | kamaji | `v0.19.0-cozystack.0` |
| `capi-providers-ipam-in-cluster` | in-cluster |
`v1.0.3-ipam-in-cluster` |

The kind label each package already had (`infraprovider-provider`,
`cp-components`, `ipamprovider-provider`, `bootstrap-provider`) stays:
it is what keeps one provider's bundle out of another's selector, and it
is unrelated to the version match.

The comment in the Proxmox ConfigMap said the operator would still
install the right one because it keys every matched ConfigMap by name.
That is not what v0.30 does any more — it rejects the multiple match
outright — so the comment is replaced with what the operator does now,
and the reason the version label is there.

## Verification

New asserts in `hack/capi-provider-components_test.bats`, run with bats
1.14.0 and helm 3.19.0:

- `every provider selector pins the ConfigMap version` — for each of the
five packages plus core: exactly one provider object and one compressed
bundle render, the bundle's `provider.cluster.x-k8s.io/version` label is
non-empty, and both the selector and `spec.version` carry that same
value.
- `an upgrade with the previous ConfigMap present still matches one
bundle` — synthesises the upgrade window by adding the previous
release's bundle beside the rendered one; the selector has to keep
matching exactly one object.
- `the double-match fixture fails when the version label is removed` —
the negative control: with the version label dropped from both the
selector and the ConfigMap copy, that same fixture has to match two, so
the assertion above is known to be able to fail.
- `both bootstrap providers pin their own ConfigMap version` — the Talos
pair, which the single-provider helper cannot cover.

```
$ bats hack/capi-provider-components_test.bats
ok 25 every provider selector pins the ConfigMap version
ok 26 an upgrade with the previous ConfigMap present still matches one bundle
ok 27 the double-match fixture fails when the version label is removed
ok 28 both bootstrap providers pin their own ConfigMap version
```

A/B: with the template changes stashed and the tests kept, all four new
asserts fail (`selector does not pin the ConfigMap version`, `an upgrade
matches more than one ConfigMap`, `talos does not select exactly one
bundle`); restored, they pass.

Also run, unchanged by this PR:

- `bats hack/capi-upgrade-chart_test.bats` — 16/16
- `bats hack/capi-upgrade_test.bats` — 44/44
- `bats hack/capk-provider_test.bats` — 4/4
- `bats hack/bats-no-negated-assert.bats`, `bats-strict-setup.bats`,
`bats-no-exit-trap.bats` — 10/10, 19/19, 22/22
- `make -C packages/system/capi-providers-bootstrap test` (helm-unittest
1.1.2) — 9/9
- `bash hack/check-commit-trailers.sh origin/main..HEAD` — OK
- `python3 hack/check-helm-document-indices.py main` — clean
- `git diff --check` — clean

Not covered locally: 8 asserts in
`hack/capi-provider-components_test.bats` fail on this machine both
before and after this change, all with `sed: illegal option -- -` —
`check_sums` / `check_patched_sums` use GNU `sed --quiet`, which is not
POSIX and not present in macOS's BSD sed. They are unrelated to this
diff and pass in CI on Linux. No full ctest/Go build was needed: the
change is Helm templates and bats only.

## Downstream repositories

No downstream repository is affected. This changes the labels and
selectors inside five `packages/system/` charts; nothing in
`cozystack/website`, `terraform-provider-cozystack`,
`ansible-cozystack`, `ccp`, `talm`, `cozyhr`, `cozy-proxy`,
`cozystack-telemetry-server`, `external-apps-example`, `examples` or
`community` reads those label keys or restates these templates.
`packages/system/` is not imported into the website's managed-apps
reference, and no values key, schema, or release-notes convention
changes.

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

Bumping the Talos bootstrap, KubeVirt, Kamaji, Proxmox or in-cluster IPAM provider left its old and new components ConfigMap both matching the provider's selector for the length of the Helm upgrade, which capi-operator v0.30 rejects with "multiple ConfigMaps match selector". Each selector now carries `provider.cluster.x-k8s.io/version`, as the core and kubeadm providers already did, so an upgrade matches exactly one bundle.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Provider configurations now select the components bundle matching
their version, avoiding ambiguous matches when older and newer bundles
coexist during upgrades.
* Bootstrap providers now select their own version-specific bundle, so
each provider uses the correct components configuration.
* Provider and bundle versions remain aligned across supported
infrastructure, IPAM, control-plane, and bootstrap providers.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Aleksei Sviridkin authored and GitHub committed 2026-12-02 08:08:15 +03:00
commit 7bf48125ca
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: