feat(cluster-api)!: upgrade Cluster API to v1.14.4

Use the stable core and kubeadm release while retaining temporary
compatibility with v1beta1 providers. clusterctl rejects a direct jump
from v1.10, so legacy installations pass through v1.13.8 before Helm
applies the final provider manifests. CABPT v0.6.13 supports Talos v1.14
without changing its v1beta1 provider contract.

Select one repository at the full requested provider version. Change
bridge versions and selectors atomically, repair incomplete bridge
selectors, and reject concurrent configuration changes without
conflicting with status updates.

The transition must not accept stale readiness, overwrite another
requested upgrade or continue after an API error or deadline. Verify
both provider status and Deployment rollout, and leave fresh installs
and supported versions with matching selectors to normal installation.

Keep intermediate repositories in the operator dependency and ship
only their compressed bundles. The packages artifact does not apply
.helmignore, so unpacked duplicates can exceed the release Secret limit.
Retain the repositories for interrupted transitions, and preserve the
core startup probe across refreshes of either release.

BREAKING CHANGE: management clusters require Kubernetes v1.33 or later.

Link: https://github.com/kubernetes-sigs/cluster-api/blob/v1.14.0/cmd/clusterctl/client/cluster/upgrader.go#L377-L404
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
This commit is contained in:
Aleksei Sviridkin committed 2026-11-12 22:43:23 +03:00
1 parent fe810b7da8
commit adcafd10f2
42 files changed
+18456 -10317

No files matched your search

+4
View File
@@ -2,3 +2,7 @@
packages/system/capi-providers-infraprovider/images/cluster-api-provider-kubevirt/patches/*.diff -whitespace
packages/system/cilium/images/cilium-operator/patches/*.diff -whitespace
packages/system/seaweedfs/images/seaweedfs/patches/*.diff -whitespace
packages/system/capi-operator/charts/** linguist-vendored
packages/system/capi-operator/files/bridge-*.yaml linguist-generated
packages/system/capi-providers-core/files/*-components*.yaml linguist-generated
packages/system/capi-providers-bootstrap/files/*-components*.yaml linguist-generated
-34
View File
@@ -1,34 +0,0 @@
#!/usr/bin/env bats
# capi-providers-core ships the Cluster API core manifests twice: as
# files/core-components.yaml, which a reviewer reads, and as files/components.gz,
# which the chart mounts into the cluster. Both are edited by hand; this package
# has no `make components`. An edit to the YAML alone reviews cleanly and changes
# nothing in a cluster, which is how the startupProbe from #2946 stayed out of
# the shipped manager. This holds the two files to the same bytes.
#
# The comparison is on the decompressed bytes, so the gzip header plays no part
# in it. `gzip -n` is still the flag to regenerate with: without it the header
# carries a timestamp and every regeneration rewrites the committed blob even
# when the input has not changed.
load test_helper
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
FILES="$REPO_ROOT/packages/system/capi-providers-core/files"
@test "core provider components.gz matches core-components.yaml" {
[ -f "$FILES/core-components.yaml" ] || { echo "missing core-components.yaml" >&2; return 1; }
[ -f "$FILES/components.gz" ] || { echo "missing components.gz" >&2; return 1; }
local work; work="$(mktemp -d)"
gzip -dc "$FILES/components.gz" > "$work/decompressed.yaml"
if ! cmp -s "$work/decompressed.yaml" "$FILES/core-components.yaml"; then
echo "components.gz does not match core-components.yaml" >&2
echo "the chart mounts the blob, so the cluster would run what the YAML does not say" >&2
echo "regenerate: gzip -9 -n -c files/core-components.yaml > files/components.gz" >&2
diff "$work/decompressed.yaml" "$FILES/core-components.yaml" | head -20 >&2 || true
rm -rf "$work"
return 1
fi
rm -rf "$work"
}
+205 -12
View File
@@ -18,22 +18,22 @@ load test_helper
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
check_pair() {
local pkg="$1" yaml="$2"
local pkg="$1" yaml="$2" blob="${3:-components.gz}"
local dir="$REPO_ROOT/packages/system/$pkg/files"
[ -f "$dir/$yaml" ] || { echo "missing $pkg/files/$yaml" >&2; return 1; }
[ -f "$dir/components.gz" ] || { echo "missing $pkg/files/components.gz" >&2; return 1; }
[ -f "$dir/$blob" ] || { echo "missing $pkg/files/$blob" >&2; return 1; }
local work; work="$(mktemp -d)"
gzip -dc "$dir/components.gz" > "$work/decompressed.yaml"
gzip -dc "$dir/$blob" > "$work/decompressed.yaml"
if ! cmp -s "$work/decompressed.yaml" "$dir/$yaml"; then
echo "$pkg: components.gz does not match $yaml" >&2
echo "$pkg: $blob does not match $yaml" >&2
echo "the chart mounts the blob, so the cluster would run what the YAML does not say" >&2
if grep -q '^components:' "$REPO_ROOT/packages/system/$pkg/Makefile" 2>/dev/null; then
if [ "$blob" = components.gz ] && grep -q '^components:' "$REPO_ROOT/packages/system/$pkg/Makefile" 2>/dev/null; then
echo "run: make -C packages/system/$pkg components" >&2
else
echo "regenerate: gzip -9 -n -c files/$yaml > files/components.gz" >&2
echo "regenerate: gzip -9 -n -c files/$yaml > files/$blob" >&2
fi
head -40 "$work/decompressed.yaml" > "$work/a"
head -40 "$dir/$yaml" > "$work/b"
@@ -66,9 +66,10 @@ check_version() {
version="$(sed -n "s/^${makefile_var}=//p" "$dir/Makefile")"
[ -n "$version" ] || { echo "$pkg: no $makefile_var in Makefile" >&2; return 1; }
local cm_name provider_version
cm_name="$(sed -n 's/^ name: //p' "$dir/templates/configmaps.yaml")"
provider_version="$(sed -n 's/^ version: //p' "$dir/templates/providers.yaml")"
local cm_name provider_version rendered="$BATS_TEST_TMPDIR/$pkg.yaml"
helm template provider "$dir" --kube-version 1.33.0 > "$rendered"
provider_version="$(yq --no-doc 'select(.apiVersion == "operator.cluster.x-k8s.io/v1alpha2") | .spec.version' "$rendered")"
cm_name="$(PROVIDER_VERSION="$provider_version" yq --no-doc 'select(.kind == "ConfigMap" and .metadata.name == strenv(PROVIDER_VERSION)) | .metadata.name' "$rendered")"
if [ "$cm_name" != "$provider_version" ]; then
echo "$pkg: ConfigMap name '$cm_name' and spec.version '$provider_version' differ" >&2
@@ -100,16 +101,24 @@ check_version() {
# vendored file edited by hand, or a sum bumped without the file, both show up
# without anyone running the refresh target.
check_sums() {
local pkg="$1" makefile_var="$2" yaml="$3"
local pkg="$1" makefile_var="$2" yaml="$3" metadata="${4:-metadata.yaml}"
local metadata_var="${5:-${makefile_var}_SHA256_METADATA}"
local dir="$REPO_ROOT/packages/system/$pkg"
local sum_components sum_metadata
sum_components="$(sed -n "s/^${makefile_var}_SHA256_COMPONENTS=//p" "$dir/Makefile")"
sum_metadata="$(sed -n "s/^${makefile_var}_SHA256_METADATA=//p" "$dir/Makefile")"
sum_metadata="$(sed --quiet "s/^${metadata_var}=//p" "$dir/Makefile")"
[ -n "$sum_components" ] && [ -n "$sum_metadata" ] \
|| { echo "$pkg: Makefile pins no ${makefile_var}_SHA256_* sums" >&2; return 1; }
if ! printf '%s %s\n%s %s\n' "$sum_components" "$dir/files/$yaml" "$sum_metadata" "$dir/files/metadata.yaml" \
local components="$dir/files/$yaml"
case "$yaml" in
*.gz)
components="$BATS_TEST_TMPDIR/$makefile_var.yaml"
gzip --decompress --stdout "$dir/files/$yaml" > "$components" || return
;;
esac
if ! printf '%s %s\n%s %s\n' "$sum_components" "$components" "$sum_metadata" "$dir/files/$metadata" \
| sha256sum -c - >/dev/null 2>&1; then
echo "$pkg: a vendored file does not match the sum its Makefile pins" >&2
echo "either the file was edited without a refresh, or the sum moved without the file" >&2
@@ -117,6 +126,46 @@ check_sums() {
fi
}
# Packages that carry patches/ vendor a file that differs from the release
# asset, so its sum cannot be pinned directly. Reverting the patches recovers
# the asset, and that is checked against the pinned sum instead: a hand edit of
# the vendored file, a patch changed without a refresh, or a sum moved without
# the file all show up here.
check_patched_sums() {
local pkg="$1" makefile_var="$2" yaml="$3" metadata="${4:-metadata.yaml}"
local metadata_var="${5:-${makefile_var}_SHA256_METADATA}"
local dir="$REPO_ROOT/packages/system/$pkg"
local sum_components sum_metadata
sum_components="$(sed -n "s/^${makefile_var}_SHA256_COMPONENTS=//p" "$dir/Makefile")"
sum_metadata="$(sed --quiet "s/^${metadata_var}=//p" "$dir/Makefile")"
[ -n "$sum_components" ] && [ -n "$sum_metadata" ] \
|| { echo "$pkg: Makefile pins no ${makefile_var}_SHA256_* sums" >&2; return 1; }
local work; work="$(mktemp -d)"
case "$yaml" in
*.gz) gzip --decompress --stdout "$dir/files/$yaml" > "$work/asset.yaml" || return ;;
*) cp "$dir/files/$yaml" "$work/asset.yaml" ;;
esac
local patches=() i
local patches_dir="${6:-$dir/patches}"
for i in "$patches_dir"/*.diff; do
[ -e "$i" ] && patches+=("$i")
done
for (( i = ${#patches[@]} - 1; i >= 0; i-- )); do
patch -s -f -R "$work/asset.yaml" < "${patches[$i]}" \
|| { echo "$pkg: $(basename "${patches[$i]}") does not revert cleanly from files/$yaml" >&2; rm -rf "$work"; return 1; }
done
if ! printf '%s %s\n%s %s\n' "$sum_components" "$work/asset.yaml" "$sum_metadata" "$dir/files/$metadata" \
| sha256sum -c - >/dev/null 2>&1; then
echo "$pkg: files/$yaml without patches/, or files/$metadata, does not match the sum its Makefile pins" >&2
rm -rf "$work"
return 1
fi
rm -rf "$work"
}
@test "capmox vendored files match the sums its Makefile pins" {
check_sums capi-providers-infraprovider-proxmox CAPMOX infrastructure-components.yaml
}
@@ -124,3 +173,147 @@ check_sums() {
@test "in-cluster IPAM vendored files match the sums its Makefile pins" {
check_sums capi-providers-ipam-in-cluster CAIP ipam-components.yaml
}
@test "CAPI core components.gz matches the vendored core-components.yaml" {
check_pair capi-providers-core core-components.yaml
}
@test "CAPI core vendored files match the sums its Makefile pins" {
check_patched_sums capi-providers-core CAPI core-components.yaml
}
@test "CAPI core ships the version its Makefile vendored" {
check_version capi-providers-core CAPI_VERSION
}
# capi-providers-bootstrap ships two providers, kubeadm and Talos, each with its
# own ConfigMap and BootstrapProvider, so the single-provider check above does
# not fit it. This asserts that the ConfigMap and the provider object for one of
# them both carry <Makefile version>-<suffix>.
check_bootstrap_version() {
local makefile_var="$1" suffix="$2"
local dir="${3:-$REPO_ROOT/packages/system/capi-providers-bootstrap}"
local version
version="$(sed -n "s/^${makefile_var} *= *//p" "$dir/Makefile")"
[ -n "$version" ] || { echo "capi-providers-bootstrap: no $makefile_var in Makefile" >&2; return 1; }
local want="$version-$suffix" rendered="$BATS_TEST_TMPDIR/$suffix.yaml" provider
case "$suffix" in
bootstrap) provider=kubeadm ;;
bootstrap-talos) provider=talos ;;
*) return 1 ;;
esac
helm template provider "$dir" --kube-version 1.33.0 > "$rendered"
[ "$(WANT="$want" yq --no-doc 'select(.kind == "ConfigMap" and .metadata.name == strenv(WANT)) | .metadata.name' "$rendered")" = "$want" ] \
|| { echo "capi-providers-bootstrap: no ConfigMap named $want" >&2; return 1; }
[ "$(PROVIDER="$provider" yq --no-doc 'select(.kind == "BootstrapProvider" and .metadata.name == strenv(PROVIDER)) | .spec.version' "$rendered")" = "$want" ] \
|| { echo "capi-providers-bootstrap: no BootstrapProvider at version $want" >&2; return 1; }
}
# A version carries dots, which a pattern match would take for any character.
@test "the bootstrap version check compares the version literally" {
local fx="$BATS_TEST_TMPDIR/bootstrap"
mkdir -p "$fx/templates"
printf 'CAPI_VERSION=v1.13.7\n' > "$fx/Makefile"
printf 'apiVersion: v2\nname: example\nversion: 0.0.0\n' > "$fx/Chart.yaml"
printf 'apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: v1x13x7-bootstrap\n' > "$fx/templates/configmaps.yaml"
printf 'apiVersion: operator.cluster.x-k8s.io/v1alpha2\nkind: BootstrapProvider\nmetadata:\n name: kubeadm\nspec:\n version: v1x13x7-bootstrap\n' > "$fx/templates/providers.yaml"
run check_bootstrap_version CAPI_VERSION bootstrap "$fx"
[ "$status" -ne 0 ]
}
@test "kubeadm bootstrap ships the version its Makefile vendored" {
check_bootstrap_version CAPI_VERSION bootstrap
}
@test "Talos bootstrap ships the version its Makefile vendored" {
check_bootstrap_version CABPT_UPSTREAM_VERSION bootstrap-talos
}
@test "Talos bootstrap components-talos.gz matches the vendored bootstrap-components-talos.yaml" {
check_pair capi-providers-bootstrap bootstrap-components-talos.yaml components-talos.gz
}
@test "Talos bootstrap vendored files match the sums its Makefile pins" {
check_patched_sums capi-providers-bootstrap CABPT bootstrap-components-talos.yaml metadata-talos.yaml
}
@test "Talos bootstrap keeps a dedicated service account and matching bindings" {
local file="$REPO_ROOT/packages/system/capi-providers-bootstrap/files/bootstrap-components-talos.yaml" accounts
[ "$(yq --no-doc 'select(.kind == "Deployment") | .spec.template.spec.serviceAccountName' "$file")" = cabpt-manager ]
[ "$(yq --no-doc 'select(.kind == "ServiceAccount") | .metadata.name' "$file")" = cabpt-manager ]
accounts="$(yq --no-doc 'select(.kind == "RoleBinding" or .kind == "ClusterRoleBinding") | .subjects[] | select(.kind == "ServiceAccount") | .name' "$file")"
[ -n "$accounts" ]
while IFS= read -r account; do
[ "$account" = cabpt-manager ]
done <<< "$accounts"
}
@test "kubeadm bootstrap components.gz matches the vendored bootstrap-components.yaml" {
check_pair capi-providers-bootstrap bootstrap-components.yaml
}
@test "kubeadm bootstrap vendored files match the sums its Makefile pins" {
check_sums capi-providers-bootstrap CAPI bootstrap-components.yaml
}
# The core and the kubeadm bootstrap provider are cut from one Cluster API
# release; running them at different versions is not a combination upstream
# tests.
@test "CAPI core and kubeadm bootstrap vendor the same Cluster API release" {
local core boot
core="$(sed -n 's/^CAPI_VERSION=//p' "$REPO_ROOT/packages/system/capi-providers-core/Makefile")"
boot="$(sed -n 's/^CAPI_VERSION=//p' "$REPO_ROOT/packages/system/capi-providers-bootstrap/Makefile")"
[ -n "$core" ] && [ "$core" = "$boot" ] \
|| { echo "core vendors '$core', kubeadm bootstrap vendors '$boot'" >&2; return 1; }
}
@test "CAPI charts reject management Kubernetes below the supported minimum" {
local pkg
for pkg in capi-providers-core capi-providers-bootstrap; do
run helm template "$pkg" "$REPO_ROOT/packages/system/$pkg" --kube-version 1.32.9
[ "$status" -ne 0 ]
[[ "$output" == *"requires kubeVersion"* ]]
done
}
@test "CAPI charts render on the minimum supported management Kubernetes" {
local pkg
for pkg in capi-providers-core capi-providers-bootstrap; do
run helm template "$pkg" "$REPO_ROOT/packages/system/$pkg" --kube-version 1.33.0
[ "$status" -eq 0 ]
[[ "$output" == *"kind: ConfigMap"* ]]
done
}
@test "intermediate core bundle recovers the pinned upstream release" {
check_patched_sums capi-operator CAPI_BRIDGE_CORE bridge-core-components.gz bridge-metadata.yaml CAPI_BRIDGE_SHA256_METADATA "$REPO_ROOT/packages/system/capi-providers-core/patches"
}
@test "intermediate kubeadm bundle matches the pinned upstream release" {
check_sums capi-operator CAPI_BRIDGE_BOOTSTRAP bridge-bootstrap-components.gz bridge-metadata.yaml CAPI_BRIDGE_SHA256_METADATA
}
@test "a changed compressed bootstrap bundle fails the pinned checksum" {
local fixture="$BATS_TEST_TMPDIR/fixture" source="$REPO_ROOT/packages/system/capi-operator"
mkdir "$fixture" "$fixture/packages" "$fixture/packages/system" "$fixture/packages/system/capi-operator" "$fixture/packages/system/capi-operator/files"
cp "$source/Makefile" "$fixture/packages/system/capi-operator/Makefile"
cp "$source/files/bridge-metadata.yaml" "$fixture/packages/system/capi-operator/files/bridge-metadata.yaml"
gzip --decompress --stdout "$source/files/bridge-bootstrap-components.gz" > "$BATS_TEST_TMPDIR/modified.yaml"
printf '\n# changed\n' >> "$BATS_TEST_TMPDIR/modified.yaml"
gzip --no-name --stdout "$BATS_TEST_TMPDIR/modified.yaml" > "$fixture/packages/system/capi-operator/files/bridge-bootstrap-components.gz"
REPO_ROOT="$fixture" run check_sums capi-operator CAPI_BRIDGE_BOOTSTRAP bridge-bootstrap-components.gz bridge-metadata.yaml CAPI_BRIDGE_SHA256_METADATA
[ "$status" -ne 0 ]
[[ "$output" == *"does not match the sum"* ]]
}
@test "both core bundles retain the certificate provisioning startup budget" {
local file probe manifest="$BATS_TEST_TMPDIR/core-components.yaml"
for file in capi-providers-core/files/components.gz capi-operator/files/bridge-core-components.gz; do
gzip --decompress --stdout "$REPO_ROOT/packages/system/$file" > "$manifest"
probe="$(yq --output-format=json --no-doc 'select(.kind == "Deployment" and .metadata.name == "capi-controller-manager") | .spec.template.spec.containers[] | select(.name == "manager") | .startupProbe' "$manifest")"
[ -n "$probe" ]
jq --exit-status '.httpGet.path == "/healthz" and .httpGet.port == "healthz" and .failureThreshold * .periodSeconds >= 300' <<< "$probe"
done
}
+151
View File
@@ -0,0 +1,151 @@
#!/usr/bin/env bats
load test_helper
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
CORE="$REPO_ROOT/packages/system/capi-providers-core"
setup() {
strict_setup
RENDERED="$BATS_TEST_TMPDIR/core.yaml"
helm template capi-providers-core "$CORE" --namespace test-capi --kube-version 1.33.0 > "$RENDERED"
}
@test "the intermediate upgrade runs before Helm applies final provider manifests" {
[ "$(yq --no-doc 'select(.kind == "Job") | .metadata.annotations."helm.sh/hook"' "$RENDERED")" = pre-install,pre-upgrade ]
[ "$(yq --no-doc 'select(.kind == "Job") | .spec.backoffLimit' "$RENDERED")" = 0 ]
[ "$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.restartPolicy' "$RENDERED")" = Never ]
[ "$(yq --no-doc 'select(.kind == "CoreProvider") | .metadata.annotations."helm.sh/hook"' "$RENDERED")" = null ]
local provider target
provider="$(yq --no-doc 'select(.kind == "CoreProvider") | .spec.version' "$RENDERED")"
target="$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].env[] | select(.name == "TARGET_VERSION") | .value' "$RENDERED")"
[ "$provider" = "$target-core" ]
}
@test "the operator retains intermediate bundles independently of migration hooks" {
local name bridge policy rendered="$BATS_TEST_TMPDIR/operator.yaml"
bridge="$(< "$CORE/files/bridge-version")"
[ "$bridge" = "$(< "$REPO_ROOT/packages/system/capi-operator/files/bridge-version")" ]
helm template capi-operator "$REPO_ROOT/packages/system/capi-operator" --namespace test-capi > "$rendered"
for name in "$bridge-core" "$bridge-bootstrap"; do
policy="$(NAME="$name" yq --no-doc 'select(.kind == "ConfigMap" and .metadata.name == strenv(NAME)) | .metadata.annotations."helm.sh/resource-policy"' "$rendered")"
[ "$policy" = keep ]
[ "$(NAME="$name" yq --no-doc 'select(.kind == "ConfigMap" and .metadata.name == strenv(NAME)) | .metadata.annotations."helm.sh/hook"' "$rendered")" = null ]
[ "$(NAME="$name" yq --no-doc 'select(.kind == "ConfigMap" and .metadata.name == strenv(NAME)) | .metadata.annotations."provider.cluster.x-k8s.io/compressed"' "$rendered")" = true ]
done
}
@test "the hook has no cluster-wide or secret permissions" {
local roles
roles="$(yq --output-format=json --no-doc 'select(.kind == "Role") | .rules' "$RENDERED")"
[ -n "$roles" ]
jq --exit-status 'length == 3 and all(.[];
(.verbs - ["get", "patch"] | length == 0) and
(.resourceNames | length > 0) and
(.resources - ["coreproviders", "bootstrapproviders", "deployments"] | length == 0)
)' <<< "$roles"
[ -z "$(yq --no-doc 'select(.kind == "ClusterRole" or .kind == "ClusterRoleBinding") | .kind' "$RENDERED")" ]
}
@test "the hook mounts its script and uses an explicit in-cluster kubeconfig" {
local script image
script="$(yq --no-doc 'select(.kind == "ConfigMap" and .metadata.name == "capi-providers-core-upgrade") | .data."upgrade-providers.sh"' "$RENDERED")"
[ -n "$script" ]
[ "$script" = "$(< "$CORE/files/upgrade-providers.sh")" ]
[ "$(yq --output-format=json --indent 0 --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].command' "$RENDERED")" = '["bash","/scripts/upgrade-providers.sh"]' ]
[ "$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.volumes[] | select(.name == "scripts") | .configMap.name' "$RENDERED")" = capi-providers-core-upgrade ]
[ "$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].volumeMounts[] | select(.name == "scripts") | .mountPath' "$RENDERED")" = /scripts ]
[ "$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].env[] | select(.name == "KUBE_CONTEXT") | .value' "$RENDERED")" = capi-upgrade ]
image="$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].image' "$RENDERED")"
[[ "$image" =~ @sha256:[0-9a-f]{64}$ ]]
}
@test "hook RoleBinding namespace remains a string for YAML keyword names" {
local rendered="$BATS_TEST_TMPDIR/keyword-namespace.yaml"
helm template capi-providers-core "$CORE" --namespace true --kube-version 1.33.0 > "$rendered"
[ "$(yq --no-doc 'select(.kind == "RoleBinding") | .subjects[0].namespace | tag' "$rendered")" = '!!str' ]
[ "$(yq --no-doc 'select(.kind == "RoleBinding") | .subjects[0].namespace' "$rendered")" = true ]
}
@test "the job deadline leaves room beyond the script deadline" {
local outer inner
outer="$(yq --no-doc 'select(.kind == "Job") | .spec.activeDeadlineSeconds' "$RENDERED")"
inner="$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].env[] | select(.name == "CAPI_UPGRADE_TIMEOUT_SECONDS") | .value' "$RENDERED")"
[ "$outer" -gt "$((inner + 10))" ]
[ "$outer" -lt 600 ]
}
@test "CAPI releases leave headroom for Helm Secret storage" {
local package chart manifest size budget=$((900 * 1024))
for package in capi-operator capi-providers-core; do
chart="$REPO_ROOT/packages/system/$package"
manifest="$BATS_TEST_TMPDIR/$package-manifest.yaml"
helm template "$package" "$chart" --namespace test-capi --kube-version 1.33.0 > "$manifest"
size="$(python3 -I "$REPO_ROOT/hack/helm-release-size.py" "$chart" < "$manifest")"
if [ "$size" -ge "$budget" ]; then
printf '%s: %s bytes exceeds storage budget %s\n' "$package" "$size" "$budget" >&2
return 1
fi
done
}
@test "every bootstrap variant waits for the core package migration" {
local variants
variants="$(yq --output-format=json '.spec.variants' "$REPO_ROOT/packages/core/platform/sources/capi-provider-bootstrap-kubeadm.yaml")"
[ -n "$variants" ]
jq --exit-status 'length > 0 and all(.[]; .dependsOn | index("cozystack.capi-provider-core") != null)' <<< "$variants"
}
render_repositories() {
local package
for package in capi-operator capi-providers-core capi-providers-bootstrap; do
helm template "$package" "$REPO_ROOT/packages/system/$package" --namespace test-capi --kube-version 1.33.0
printf '\n---\n'
done | yq --output-format=json --no-doc '.' | jq --slurp '.' > "$BATS_TEST_TMPDIR/repositories.json"
}
repository_matches_request() {
jq --exit-status --argjson count "${1:-2}" '
. as $objects | [.[] | select(.kind == "CoreProvider" or (.kind == "BootstrapProvider" and .metadata.name == "kubeadm"))] |
length == $count and all(.[]; . as $provider |
[$objects[] | select(.kind == "ConfigMap") | select(.metadata.labels as $labels |
$provider.spec.fetchConfig.selector.matchLabels | to_entries | all(.[]; $labels[.key] == .value))] |
length == 1 and ((.[0].metadata.labels["provider.cluster.x-k8s.io/version"] // .[0].metadata.name) == $provider.spec.version))
' "$BATS_TEST_TMPDIR/repositories.json"
}
@test "combined final repositories select one ConfigMap at the requested effective version" {
render_repositories
repository_matches_request
}
@test "combined bridge repositories select one ConfigMap at the requested effective version" {
render_repositories
local bridge
bridge="$(< "$CORE/files/bridge-version")"
jq --arg bridge "$bridge" 'map(if .kind == "CoreProvider" or (.kind == "BootstrapProvider" and .metadata.name == "kubeadm") then
.spec.version = ($bridge + (if .kind == "CoreProvider" then "-core" else "-bootstrap" end)) |
.spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"] = .spec.version
else . end)' "$BATS_TEST_TMPDIR/repositories.json" > "$BATS_TEST_TMPDIR/bridge.json"
mv "$BATS_TEST_TMPDIR/bridge.json" "$BATS_TEST_TMPDIR/repositories.json"
repository_matches_request
}
@test "a unique repository with an unsuffixed native version is rejected" {
render_repositories
jq 'map(select(.kind != "BootstrapProvider") | if (.kind == "CoreProvider") then
.spec.fetchConfig.selector.matchLabels = {"core-components": "cozy", "provider.cluster.x-k8s.io/version": "v1.14.4"}
elif (.kind == "ConfigMap" and .metadata.name == "v1.14.4-core") then
.metadata.labels["provider.cluster.x-k8s.io/version"] = "v1.14.4"
else . end)' "$BATS_TEST_TMPDIR/repositories.json" > "$BATS_TEST_TMPDIR/negative.json"
mv "$BATS_TEST_TMPDIR/negative.json" "$BATS_TEST_TMPDIR/repositories.json"
jq --exit-status '[.[] | select(.kind == "ConfigMap" and .metadata.labels["core-components"] == "cozy" and .metadata.labels["provider.cluster.x-k8s.io/version"] == "v1.14.4")] | length == 1' "$BATS_TEST_TMPDIR/repositories.json"
run repository_matches_request 1
[ "$status" -ne 0 ]
}
@test "Helm final restoration changes the bridge version and selector together" {
render_repositories
jq --exit-status '[.[] | select(.kind == "CoreProvider" or (.kind == "BootstrapProvider" and .metadata.name == "kubeadm"))] |
length == 2 and all(.[]; .spec.version == .spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"])' "$BATS_TEST_TMPDIR/repositories.json"
}
+274
View File
@@ -0,0 +1,274 @@
#!/usr/bin/env bats
load test_helper
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
UPGRADE_SCRIPT="$REPO_ROOT/packages/system/capi-providers-core/files/upgrade-providers.sh"
setup() {
strict_setup
mkdir "$BATS_TEST_TMPDIR/bin"
cp "$REPO_ROOT/hack/testdata/capi-upgrade/kubectl" "$BATS_TEST_TMPDIR/bin/kubectl"
chmod +x "$BATS_TEST_TMPDIR/bin/kubectl"
export PATH="$BATS_TEST_TMPDIR/bin:$PATH"
export KUBECONFIG=/dev/null KUBE_CONTEXT=fixture NAMESPACE=test-capi
export BRIDGE_VERSION=v1.13.8 TARGET_VERSION=v1.14.4
export CAPI_UPGRADE_TIMEOUT_SECONDS=60 CAPI_UPGRADE_POLL_SECONDS=0
export CAPI_TEST_CLOCK_JUMP="${CAPI_TEST_CLOCK_JUMP:-5}"
export BASH_ENV="$REPO_ROOT/hack/testdata/capi-upgrade/clock.bash"
export CAPI_TEST_STATE="$BATS_TEST_TMPDIR/state.json" CAPI_TEST_LOG="$BATS_TEST_TMPDIR/calls.jsonl"
: > "$CAPI_TEST_LOG"
jq --null-input '
def provider($name; $suffix): {
metadata: {name: $name, uid: $name, generation: 1},
spec: {version: ("v1.10.1-" + $suffix), fetchConfig: {selector: {matchLabels: {($suffix + "-components"): "cozy"}}}},
status: {installedVersion: ("v1.10.1-" + $suffix), observedGeneration: 1, conditions: [{type: "Ready", status: "True"}]}
};
def deployment: {
metadata: {generation: 1}, spec: {replicas: 1},
status: {observedGeneration: 1, replicas: 1, updatedReplicas: 1, readyReplicas: 1, availableReplicas: 1}
};
{
providers: {"cluster-api": provider("cluster-api"; "core"), kubeadm: provider("kubeadm"; "bootstrap")},
deployments: {"capi-controller-manager": deployment, "capi-kubeadm-bootstrap-controller-manager": deployment}
}' > "$CAPI_TEST_STATE"
}
fixture() {
jq "$1" "$CAPI_TEST_STATE" > "$BATS_TEST_TMPDIR/next.json"
mv "$BATS_TEST_TMPDIR/next.json" "$CAPI_TEST_STATE"
}
accepted_patches() {
jq --slurp --compact-output '[.[] | select(.accepted == true) | {name, version: (.patch[] | select(.path == "/spec/version" and .op == "replace") | .value)}]' "$CAPI_TEST_LOG"
}
@test "fresh installations do not create or patch providers" {
fixture '.providers = {}'
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
[ "$(accepted_patches)" = '[]' ]
}
@test "providers within the supported upgrade window are unchanged" {
fixture '.providers["cluster-api"].spec.version = "v1.13.7-core" | .providers["cluster-api"].status.installedVersion = "v1.13.7-core" | .providers.kubeadm.spec.version = "v1.13.7-bootstrap" | .providers.kubeadm.status.installedVersion = "v1.13.7-bootstrap"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
[ "$(accepted_patches)" = '[]' ]
}
@test "legacy core and kubeadm converge on the intermediate release in order" {
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
[ "$(accepted_patches)" = '[{"name":"cluster-api","version":"v1.13.8-core"},{"name":"kubeadm","version":"v1.13.8-bootstrap"}]' ]
[ "$(jq --raw-output '.providers.kubeadm.status.installedVersion' "$CAPI_TEST_STATE")" = v1.13.8-bootstrap ]
}
@test "bootstrap waits for the intermediate core deployment rollout" {
fixture '.lagRollout = true'
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
[ "$(jq --raw-output '.deployments["capi-controller-manager"].status.readyReplicas' "$CAPI_TEST_STATE")" = 1 ]
[ "$(jq --raw-output '.deployments["capi-kubeadm-bootstrap-controller-manager"].status.readyReplicas' "$CAPI_TEST_STATE")" = 1 ]
}
@test "an interrupted transition resumes without downgrading core" {
fixture '.providers["cluster-api"].spec.version = "v1.13.8-core" | .providers["cluster-api"].spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"] = "v1.13.8-core" | .providers["cluster-api"].status.installedVersion = "v1.13.8-core"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
[ "$(accepted_patches)" = '[{"name":"kubeadm","version":"v1.13.8-bootstrap"}]' ]
}
@test "a final core upgrade already in progress is not reset to the bridge" {
fixture '.providers["cluster-api"].spec.version = "v1.14.4-core" | .providers["cluster-api"].status.installedVersion = "v1.13.8-core" | .pending = {"cluster-api": 2} | .providers["cluster-api"].spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"] = "v1.14.4-core"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
[ "$(accepted_patches)" = '[{"name":"kubeadm","version":"v1.13.8-bootstrap"}]' ]
[ "$(jq --raw-output '.providers["cluster-api"].status.installedVersion' "$CAPI_TEST_STATE")" = v1.14.4-core ]
}
@test "an API process cannot outlive the upgrade deadline" {
fixture '.readDelay = 3'
export CAPI_UPGRADE_TIMEOUT_SECONDS=1
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"timed out"* ]]
[ "$(accepted_patches)" = '[]' ]
[ "$(jq --raw-output '.delayedReadCompleted // false' "$CAPI_TEST_STATE")" = false ]
}
@test "a rollback of the requested core version resumes the installed bridge" {
fixture '.providers["cluster-api"].status.installedVersion = "v1.13.8-core"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
[ "$(accepted_patches)" = '[{"name":"cluster-api","version":"v1.13.8-core"},{"name":"kubeadm","version":"v1.13.8-bootstrap"}]' ]
}
@test "a missing kubeadm provider is not installed by the migration" {
fixture 'del(.providers.kubeadm)'
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
[ "$(accepted_patches)" = '[{"name":"cluster-api","version":"v1.13.8-core"}]' ]
}
@test "an API read failure aborts before any mutation" {
fixture '.failGet = "cluster-api"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"API unavailable"* ]]
[ "$(accepted_patches)" = '[]' ]
}
@test "a rejected patch aborts rather than reporting an upgraded provider" {
fixture '.failPatch = "cluster-api"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"patch refused"* ]]
[ "$(accepted_patches)" = '[]' ]
}
@test "replacing a provider between read and patch fails the UID precondition" {
fixture '.replaceUIDOnPatch = "cluster-api"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"JSON patch test failed"* ]]
[ "$(accepted_patches)" = '[]' ]
}
@test "a competing requested version is not overwritten by the migration" {
fixture '.replaceVersionOnPatch = "cluster-api"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"JSON patch test failed"* ]]
[ "$(accepted_patches)" = '[]' ]
[ "$(jq --raw-output '.providers["cluster-api"].spec.version' "$CAPI_TEST_STATE")" = v1.12.4-core ]
}
@test "a newer installed minor cannot be downgraded by the chart" {
fixture '.providers["cluster-api"].spec.version = "v1.15.0-core" | .providers["cluster-api"].status.installedVersion = "v1.15.0-core"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"downgrades are not supported"* ]]
[ "$(accepted_patches)" = '[]' ]
}
@test "a newer installed patch cannot be downgraded by the chart" {
fixture '.providers["cluster-api"].spec.version = "v1.14.5-core" | .providers["cluster-api"].status.installedVersion = "v1.14.5-core"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"downgrades are not supported"* ]]
[ "$(accepted_patches)" = '[]' ]
}
@test "malformed installed versions fail before either provider is changed" {
fixture '.providers.kubeadm.status.installedVersion = "invalid"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"invalid installed version"* ]]
[ "$(accepted_patches)" = '[]' ]
}
@test "an uninitialised provider is not mistaken for a fresh installation" {
fixture 'del(.providers["cluster-api"].status.installedVersion)'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"installed version is not recorded"* ]]
[ "$(accepted_patches)" = '[]' ]
}
@test "versions outside the intermediate upgrade window are rejected" {
fixture '.providers["cluster-api"].status.installedVersion = "v1.9.0-core" | .providers["cluster-api"].spec.version = "v1.9.0-core"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"outside the intermediate upgrade window"* ]]
[ "$(accepted_patches)" = '[]' ]
}
@test "a different requested upgrade is not overwritten" {
fixture '.providers["cluster-api"].spec.version = "v1.12.4-core"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"another upgrade is in progress"* ]]
[ "$(accepted_patches)" = '[]' ]
}
@test "a stalled intermediate rollout reaches a hard deadline" {
fixture '.stalled = true'
export CAPI_TEST_CLOCK_JUMP=61
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"timed out"* ]]
[ "$(accepted_patches)" = '[{"name":"cluster-api","version":"v1.13.8-core"}]' ]
}
@test "bridge selection changes version and repository selector in one guarded patch" {
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
jq --slurp --exit-status 'all(.[] | select(.accepted); . as $call |
any(.patch[]; .op == "test" and .path == "/metadata/uid") and
any(.patch[]; .op == "test" and .path == "/spec/version") and
any(.patch[]; .op == "test" and .path == "/spec/fetchConfig") and
any(.patch[]; .path == "/spec/fetchConfig" and .op == "replace" and
.value.selector.matchLabels["provider.cluster.x-k8s.io/version"] ==
(if $call.name == "cluster-api" then "v1.13.8-core" else "v1.13.8-bootstrap" end)))' "$CAPI_TEST_LOG"
}
@test "already selected bridges repair stale selectors inside the supported window" {
fixture '.providers |= with_entries(.value.spec.version = ("v1.13.8-" + (if .key == "cluster-api" then "core" else "bootstrap" end)) | .value.status.installedVersion = .value.spec.version)'
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
jq --exit-status 'all(.providers[]; .spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"] == .spec.version)' "$CAPI_TEST_STATE"
}
@test "already selected bridges repair missing fetchConfig without changing other spec fields" {
fixture '.providers |= with_entries(.value.spec.version = ("v1.13.8-" + (if .key == "cluster-api" then "core" else "bootstrap" end)) | .value.status.installedVersion = .value.spec.version | .value.spec.deployment = {replicas: 2} | del(.value.spec.fetchConfig))'
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
jq --exit-status 'all(.providers[]; .spec.deployment.replicas == 2 and .spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"] == .spec.version)' "$CAPI_TEST_STATE"
jq --slurp --exit-status 'all(.[] | select(.accepted); any(.patch[]; .op == "test" and .path == "/spec") and any(.patch[]; .op == "add" and .path == "/spec/fetchConfig"))' "$CAPI_TEST_LOG"
}
@test "a matching bridge selector is an idempotent no-op" {
fixture '.providers |= with_entries(.value.spec.version = ("v1.13.8-" + (if .key == "cluster-api" then "core" else "bootstrap" end)) | .value.status.installedVersion = .value.spec.version | .value.spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"] = .value.spec.version)'
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
[ "$(accepted_patches)" = '[]' ]
}
@test "a concurrent fetchConfig replacement rejects the whole version transition" {
fixture '.replaceFetchConfigOnPatch = "cluster-api"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"JSON patch test failed"* ]]
[ "$(accepted_patches)" = '[]' ]
jq --exit-status '.providers["cluster-api"].spec | .version == "v1.10.1-core" and .fetchConfig.selector.matchLabels == {competing: "repository"}' "$CAPI_TEST_STATE"
}
@test "a concurrent fetchConfig creation rejects a stale add" {
fixture 'del(.providers["cluster-api"].spec.fetchConfig) | .replaceFetchConfigOnPatch = "cluster-api"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -ne 0 ]
[[ "$output" == *"JSON patch test failed"* ]]
[ "$(accepted_patches)" = '[]' ]
jq --exit-status '.providers["cluster-api"].spec | .version == "v1.10.1-core" and .fetchConfig.selector.matchLabels == {competing: "repository"}' "$CAPI_TEST_STATE"
}
@test "a status-only concurrent update does not conflict with bridge selection" {
fixture '.statusOnlyOnPatch = "cluster-api"'
run bash "$UPGRADE_SCRIPT"
[ "$status" -eq 0 ]
[ "$(jq --raw-output '.providers["cluster-api"].metadata.resourceVersion' "$CAPI_TEST_STATE")" = 2 ]
}
@test "the fake applies JSON Patch atomically when a later precondition fails" {
run kubectl --context fixture --namespace test-capi --request-timeout=10s patch coreproviders.operator.cluster.x-k8s.io cluster-api --type=json --patch '[{"op":"replace","path":"/spec/version","value":"v1.13.8-core"},{"op":"test","path":"/metadata/uid","value":"wrong"}]'
[ "$status" -ne 0 ]
[ "$(jq --raw-output '.providers["cluster-api"].spec.version' "$CAPI_TEST_STATE")" = v1.10.1-core ]
}
@test "the fake does not repair a stale selector or synthesize readiness" {
fixture '.pending = {"cluster-api": 0} | .providers["cluster-api"].spec.version = "v1.13.8-core" | .providers["cluster-api"].status.conditions = [{type: "Ready", status: "False"}]'
run kubectl --context fixture --namespace test-capi --request-timeout=10s get coreproviders.operator.cluster.x-k8s.io cluster-api --output json
[ "$status" -eq 0 ]
jq --exit-status '.providers["cluster-api"] | .status.installedVersion == "v1.10.1-core" and .status.conditions[0].status == "False" and (.spec.fetchConfig.selector.matchLabels | has("provider.cluster.x-k8s.io/version") | not)' "$CAPI_TEST_STATE"
}
+7
View File
@@ -0,0 +1,7 @@
sleep() {
if [[ -n "${CAPI_TEST_CLOCK_JUMP:-}" ]]; then
SECONDS=$((SECONDS + CAPI_TEST_CLOCK_JUMP))
else
command sleep "$@"
fi
}
+135
View File
@@ -0,0 +1,135 @@
#!/usr/bin/env python3
import copy
import json
import os
import sys
import time
from pathlib import Path
state_path = Path(os.environ["CAPI_TEST_STATE"])
log_path = Path(os.environ["CAPI_TEST_LOG"])
state = json.loads(state_path.read_text())
args = sys.argv[1:]
expected = ["--context", "fixture", "--namespace", "test-capi", "--request-timeout=10s"]
if args[:len(expected)] != expected:
sys.exit("unexpected kubectl context or namespace")
args = args[len(expected):]
verb, resource, name = args[:3]
resources = {
"coreproviders.operator.cluster.x-k8s.io": "providers",
"bootstrapproviders.operator.cluster.x-k8s.io": "providers",
"deployments.apps": "deployments",
}
if resource not in resources or name not in (
"cluster-api", "kubeadm", "capi-controller-manager", "capi-kubeadm-bootstrap-controller-manager"
):
sys.exit("unexpected resource")
entry = {"verb": verb, "resource": resource, "name": name}
def save():
state_path.write_text(json.dumps(state))
def log():
with log_path.open("a") as stream:
stream.write(json.dumps(entry) + "\n")
if verb == "get":
log()
time.sleep(state.get("readDelay", 0))
if state.get("readDelay"):
state["delayedReadCompleted"] = True
save()
if state.get("failGet") == name:
sys.exit("API unavailable")
obj = state[resources[resource]].get(name)
if obj is None:
if "--ignore-not-found" not in args:
sys.exit("NotFound")
sys.exit(0)
if resource != "deployments.apps" and name in state.get("pending", {}):
pending = state["pending"][name]
if pending > 0:
state["pending"][name] -= 1
elif not state.get("stalled") and obj["spec"].get("fetchConfig", {}).get("selector", {}).get("matchLabels", {}).get("provider.cluster.x-k8s.io/version") == obj["spec"]["version"]:
obj["status"]["installedVersion"] = obj["spec"]["version"]
obj["status"]["observedGeneration"] = obj["metadata"]["generation"]
obj["status"]["conditions"] = [{"type": "Ready", "status": "True"}]
deployment_name = "capi-controller-manager" if name == "cluster-api" else "capi-kubeadm-bootstrap-controller-manager"
deployment = state["deployments"][deployment_name]
deployment["metadata"]["generation"] += 1
deployment["status"]["observedGeneration"] = deployment["metadata"]["generation"]
deployment["status"]["updatedReplicas"] = 1
deployment["status"]["replicas"] = 1
deployment["status"]["readyReplicas"] = 0 if state.get("lagRollout") else 1
deployment["status"]["availableReplicas"] = deployment["status"]["readyReplicas"]
if state.get("lagRollout"):
state.setdefault("rolloutReads", {})[deployment_name] = 1
del state["pending"][name]
if resource == "deployments.apps" and name in state.get("rolloutReads", {}):
if state["rolloutReads"][name] > 0:
state["rolloutReads"][name] -= 1
else:
obj["status"]["readyReplicas"] = 1
obj["status"]["availableReplicas"] = 1
del state["rolloutReads"][name]
save()
print(json.dumps(obj))
elif verb == "patch":
if resource == "deployments.apps" or "--type=json" not in args:
sys.exit("unexpected write")
patch = json.loads(args[args.index("--patch") + 1])
entry["patch"] = patch
if state.get("failPatch") == name:
log()
sys.exit("patch refused")
obj = state["providers"][name]
if state.get("replaceUIDOnPatch") == name:
obj["metadata"]["uid"] = "replacement"
save()
if state.get("replaceVersionOnPatch") == name:
obj["spec"]["version"] = "v1.12.4-core"
save()
if state.get("replaceFetchConfigOnPatch") == name:
obj["spec"]["fetchConfig"] = {"selector": {"matchLabels": {"competing": "repository"}}}
save()
if state.get("statusOnlyOnPatch") == name:
obj["metadata"]["resourceVersion"] = "2"
obj["status"]["conditions"] = [{"type": "Ready", "status": "False"}]
save()
candidate = copy.deepcopy(obj)
for operation in patch:
keys = [key.replace("~1", "/").replace("~0", "~") for key in operation["path"].strip("/").split("/")]
parent = candidate
for key in keys[:-1]:
parent = parent[key]
key = keys[-1]
if operation["op"] == "test":
if key not in parent or parent[key] != operation["value"]:
log()
sys.exit("JSON patch test failed")
elif operation["op"] in ("replace", "add") and operation["path"] in ("/spec/version", "/spec/fetchConfig"):
if operation["op"] == "replace" and key not in parent:
sys.exit("JSON patch replace target missing")
if name == "kubeadm":
core = state["providers"]["cluster-api"]
deployment = state["deployments"]["capi-controller-manager"]
if core["status"]["installedVersion"] == "v1.10.1-core" or deployment["status"]["readyReplicas"] != 1:
log()
sys.exit("bootstrap upgrade started before core was ready")
parent[key] = operation["value"]
else:
sys.exit("unexpected patch operation")
obj = candidate
state["providers"][name] = obj
obj["metadata"]["generation"] += 1
obj["status"]["conditions"] = [{"type": "Ready", "status": "False"}]
state.setdefault("pending", {})[name] = 1
entry["accepted"] = True
save()
log()
print(json.dumps(obj))
else:
sys.exit("unexpected kubectl operation")
@@ -14,6 +14,7 @@ spec:
dependsOn:
- cozystack.networking
- cozystack.capi-operator
- cozystack.capi-provider-core
components:
- name: capi-providers-bootstrap
path: system/capi-providers-bootstrap
@@ -25,6 +26,7 @@ spec:
dependsOn:
- cozystack.networking
- cozystack.capi-operator
- cozystack.capi-provider-core
components:
- name: capi-providers-bootstrap
path: system/capi-providers-bootstrap
@@ -1,3 +1,5 @@
images
hack
.gitkeep
files/*-components.yaml
patches/
+22
View File
@@ -5,6 +5,12 @@ export REPO_URL=https://kubernetes-sigs.github.io/cluster-api-operator
export CHART_NAME=cluster-api-operator
export CHART_VERSION=0.30.0
CAPI_BRIDGE_VERSION=v1.13.8
CAPI_BRIDGE_URL=https://github.com/kubernetes-sigs/cluster-api/releases/download/$(CAPI_BRIDGE_VERSION)
CAPI_BRIDGE_CORE_SHA256_COMPONENTS=f28647b6c20956d56fd8a678bf477821036bea71f1a1318d9cacdc413c779957
CAPI_BRIDGE_BOOTSTRAP_SHA256_COMPONENTS=775ebb39516fcf17eccaa6f2d157fa763f90d7349f274520c5320cb693d88726
CAPI_BRIDGE_SHA256_METADATA=20ffd682bfc50ab5193aa14ba55222ba390f9204ccf6a0dd2d52c4a3c4fb004f
include ../../../hack/package.mk
update: clean capi-operator-update
@@ -18,3 +24,19 @@ update: clean capi-operator-update
patch -p1 < patches/profiling-independent.diff
patch -p1 < patches/fetch-config-types.diff
patch -p1 < patches/provider-string-types.diff
.PHONY: bridge-components
bridge-components:
mkdir .bridge-tmp
curl --fail --location --output .bridge-tmp/core-components.yaml $(CAPI_BRIDGE_URL)/core-components.yaml
curl --fail --location --output .bridge-tmp/bootstrap-components.yaml $(CAPI_BRIDGE_URL)/bootstrap-components.yaml
curl --fail --location --output .bridge-tmp/metadata.yaml $(CAPI_BRIDGE_URL)/metadata.yaml
printf '%s .bridge-tmp/core-components.yaml\n%s .bridge-tmp/bootstrap-components.yaml\n%s .bridge-tmp/metadata.yaml\n' $(CAPI_BRIDGE_CORE_SHA256_COMPONENTS) $(CAPI_BRIDGE_BOOTSTRAP_SHA256_COMPONENTS) $(CAPI_BRIDGE_SHA256_METADATA) | sha256sum --check -
patch --batch .bridge-tmp/core-components.yaml < ../capi-providers-core/patches/0001-add-startup-probe.diff
mv .bridge-tmp/metadata.yaml files/bridge-metadata.yaml
gzip --best --no-name --stdout .bridge-tmp/core-components.yaml > files/bridge-core-components.gz
gzip --best --no-name --stdout .bridge-tmp/bootstrap-components.yaml > files/bridge-bootstrap-components.gz
rm .bridge-tmp/core-components.yaml .bridge-tmp/bootstrap-components.yaml
printf '%s\n' $(CAPI_BRIDGE_VERSION) | tee files/bridge-version ../capi-providers-core/files/bridge-version >/dev/null
if [ -f .bridge-tmp/core-components.yaml.orig ]; then rm .bridge-tmp/core-components.yaml.orig; fi
rmdir .bridge-tmp
+50
View File
@@ -0,0 +1,50 @@
# maps release series of major.minor to cluster-api contract version
# the contract version may change between minor or major versions, but *not*
# between patch versions.
#
# update this file only when a new major or minor version is released
apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3
kind: Metadata
releaseSeries:
- major: 1
minor: 13
contract: v1beta2
- major: 1
minor: 12
contract: v1beta2
- major: 1
minor: 11
contract: v1beta2
- major: 1
minor: 10
contract: v1beta1
- major: 1
minor: 9
contract: v1beta1
- major: 1
minor: 8
contract: v1beta1
- major: 1
minor: 7
contract: v1beta1
- major: 1
minor: 6
contract: v1beta1
- major: 1
minor: 5
contract: v1beta1
- major: 1
minor: 4
contract: v1beta1
- major: 1
minor: 3
contract: v1beta1
- major: 1
minor: 2
contract: v1beta1
- major: 1
minor: 1
contract: v1beta1
- major: 1
minor: 0
contract: v1beta1
@@ -0,0 +1 @@
v1.13.8
@@ -0,0 +1,32 @@
{{- $bridge := required "intermediate provider version is missing" (.Files.Get "files/bridge-version" | trim) -}}
{{/* Keep repositories available for providers left at the intermediate version. */}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $bridge }}-core
labels:
provider.cluster.x-k8s.io/version: {{ $bridge }}-core
core-components: cozy
annotations:
provider.cluster.x-k8s.io/compressed: "true"
helm.sh/resource-policy: keep
binaryData:
components: {{ required "intermediate core bundle is missing" (.Files.Get "files/bridge-core-components.gz") | b64enc | quote }}
data:
metadata: {{ required "intermediate provider metadata is missing" (.Files.Get "files/bridge-metadata.yaml") | quote }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $bridge }}-bootstrap
labels:
provider.cluster.x-k8s.io/version: {{ $bridge }}-bootstrap
bootstrap-components: cozy
bootstrap-provider: kubeadm
annotations:
provider.cluster.x-k8s.io/compressed: "true"
helm.sh/resource-policy: keep
binaryData:
components: {{ required "intermediate kubeadm bundle is missing" (.Files.Get "files/bridge-bootstrap-components.gz") | b64enc | quote }}
data:
metadata: {{ required "intermediate provider metadata is missing" (.Files.Get "files/bridge-metadata.yaml") | quote }}
@@ -1 +1,2 @@
files/.*-components.yaml
files/*-components*.yaml
patches/
@@ -1,3 +1,5 @@
apiVersion: v2
name: cozy-capi-providers-bootstrap
appVersion: "v1.14.4"
kubeVersion: ">=1.33.0-0"
version: 0.0.0 # Placeholder, the actual version will be automatically set during the build process
@@ -1,37 +1,59 @@
export NAME=capi-providers-bootstrap
export NAMESPACE=cozy-cluster-api
CAPI_VERSION=v1.14.4
CAPI_URL=https://github.com/kubernetes-sigs/cluster-api/releases/download/$(CAPI_VERSION)
# SHA-256 of the kubeadm bootstrap provider's two release assets at
# CAPI_VERSION. A release tag can be moved; these cannot. Keep CAPI_VERSION
# equal to the one in capi-providers-core/Makefile.
CAPI_SHA256_COMPONENTS=cf805775f24d197581b06e938bcd0eb9a9ed49d675f67e0f689ce7b71e5e397c
CAPI_SHA256_METADATA=c470906f551ac3e3e9aedc9a3e733b5a5994428693df43e95f65ea67c035f9fe
include ../../../hack/package.mk
.PHONY: update
.PHONY: update components test
test:
helm unittest .
# Upstream Talos bootstrap provider (CABPT) release pinned by tag. Keep
# in lockstep with templates/providers.yaml (BootstrapProvider spec.version)
# and templates/configmaps.yaml (ConfigMap name) — clusterctl matches the
# bundle by tag.
CABPT_UPSTREAM_VERSION = v0.6.12
CABPT_UPSTREAM_VERSION = v0.6.13
CABPT_URL=https://github.com/siderolabs/cluster-api-bootstrap-provider-talos/releases/download/$(CABPT_UPSTREAM_VERSION)
# SHA-256 of the two CABPT release assets at CABPT_UPSTREAM_VERSION, as
# downloaded, before patches/ is applied.
CABPT_SHA256_COMPONENTS=1e721ad294bdd5c8994aa957017cb94ad6e0cfd4ba52a52b45ed456d93efd4f8
CABPT_SHA256_METADATA=f2069963ae63593a795a7d134bb35999e372fd36240219a539f123c9387507ed
# Refreshes files/bootstrap-components-talos.yaml + files/components-talos.gz
# from upstream CABPT release artifacts at CABPT_UPSTREAM_VERSION with
# patches/ applied (the cozystack-side rename of the default ServiceAccount
# to cabpt-manager so capi-operator does not rewrite the SA namespace —
# see PR #2610 for the full rationale). Mirrors the symmetric update
# target in packages/system/capi-providers-cpprovider/Makefile.
#
# Run when bumping CABPT_UPSTREAM_VERSION or editing patches/. The
# metadata-talos.yaml file is checked in as-is from upstream and is not
# refreshed here (it changes far less often and a manual curl+diff is
# enough when CABPT cuts a new release series).
# Providers share a namespace. Keep CABPT's permissions off that namespace's
# default service account by retaining its dedicated account and bindings.
update:
@command -v patch >/dev/null || { echo "patch(1) required"; exit 1; }
rm -rf .update-tmp
mkdir .update-tmp
curl -sSL "https://github.com/siderolabs/cluster-api-bootstrap-provider-talos/releases/download/$(CABPT_UPSTREAM_VERSION)/bootstrap-components.yaml" \
-o .update-tmp/bootstrap-components.yaml
curl -fL -o .update-tmp/bootstrap-components.yaml $(CABPT_URL)/bootstrap-components.yaml
curl -fL -o .update-tmp/metadata.yaml $(CABPT_URL)/metadata.yaml
printf '%s .update-tmp/bootstrap-components.yaml\n%s .update-tmp/metadata.yaml\n' $(CABPT_SHA256_COMPONENTS) $(CABPT_SHA256_METADATA) | sha256sum -c -
for p in patches/*.diff; do \
[ -e "$$p" ] || continue; \
(cd .update-tmp && patch bootstrap-components.yaml < ../$$p) || exit 1; \
done
mv .update-tmp/bootstrap-components.yaml files/bootstrap-components-talos.yaml
gzip -nc files/bootstrap-components-talos.yaml > files/components-talos.gz
mv .update-tmp/metadata.yaml files/metadata-talos.yaml
gzip -9 -n -c files/bootstrap-components-talos.yaml > files/components-talos.gz
rm -rf .update-tmp
# Keep Chart.yaml appVersion equal to CAPI_VERSION: it selects the kubeadm
# version and ConfigMap that the operator installs.
components:
rm -rf .components-tmp
mkdir .components-tmp
curl -fL -o .components-tmp/bootstrap-components.yaml $(CAPI_URL)/bootstrap-components.yaml
curl -fL -o .components-tmp/metadata.yaml $(CAPI_URL)/metadata.yaml
printf '%s .components-tmp/bootstrap-components.yaml\n%s .components-tmp/metadata.yaml\n' $(CAPI_SHA256_COMPONENTS) $(CAPI_SHA256_METADATA) | sha256sum -c -
mv .components-tmp/bootstrap-components.yaml files/bootstrap-components.yaml
mv .components-tmp/metadata.yaml files/metadata.yaml
gzip -9 -n -c files/bootstrap-components.yaml > files/components.gz
rm -rf .components-tmp
@@ -699,7 +699,7 @@ spec:
- --insecure-diagnostics=${CAPI_INSECURE_DIAGNOSTICS:=false}
command:
- /manager
image: ghcr.io/siderolabs/cluster-api-talos-controller:v0.6.12
image: ghcr.io/siderolabs/cluster-api-talos-controller:v0.6.13
imagePullPolicy: Always
livenessProbe:
httpGet:
File diff suppressed because it is too large. Load diff
@@ -6,6 +6,18 @@
apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3
kind: Metadata
releaseSeries:
- major: 1
minor: 14
contract: v1beta2
- major: 1
minor: 13
contract: v1beta2
- major: 1
minor: 12
contract: v1beta2
- major: 1
minor: 11
contract: v1beta2
- major: 1
minor: 10
contract: v1beta1
@@ -0,0 +1,20 @@
{{- define "capi-providers-bootstrap.assertUpgradeWindow" -}}
{{- if .Capabilities.APIVersions.Has "operator.cluster.x-k8s.io/v1alpha2" -}}
{{- $provider := lookup "operator.cluster.x-k8s.io/v1alpha2" "BootstrapProvider" .Release.Namespace "kubeadm" -}}
{{- if $provider -}}
{{- $status := get $provider "status" | default dict -}}
{{- $installed := get $status "installedVersion" -}}
{{- if or (not (kindIs "string" $installed)) (eq $installed "") -}}
{{- fail "kubeadm provider installed version is not recorded; wait for the existing installation before upgrading" -}}
{{- end -}}
{{- $current := semver $installed -}}
{{- $target := semver .Chart.AppVersion -}}
{{- if or (gt $current.Major $target.Major) (and (eq $current.Major $target.Major) (gt $current.Minor $target.Minor)) (and (eq $current.Major $target.Major) (eq $current.Minor $target.Minor) (gt $current.Patch $target.Patch)) -}}
{{- fail "Cluster API provider downgrades are not supported" -}}
{{- end -}}
{{- if or (ne $current.Major $target.Major) (gt (sub $target.Minor $current.Minor) 3) -}}
{{- fail "kubeadm provider cannot skip more than three minor versions; upgrade the core provider package first to run the intermediate migration" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
@@ -1,8 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: v1.10.1-bootstrap
name: {{ .Chart.AppVersion }}-bootstrap
labels:
provider.cluster.x-k8s.io/version: {{ .Chart.AppVersion }}-bootstrap
bootstrap-components: cozy
bootstrap-provider: kubeadm
annotations:
@@ -15,7 +16,7 @@ data:
apiVersion: v1
kind: ConfigMap
metadata:
name: v0.6.12-bootstrap-talos
name: v0.6.13-bootstrap-talos
labels:
bootstrap-components: cozy
bootstrap-provider: talos
@@ -1,13 +1,15 @@
{{- include "capi-providers-bootstrap.assertUpgradeWindow" . }}
apiVersion: operator.cluster.x-k8s.io/v1alpha2
kind: BootstrapProvider
metadata:
name: kubeadm
spec:
# https://github.com/kubernetes-sigs/cluster-api
version: v1.10.1-bootstrap
version: {{ .Chart.AppVersion }}-bootstrap
fetchConfig:
selector:
matchLabels:
provider.cluster.x-k8s.io/version: {{ .Chart.AppVersion }}-bootstrap
bootstrap-components: cozy
bootstrap-provider: kubeadm
deployment:
@@ -27,7 +29,7 @@ metadata:
name: talos
spec:
# https://github.com/siderolabs/cluster-api-bootstrap-provider-talos
version: v0.6.12-bootstrap-talos
version: v0.6.13-bootstrap-talos
fetchConfig:
selector:
matchLabels:
@@ -0,0 +1,141 @@
suite: kubeadm provider upgrade window
templates:
- templates/providers.yaml
release:
name: capi-providers-bootstrap
namespace: test-capi
capabilities:
majorVersion: 1
minorVersion: 33
apiVersions:
- operator.cluster.x-k8s.io/v1alpha2
tests:
- it: allows a fresh installation
kubernetesProvider:
scheme: &scheme
operator.cluster.x-k8s.io/v1alpha2/BootstrapProvider:
gvr:
group: operator.cluster.x-k8s.io
version: v1alpha2
resource: bootstrapproviders
namespaced: true
objects:
- &other
apiVersion: operator.cluster.x-k8s.io/v1alpha2
kind: BootstrapProvider
metadata:
name: other
namespace: other
documentSelector:
path: metadata.name
value: kubeadm
asserts:
- isKind:
of: BootstrapProvider
- it: rejects the legacy installed version before the core migration
kubernetesProvider:
scheme: *scheme
objects:
- &legacy
apiVersion: operator.cluster.x-k8s.io/v1alpha2
kind: BootstrapProvider
metadata:
name: kubeadm
namespace: test-capi
spec:
version: v1.10.1-bootstrap
status:
installedVersion: v1.10.1-bootstrap
asserts:
- failedTemplate:
errorPattern: "upgrade the core provider package first"
- it: does not confuse a requested bridge version with an installed one
kubernetesProvider:
scheme: *scheme
objects:
- <<: *legacy
spec:
version: v1.13.8-bootstrap
asserts:
- failedTemplate:
errorPattern: "upgrade the core provider package first"
- it: accepts the installed intermediate release
kubernetesProvider:
scheme: *scheme
objects:
- <<: *legacy
spec:
version: v1.13.8-bootstrap
status:
installedVersion: v1.13.8-bootstrap
documentSelector:
path: metadata.name
value: kubeadm
asserts:
- isKind:
of: BootstrapProvider
- it: accepts the oldest supported minor despite the provider suffix
kubernetesProvider:
scheme: *scheme
objects:
- <<: *legacy
spec:
version: v1.11.0-bootstrap
status:
installedVersion: v1.11.0-bootstrap
documentSelector:
path: metadata.name
value: kubeadm
asserts:
- isKind:
of: BootstrapProvider
- it: refuses an existing provider without an installed version
kubernetesProvider:
scheme: *scheme
objects:
- <<: *legacy
status: {}
asserts:
- failedTemplate:
errorPattern: "installed version is not recorded"
- it: refuses a downgrade
kubernetesProvider:
scheme: *scheme
objects:
- <<: *legacy
spec:
version: v1.15.0-bootstrap
status:
installedVersion: v1.15.0-bootstrap
asserts:
- failedTemplate:
errorPattern: "downgrades are not supported"
- it: refuses a patch downgrade
kubernetesProvider:
scheme: *scheme
objects:
- <<: *legacy
spec:
version: v1.14.5-bootstrap
status:
installedVersion: v1.14.5-bootstrap
asserts:
- failedTemplate:
errorPattern: "downgrades are not supported"
- it: renders offline when the provider API is not served
capabilities:
apiVersions: []
documentSelector:
path: metadata.name
value: kubeadm
asserts:
- isKind:
of: BootstrapProvider
@@ -1 +1,2 @@
files/*-components.yaml
patches/
@@ -1,3 +1,5 @@
apiVersion: v2
name: cozy-capi-providers-core
appVersion: "v1.14.4"
kubeVersion: ">=1.33.0-0"
version: 0.0.0 # Placeholder, the actual version will be automatically set during the build process
@@ -1,4 +1,33 @@
export NAME=capi-providers-core
export NAMESPACE=cozy-cluster-api
CAPI_VERSION=v1.14.4
CAPI_URL=https://github.com/kubernetes-sigs/cluster-api/releases/download/$(CAPI_VERSION)
# SHA-256 of the two release assets at CAPI_VERSION, as downloaded. A release tag
# can be moved; these cannot. Bumping the version means recording the new sums
# here. files/core-components.yaml carries patches/ on top, so its own sum differs.
CAPI_SHA256_COMPONENTS=0030264eb0a0d90ebacc9da8f6bbb717bee32e45ffadc4a74784fb5ad7b9bb0b
CAPI_SHA256_METADATA=c470906f551ac3e3e9aedc9a3e733b5a5994428693df43e95f65ea67c035f9fe
include ../../../hack/package.mk
# Keep Chart.yaml appVersion equal to CAPI_VERSION: it selects the provider
# version and ConfigMap that the operator installs.
# patches/ is applied on top of the verified download. See the note in
# capi-providers-infraprovider-proxmox/Makefile on gzip -n.
.PHONY: components
components:
@command -v patch >/dev/null || { echo "patch(1) required"; exit 1; }
rm -rf .components-tmp
mkdir .components-tmp
curl -fL -o .components-tmp/core-components.yaml $(CAPI_URL)/core-components.yaml
curl -fL -o .components-tmp/metadata.yaml $(CAPI_URL)/metadata.yaml
printf '%s .components-tmp/core-components.yaml\n%s .components-tmp/metadata.yaml\n' $(CAPI_SHA256_COMPONENTS) $(CAPI_SHA256_METADATA) | sha256sum -c -
for p in patches/*.diff; do \
[ -e "$$p" ] || continue; \
(cd .components-tmp && patch core-components.yaml < ../$$p) || exit 1; \
done
mv .components-tmp/core-components.yaml files/core-components.yaml
mv .components-tmp/metadata.yaml files/metadata.yaml
gzip -9 -n -c files/core-components.yaml > files/components.gz
rm -rf .components-tmp
@@ -0,0 +1 @@
v1.13.8
File diff suppressed because it is too large. Load diff
@@ -6,6 +6,18 @@
apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3
kind: Metadata
releaseSeries:
- major: 1
minor: 14
contract: v1beta2
- major: 1
minor: 13
contract: v1beta2
- major: 1
minor: 12
contract: v1beta2
- major: 1
minor: 11
contract: v1beta2
- major: 1
minor: 10
contract: v1beta1
@@ -0,0 +1,166 @@
#!/usr/bin/env bash
set -euo pipefail
: "${KUBE_CONTEXT:?}" "${NAMESPACE:?}" "${BRIDGE_VERSION:?}" "${TARGET_VERSION:?}"
fail() {
printf 'CAPI upgrade: %s\n' "$*" >&2
exit 1
}
kube() {
local remaining=$((deadline - SECONDS)) status=0
((remaining > 0)) || fail "timed out before an API request"
timeout "$remaining" kubectl --context "$KUBE_CONTEXT" --namespace "$NAMESPACE" --request-timeout=10s "$@" || status=$?
((SECONDS < deadline)) || fail "timed out during an API request"
return "$status"
}
minor_version() {
local version="$1"
if [[ ! "$version" =~ ^v?1\.([0-9]+)\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
fail "invalid installed version: $version"
fi
local minor="${BASH_REMATCH[1]}"
[[ "$minor" =~ ^(0|[1-9][0-9]?)$ ]] || fail "invalid installed version: $version"
printf '%s\n' "$minor"
}
command -v timeout >/dev/null || fail "timeout command is required"
timeout_seconds="${CAPI_UPGRADE_TIMEOUT_SECONDS:-480}"
[[ "$timeout_seconds" =~ ^[1-9][0-9]{0,3}$ ]] || fail "invalid upgrade timeout"
deadline=$((SECONDS + timeout_seconds))
poll_seconds="${CAPI_UPGRADE_POLL_SECONDS:-2}"
[[ "$poll_seconds" =~ ^[0-9]+$ ]] || fail "invalid poll interval"
bridge_minor="$(minor_version "$BRIDGE_VERSION")"
target_minor="$(minor_version "$TARGET_VERSION")"
((target_minor >= bridge_minor && target_minor - bridge_minor <= 3)) || fail "invalid intermediate release"
core="$(kube get coreproviders.operator.cluster.x-k8s.io cluster-api --ignore-not-found --output json)"
bootstrap="$(kube get bootstrapproviders.operator.cluster.x-k8s.io kubeadm --ignore-not-found --output json)"
if [[ -z "$core" ]]; then
[[ -z "$bootstrap" ]] || fail "kubeadm exists without a core provider"
printf 'No installed providers need an intermediate upgrade.\n'
exit 0
fi
validate_provider() {
local object="$1" suffix="$2" installed requested uid minor requested_minor newer
installed="$(jq --raw-output '.status.installedVersion // empty' <<< "$object")"
[[ -n "$installed" ]] || fail "$suffix installed version is not recorded"
minor="$(minor_version "$installed")"
newer="$(jq --null-input --arg installed "$installed" --arg target "$TARGET_VERSION" '
def base: ltrimstr("v") | split("-")[0] | split("+")[0] | split(".") | map(tonumber);
($installed | base) > ($target | base)')"
[[ "$newer" == false ]] || fail "$suffix provider downgrades are not supported"
((bridge_minor - minor <= 3)) || fail "$suffix is outside the intermediate upgrade window"
requested="$(jq --raw-output '.spec.version // empty' <<< "$object")"
requested_minor="$(minor_version "$requested")"
uid="$(jq --raw-output '.metadata.uid // empty' <<< "$object")"
[[ -n "$uid" ]] || fail "$suffix provider UID is missing"
if [[ "$requested" != "$installed" && "$requested" != "$BRIDGE_VERSION-$suffix" && "$requested" != "$TARGET_VERSION-$suffix" ]]; then
# A failed Helm action can restore the old spec after the bridge installed.
[[ "$installed" == "$BRIDGE_VERSION-$suffix" && "$requested_minor" -lt "$bridge_minor" ]] \
|| fail "$suffix: another upgrade is in progress"
fi
}
validate_provider "$core" core
core_minor="$(minor_version "$(jq --raw-output '.status.installedVersion' <<< "$core")")"
bootstrap_minor="$target_minor"
if [[ -n "$bootstrap" ]]; then
validate_provider "$bootstrap" bootstrap
bootstrap_minor="$(minor_version "$(jq --raw-output '.status.installedVersion' <<< "$bootstrap")")"
fi
bridge_selector_needs_repair() {
jq --exit-status --arg version "$BRIDGE_VERSION-$2" '
.spec.version == $version and
.spec.fetchConfig.selector.matchLabels["provider.cluster.x-k8s.io/version"] != $version' <<< "$1" >/dev/null
}
if ((target_minor - core_minor <= 3 && target_minor - bootstrap_minor <= 3)) &&
! bridge_selector_needs_repair "$core" core &&
{ [[ -z "$bootstrap" ]] || ! bridge_selector_needs_repair "$bootstrap" bootstrap; }; then
printf 'Installed providers are within the supported upgrade window.\n'
exit 0
fi
wait_provider() {
local resource="$1" name="$2" deployment="$3" expected="$4" uid="$5"
local object ready rollout
while ((SECONDS < deadline)); do
object="$(kube get "$resource" "$name" --output json)"
[[ "$(jq --raw-output '.metadata.uid' <<< "$object")" == "$uid" ]] || fail "$name was replaced during the upgrade"
[[ "$(jq --raw-output '.spec.version' <<< "$object")" == "$expected" ]] || fail "$name requested version changed during the upgrade"
ready="$(jq --raw-output --arg expected "$expected" '
.status.installedVersion == $expected and
.status.observedGeneration == .metadata.generation and
any(.status.conditions[]?; .type == "Ready" and .status == "True")' <<< "$object")"
if [[ "$ready" == true ]]; then
rollout="$(kube get deployments.apps "$deployment" --ignore-not-found --output json)"
if [[ -n "$rollout" ]]; then
ready="$(jq --raw-output '
(.spec.replicas // 1) as $replicas |
$replicas > 0 and
.status.observedGeneration == .metadata.generation and
.status.replicas == $replicas and
.status.updatedReplicas == $replicas and
.status.readyReplicas == $replicas and
.status.availableReplicas == $replicas' <<< "$rollout")"
if [[ "$ready" == true ]]; then
printf '%s is ready at %s.\n' "$name" "$expected"
return
fi
fi
fi
sleep "$poll_seconds"
done
fail "$name timed out waiting for $expected"
}
stage_provider() {
local resource="$1" name="$2" deployment="$3" suffix="$4" object="$5"
local installed requested uid minor requested_minor expected patch
installed="$(jq --raw-output '.status.installedVersion' <<< "$object")"
requested="$(jq --raw-output '.spec.version' <<< "$object")"
uid="$(jq --raw-output '.metadata.uid' <<< "$object")"
minor="$(minor_version "$installed")"
requested_minor="$(minor_version "$requested")"
expected="$requested"
if ((minor < bridge_minor)); then
if [[ "$requested" == "$installed" || "$requested" == "$BRIDGE_VERSION-$suffix" ]] || ((target_minor - minor > 3)); then
expected="$BRIDGE_VERSION-$suffix"
fi
elif [[ "$installed" == "$BRIDGE_VERSION-$suffix" ]] && ((requested_minor < bridge_minor)); then
expected="$BRIDGE_VERSION-$suffix"
fi
if [[ "$requested" != "$expected" ]] || bridge_selector_needs_repair "$object" "$suffix"; then
patch="$(jq --compact-output --arg uid "$uid" --arg old "$requested" --arg next "$expected" --arg suffix "$suffix" '
.spec as $spec |
(if $spec.fetchConfig == null then
{selector: {matchLabels: {($suffix + "-components"): "cozy"}}} |
if $suffix == "bootstrap" then .selector.matchLabels["bootstrap-provider"] = "kubeadm" else . end
else $spec.fetchConfig end |
.selector.matchLabels["provider.cluster.x-k8s.io/version"] = $next) as $fetch |
[
{op: "test", path: "/metadata/uid", value: $uid},
{op: "test", path: "/spec/version", value: $old},
(if $spec | has("fetchConfig") then
{op: "test", path: "/spec/fetchConfig", value: $spec.fetchConfig}
else
{op: "test", path: "/spec", value: $spec}
end),
{op: "replace", path: "/spec/version", value: $next},
{op: (if $spec | has("fetchConfig") then "replace" else "add" end), path: "/spec/fetchConfig", value: $fetch}
]' <<< "$object")"
kube patch "$resource" "$name" --type=json --patch "$patch" >/dev/null
fi
wait_provider "$resource" "$name" "$deployment" "$expected" "$uid"
}
stage_provider coreproviders.operator.cluster.x-k8s.io cluster-api capi-controller-manager core "$core"
if [[ -n "$bootstrap" ]]; then
stage_provider bootstrapproviders.operator.cluster.x-k8s.io kubeadm capi-kubeadm-bootstrap-controller-manager bootstrap "$bootstrap"
fi
printf 'Intermediate provider upgrade completed.\n'
@@ -0,0 +1,13 @@
--- core-components.yaml
+++ core-components.yaml
@@ -20276,4 +20276,10 @@
imagePullPolicy: IfNotPresent
+ startupProbe:
+ httpGet:
+ path: /healthz
+ port: healthz
+ failureThreshold: 30
+ periodSeconds: 10
livenessProbe:
httpGet:
path: /healthz
@@ -1,8 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: v1.10.1-core
name: {{ .Chart.AppVersion }}-core
labels:
provider.cluster.x-k8s.io/version: {{ .Chart.AppVersion }}-core
core-components: cozy
annotations:
provider.cluster.x-k8s.io/compressed: "true"
@@ -5,10 +5,11 @@ metadata:
name: cluster-api
spec:
# https://github.com/kubernetes-sigs/cluster-api
version: v1.10.1-core
version: {{ .Chart.AppVersion }}-core
fetchConfig:
selector:
matchLabels:
provider.cluster.x-k8s.io/version: {{ .Chart.AppVersion }}-core
core-components: cozy
deployment:
containers:
@@ -0,0 +1,151 @@
{{- $bridge := required "intermediate provider version is missing" (.Files.Get "files/bridge-version" | trim) -}}
{{- $name := printf "%s-upgrade" .Release.Name -}}
{{- $timeout := 480 -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $name }}
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "-20"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
data:
upgrade-providers.sh: |
{{- required "provider upgrade script is missing" (.Files.Get "files/upgrade-providers.sh") | nindent 4 }}
kubeconfig: |
apiVersion: v1
kind: Config
current-context: capi-upgrade
clusters:
- name: in-cluster
cluster:
server: https://kubernetes.default.svc
certificate-authority: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
contexts:
- name: capi-upgrade
context:
cluster: in-cluster
user: upgrade
users:
- name: upgrade
user:
tokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ $name }}
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "-10"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ $name }}
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "-10"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
rules:
- apiGroups: [operator.cluster.x-k8s.io]
resources: [coreproviders]
resourceNames: [cluster-api]
verbs: [get, patch]
- apiGroups: [operator.cluster.x-k8s.io]
resources: [bootstrapproviders]
resourceNames: [kubeadm]
verbs: [get, patch]
- apiGroups: [apps]
resources: [deployments]
resourceNames: [capi-controller-manager, capi-kubeadm-bootstrap-controller-manager]
verbs: [get]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ $name }}
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "-10"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ $name }}
subjects:
- kind: ServiceAccount
name: {{ $name }}
namespace: {{ .Release.Namespace | quote }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ $name }}
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "0"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
spec:
backoffLimit: 0
activeDeadlineSeconds: {{ add $timeout 60 }}
template:
metadata:
labels:
policy.cozystack.io/allow-to-apiserver: "true"
spec:
serviceAccountName: {{ $name }}
restartPolicy: Never
securityContext:
runAsNonRoot: true
runAsUser: 65532
runAsGroup: 65532
fsGroup: 65532
seccompProfile:
type: RuntimeDefault
containers:
- name: upgrade
image: {{ .Values.upgrade.image | quote }}
command: [bash, /scripts/upgrade-providers.sh]
env:
- name: HOME
value: /tmp
- name: KUBECONFIG
value: /scripts/kubeconfig
- name: KUBE_CONTEXT
value: capi-upgrade
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: BRIDGE_VERSION
value: {{ $bridge | quote }}
- name: TARGET_VERSION
value: {{ .Chart.AppVersion | quote }}
- name: CAPI_UPGRADE_TIMEOUT_SECONDS
value: {{ $timeout | quote }}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
resources:
requests:
cpu: 10m
memory: 64Mi
limits:
cpu: 500m
memory: 256Mi
volumeMounts:
- name: scripts
mountPath: /scripts
readOnly: true
- name: tmp
mountPath: /tmp
volumes:
- name: scripts
configMap:
name: {{ $name }}
- name: tmp
emptyDir: {}
@@ -0,0 +1,2 @@
upgrade:
image: docker.io/alpine/k8s:1.33.4@sha256:b0523f0a244ddc4c8e055aa335c040d3d78b3ead5528f4544395f7f9f69c7b68
@@ -5,9 +5,9 @@ metadata:
spec:
# https://github.com/ionos-cloud/cluster-api-provider-proxmox
#
# Pinned to the v0.7 series: from v0.8 capmox declares the v1beta2 Cluster API
# contract, while the core provider shipped here is v1.10.1, which serves
# v1beta1. Bump this together with capi-providers-core, not on its own.
# Pinned to the v0.7 series: v0.8 moves capmox to its v1alpha2 API, and the
# kubernetes-nodes chart still renders ProxmoxMachineTemplate at v1alpha1.
# Moving past v0.7 means migrating those objects first.
version: v0.7.7-infraprovider-proxmox
configSecret:
name: {{ .Values.credentialsSecretName | quote }}
@@ -8,8 +8,9 @@ spec:
# Who needs this, and why it is not in a KubeVirt install: see the dependsOn
# edge in packages/core/platform/sources/capi-provider-infra-proxmox.yaml.
#
# v1.0.x, not v1.1.0: both serve InClusterIPPool v1alpha2, but the v1.0 series
# declares the v1beta1 contract that matches capi-providers-core v1.10.1.
# 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
fetchConfig:
selector: