mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
feat(cluster-api)!: update Cluster API to v1.14.4 (#4902)
<!-- Thank you for making a contribution! Here are some tips for you: - Use Conventional Commits for the PR title: `type(scope): description` - Types: feat, fix, security (a fix that comes through a security advisory), docs, style, refactor, perf, test, build, ci, chore - Scopes are not an exhaustive list. Pick the most specific scope for the change. - Breaking changes: append `!` after type/scope or add a `BREAKING CHANGE:` footer. - If it is a work in progress, consider creating this PR as a draft. - Ask for opinion and review in the community chats when needed. - Fixes merged to main reach supported release lines through the backport batch automatically. Do not open backport PRs by hand. --> ## What this PR does Updates the Cluster API stack with an automatic intermediate upgrade for existing v1.10 providers. The core chart upgrades them through v1.13.8 before Helm applies the final manifests. The hook fails on API errors, conflicting changes or timeouts. The hook image goes through cozy-lib. The core chart's PackageSource declares that library, otherwise the packaged chart can't render the hook. Fresh installations skip the intermediate providers. Helm keeps the intermediate ConfigMaps, so they stay in the cluster after the next change of the intermediate version, and that bump has to remove them. Each provider now selects exactly one repository. The bridge and final ConfigMaps carry `provider.cluster.x-k8s.io/version` with the full version, including the role suffix, and the core and kubeadm selectors include it. The operator's finalize step hashes every ConfigMap the selector matches and rejects more than one. During an upgrade it also checks the selector of every other installed provider. So the bridge ConfigMaps carry only the version label, and the v1.10 selectors, which have no version, never match them. The hook switches the version and the selector in one guarded patch and selects a bridge by that label alone. It also narrows an existing bridge selector to that label. A provider whose first installation never finished takes the fresh-install path. Kamaji, CAPK, capmox and IPAM keep their existing pins and temporary v1beta1 compatibility. The autoscaler keeps its explicit v1beta1 selection. An infrastructure provider's v1beta1 `failureReason` no longer immediately fails a Machine or triggers remediation. The provider conditions still show the cause. The vendored operator chart gets six local patches, and `make update` reapplies them. The core components get a startup probe patch. The sync-period patch from main stays. I kept the one-minute resync setting until restart recovery is tested. CAPI Bats, the bootstrap and platform Helm suites and the rendering checks pass locally. On envtest against cluster-api-operator v0.30.0, legacy v1.10 core and kubeadm providers go through v1.13.8 to v1.14.4 with these ConfigMaps. With the old bridge labels core stayed on v1.10. I have not run a live upgrade, restart or eviction test on this revision. The [earlier Proxmox report](https://github.com/cozystack/cozystack/pull/4902#pullrequestreview-5510737333) covers the v1.13 candidate only. ### Screenshots <!-- REQUIRED for UI changes: attach screenshots or screen recordings demonstrating the visual impact of your changes. PRs with UI changes without screenshots will not be merged. --> Not a UI change. ### Downstream repositories <!-- Cozystack is upstream for repositories that are not kept in sync automatically. Check the trigger map in docs/agents/contributing.md against the diff. Keep every checkbox. Tick an affected repository only after linking an existing or newly opened follow-up. Do not claim no downstream impact when it is unknown. --> - [ ] No downstream repository is affected by this change - [x] [cozystack/website](https://github.com/cozystack/website) - follow-up: cozystack/website#751 - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: The existing website follow-up needs the management-cluster minimum updated to v1.33. No tenant API fields, version enums, installer values or platform variants change. ### Release note ```release-note feat(cluster-api)!: update Cluster API core and kubeadm bootstrap to v1.14.4, cluster-api-operator to v0.30.0 and Talos bootstrap to v0.6.13. Legacy core and kubeadm installations are upgraded through v1.13.8 before the final manifests are applied. The core and kubeadm bootstrap charts reject management Kubernetes older than v1.33. The upgrade is one-way: Cluster and Machine CRDs use v1beta2 storage and downgrades are not supported. The preferred Cluster API version becomes v1beta2. Clients relying on v1beta1 fields must select that version explicitly. The operator no longer serves operator.cluster.x-k8s.io/v1alpha1. The autoscaler stays on the v1beta1 Cluster API. ```
This commit is contained in:
71 files changed
+21010
-17385
No files matched your search
@@ -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"
|
||||
}
|
||||
@@ -1,16 +1,20 @@
|
||||
#!/usr/bin/env bats
|
||||
# The operator's resync period is what bounds the stale-Ready window after an
|
||||
# operator restart (kubernetes-sigs/cluster-api-operator#1031): about two
|
||||
# periods. It reaches the manager only through patches/sync-period.diff, which
|
||||
# `make update` has to reapply on every re-vendor, and through the value in
|
||||
# values.yaml. Losing either silently returns the window to about 20 minutes,
|
||||
# so this checks the argument the rendered Deployment actually carries.
|
||||
# values.yaml keeps a one-minute resync period until restart recovery on the
|
||||
# current operator is measured; the v0.19 operator needed it for
|
||||
# kubernetes-sigs/cluster-api-operator#1031. It reaches the manager only through
|
||||
# patches/sync-period.diff, which `make update` has to reapply on every
|
||||
# re-vendor, and through the value in values.yaml. Losing either drops the
|
||||
# setting silently, so this checks the argument the rendered Deployment carries.
|
||||
|
||||
load test_helper
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
|
||||
OPERATOR="$REPO_ROOT/packages/system/capi-operator"
|
||||
|
||||
@test "the operator chart declares its vendored dependencies" {
|
||||
helm lint "$OPERATOR"
|
||||
}
|
||||
|
||||
@test "the operator manager runs with a one-minute resync period" {
|
||||
local rendered args
|
||||
rendered="$BATS_TEST_TMPDIR/operator.yaml"
|
||||
@@ -23,3 +27,473 @@ OPERATOR="$REPO_ROOT/packages/system/capi-operator"
|
||||
esac
|
||||
printf '%s\n' "$args" | grep -qx -- '--sync-period=1m' || { echo "manager args: $args" >&2; return 1; }
|
||||
}
|
||||
|
||||
check_feature_gate() {
|
||||
local expected="$1" mode="$2" group provider legacy kind rendered actual failed=0
|
||||
local -a flags
|
||||
for entry in 'core cluster-api core CoreProvider' \
|
||||
'controlPlane kubeadm kubeadm ControlPlaneProvider' \
|
||||
'infrastructure docker docker InfrastructureProvider' \
|
||||
'ipam in-cluster in-cluster IPAMProvider'; do
|
||||
read -r group provider legacy kind <<< "$entry"
|
||||
flags=(--set "cluster-api-operator.$group.$provider.version=v1.13.7")
|
||||
case "$mode" in
|
||||
global)
|
||||
flags+=(--set "cluster-api-operator.manager.featureGates.$legacy.ClusterTopology=true")
|
||||
;;
|
||||
provider)
|
||||
flags+=(--set "cluster-api-operator.$group.$provider.manager.featureGates.ClusterTopology=true")
|
||||
;;
|
||||
false)
|
||||
flags+=(--set "cluster-api-operator.manager.featureGates.$legacy.ClusterTopology=true"
|
||||
--set "cluster-api-operator.$group.$provider.manager.featureGates.ClusterTopology=false")
|
||||
;;
|
||||
empty)
|
||||
flags+=(--set "cluster-api-operator.manager.featureGates.$legacy.ClusterTopology=true"
|
||||
--set-json "cluster-api-operator.$group.$provider.manager.featureGates={}")
|
||||
;;
|
||||
esac
|
||||
rendered="$BATS_TEST_TMPDIR/$kind.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api "${flags[@]}" > "$rendered"
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.manager.featureGates.ClusterTopology" "$rendered")"
|
||||
[ "$actual" = "$expected" ] || {
|
||||
echo "$kind $mode: expected $expected, got $actual" >&2
|
||||
failed=1
|
||||
}
|
||||
done
|
||||
[ "$failed" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "legacy global feature gates remain effective for provider kinds" {
|
||||
check_feature_gate true global
|
||||
}
|
||||
|
||||
@test "provider feature gates work without a legacy global value" {
|
||||
check_feature_gate true provider
|
||||
}
|
||||
|
||||
@test "an explicit false provider gate overrides the global gate" {
|
||||
check_feature_gate false false
|
||||
}
|
||||
|
||||
@test "an explicitly empty provider gate map replaces global gates" {
|
||||
check_feature_gate null empty
|
||||
}
|
||||
|
||||
check_auto_kubeadm_gate() {
|
||||
local expected="$1" rendered actual
|
||||
shift
|
||||
rendered="$BATS_TEST_TMPDIR/automatic-control-plane.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api \
|
||||
--set cluster-api-operator.infrastructure.docker.version=v1.13.7 \
|
||||
--set cluster-api-operator.configSecret.name=provider-config \
|
||||
"$@" > "$rendered"
|
||||
actual="$(yq --no-doc 'select(.kind == "ControlPlaneProvider") | .spec.manager.featureGates.ClusterTopology' "$rendered")"
|
||||
[ "$actual" = "$expected" ] || {
|
||||
echo "automatic kubeadm gate: expected $expected, got $actual" >&2
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
@test "automatic kubeadm control plane retains the legacy global gate" {
|
||||
check_auto_kubeadm_gate true \
|
||||
--set cluster-api-operator.manager.featureGates.kubeadm.ClusterTopology=true
|
||||
}
|
||||
|
||||
@test "automatic kubeadm control plane does not manufacture a feature gate" {
|
||||
check_auto_kubeadm_gate null
|
||||
}
|
||||
|
||||
@test "explicit kubeadm false gate supersedes automatic global defaults" {
|
||||
check_auto_kubeadm_gate false \
|
||||
--set cluster-api-operator.manager.featureGates.kubeadm.ClusterTopology=true \
|
||||
--set cluster-api-operator.controlPlane.kubeadm.version=v1.13.7 \
|
||||
--set cluster-api-operator.controlPlane.kubeadm.manager.featureGates.ClusterTopology=false
|
||||
}
|
||||
|
||||
@test "explicit kubeadm empty gate map supersedes automatic global defaults" {
|
||||
check_auto_kubeadm_gate null \
|
||||
--set cluster-api-operator.manager.featureGates.kubeadm.ClusterTopology=true \
|
||||
--set cluster-api-operator.controlPlane.kubeadm.version=v1.13.7 \
|
||||
--set-json 'cluster-api-operator.controlPlane.kubeadm.manager.featureGates={}'
|
||||
}
|
||||
|
||||
@test "automatic core and bootstrap keep their existing gate-free defaults" {
|
||||
local rendered actual
|
||||
rendered="$BATS_TEST_TMPDIR/automatic-defaults.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api \
|
||||
--set cluster-api-operator.infrastructure.docker.version=v1.13.7 \
|
||||
--set cluster-api-operator.configSecret.name=provider-config \
|
||||
--set cluster-api-operator.manager.featureGates.core.ClusterTopology=true \
|
||||
--set cluster-api-operator.manager.featureGates.kubeadm.ClusterTopology=true > "$rendered"
|
||||
actual="$(yq --no-doc 'select(.kind == "CoreProvider") | .spec.manager.featureGates' "$rendered")"
|
||||
[ "$actual" = null ]
|
||||
actual="$(yq --no-doc 'select(.kind == "BootstrapProvider") | .spec.manager.featureGates' "$rendered")"
|
||||
[ "$actual" = null ]
|
||||
}
|
||||
|
||||
@test "explicit bootstrap retains its own manager gate" {
|
||||
local rendered actual
|
||||
rendered="$BATS_TEST_TMPDIR/bootstrap.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api \
|
||||
--set cluster-api-operator.bootstrap.kubeadm.version=v1.13.7 \
|
||||
--set cluster-api-operator.bootstrap.kubeadm.manager.featureGates.ClusterTopology=true > "$rendered"
|
||||
actual="$(yq --no-doc 'select(.kind == "BootstrapProvider") | .spec.manager.featureGates.ClusterTopology' "$rendered")"
|
||||
[ "$actual" = true ]
|
||||
}
|
||||
|
||||
@test "addon retains its supported manager metrics without a legacy gate" {
|
||||
local rendered actual
|
||||
rendered="$BATS_TEST_TMPDIR/addon.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api \
|
||||
--set cluster-api-operator.addon.example.version=v1.13.7 \
|
||||
--set cluster-api-operator.addon.example.manager.metrics.diagnosticsAddress=:8443 \
|
||||
--set cluster-api-operator.manager.featureGates.example.ClusterTopology=true > "$rendered"
|
||||
actual="$(yq --no-doc 'select(.kind == "AddonProvider") | .spec.manager.metrics.diagnosticsAddress' "$rendered")"
|
||||
[ "$actual" = ':8443' ]
|
||||
actual="$(yq --no-doc 'select(.kind == "AddonProvider") | .spec.manager.featureGates' "$rendered")"
|
||||
[ "$actual" = null ]
|
||||
}
|
||||
|
||||
check_provider_spec_field() {
|
||||
local field="$1" group provider kind entry rendered actual expected path failed=0
|
||||
local -a flags
|
||||
for entry in 'core cluster-api CoreProvider' 'bootstrap kubeadm BootstrapProvider' \
|
||||
'controlPlane kubeadm ControlPlaneProvider' 'infrastructure docker InfrastructureProvider' \
|
||||
'ipam in-cluster IPAMProvider' 'addon example AddonProvider'; do
|
||||
read -r group provider kind <<< "$entry"
|
||||
flags=(--set "cluster-api-operator.$group.$provider.createNamespace=false")
|
||||
case "$field" in
|
||||
fetchConfig)
|
||||
flags+=(--set-string "cluster-api-operator.$group.$provider.fetchConfig.selector.matchLabels.example=manifests")
|
||||
path='.spec.fetchConfig.selector.matchLabels.example'
|
||||
expected=manifests
|
||||
;;
|
||||
manifestPatches)
|
||||
flags+=(--set-json "cluster-api-operator.$group.$provider.manifestPatches=[\"kind: Deployment\"]")
|
||||
path='.spec.manifestPatches[0]'
|
||||
expected='kind: Deployment'
|
||||
;;
|
||||
additionalManifests)
|
||||
flags+=(--set-json "cluster-api-operator.$group.$provider.additionalManifests={\"name\":\"extra-manifests\",\"manifests\":\"kind: ConfigMap\"}")
|
||||
path='.spec.additionalManifests.name'
|
||||
expected=extra-manifests
|
||||
;;
|
||||
absent)
|
||||
path='.spec'
|
||||
expected=null
|
||||
;;
|
||||
esac
|
||||
rendered="$BATS_TEST_TMPDIR/$kind-$field.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api "${flags[@]}" > "$rendered"
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | $path" "$rendered")"
|
||||
[ "$actual" = "$expected" ] || {
|
||||
echo "$kind $field: expected $expected in spec, got $actual" >&2
|
||||
failed=1
|
||||
}
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .metadata.$field" "$rendered")"
|
||||
[ "$actual" = null ] || {
|
||||
echo "$kind leaked $field into metadata" >&2
|
||||
failed=1
|
||||
}
|
||||
done
|
||||
[ "$failed" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "fetch configuration alone belongs to every provider spec" {
|
||||
check_provider_spec_field fetchConfig
|
||||
}
|
||||
|
||||
@test "manifest patches alone belong to every provider spec" {
|
||||
check_provider_spec_field manifestPatches
|
||||
}
|
||||
|
||||
@test "additional manifests alone belong to every provider spec" {
|
||||
check_provider_spec_field additionalManifests
|
||||
}
|
||||
|
||||
@test "provider namespace options alone do not manufacture spec fields" {
|
||||
check_provider_spec_field absent
|
||||
}
|
||||
|
||||
@test "legacy global fetch configuration alone stays inside matching provider specs" {
|
||||
local group provider kind entry rendered actual
|
||||
for entry in 'infrastructure docker InfrastructureProvider' 'ipam in-cluster IPAMProvider'; do
|
||||
read -r group provider kind <<< "$entry"
|
||||
rendered="$BATS_TEST_TMPDIR/$kind-global-fetch.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api \
|
||||
--set "cluster-api-operator.$group.$provider.createNamespace=false" \
|
||||
--set-string "cluster-api-operator.fetchConfig.$provider.url=https://example.test/components.yaml" > "$rendered"
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.fetchConfig.url" "$rendered")"
|
||||
[ "$actual" = 'https://example.test/components.yaml' ]
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .metadata.fetchConfig" "$rendered")"
|
||||
[ "$actual" = null ]
|
||||
done
|
||||
}
|
||||
|
||||
@test "another provider's global fetch configuration does not create a spec" {
|
||||
local rendered actual
|
||||
rendered="$BATS_TEST_TMPDIR/unmatched-fetch.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api \
|
||||
--set cluster-api-operator.infrastructure.docker.createNamespace=false \
|
||||
--set-string cluster-api-operator.fetchConfig.other.url=https://example.test/components.yaml > "$rendered"
|
||||
actual="$(yq --no-doc 'select(.kind == "InfrastructureProvider") | .spec' "$rendered")"
|
||||
[ "$actual" = null ]
|
||||
}
|
||||
|
||||
@test "infrastructure patches alone belong to the provider spec" {
|
||||
local rendered actual
|
||||
rendered="$BATS_TEST_TMPDIR/infrastructure-patches.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api \
|
||||
--set-string 'cluster-api-operator.infrastructure.docker.patches[0].patch=kind: Deployment' > "$rendered"
|
||||
actual="$(yq --no-doc 'select(.kind == "InfrastructureProvider") | .spec.patches[0].patch' "$rendered")"
|
||||
[ "$actual" = 'kind: Deployment' ]
|
||||
actual="$(yq --no-doc 'select(.kind == "InfrastructureProvider") | .metadata.patches' "$rendered")"
|
||||
[ "$actual" = null ]
|
||||
}
|
||||
|
||||
check_fetch_overlap() {
|
||||
local mode="$1" group provider kind template entry rendered actual expected failed=0
|
||||
local -a flags
|
||||
for entry in 'infrastructure docker InfrastructureProvider infra.yaml' \
|
||||
'ipam in-cluster IPAMProvider ipam.yaml'; do
|
||||
read -r group provider kind template <<< "$entry"
|
||||
flags=(--set "cluster-api-operator.$group.$provider.createNamespace=false"
|
||||
--set-string "cluster-api-operator.fetchConfig.$provider.url=https://legacy.example/components.yaml")
|
||||
case "$mode" in
|
||||
override)
|
||||
flags+=(--set-string "cluster-api-operator.$group.$provider.fetchConfig.url=https://provider.example/components.yaml")
|
||||
expected=https://provider.example/components.yaml
|
||||
;;
|
||||
empty)
|
||||
flags+=(--set-json "cluster-api-operator.$group.$provider.fetchConfig={}")
|
||||
expected=https://legacy.example/components.yaml
|
||||
;;
|
||||
esac
|
||||
rendered="$BATS_TEST_TMPDIR/$kind-overlap-$mode.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api "${flags[@]}" \
|
||||
--show-only "charts/cluster-api-operator/templates/$template" > "$rendered"
|
||||
[ "$(grep -c '^ fetchConfig:' "$rendered")" -eq 1 ] || {
|
||||
echo "$kind $mode must emit exactly one fetchConfig key" >&2
|
||||
failed=1
|
||||
}
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.fetchConfig.url" "$rendered")"
|
||||
[ "$actual" = "$expected" ] || {
|
||||
echo "$kind $mode expected $expected, got $actual" >&2
|
||||
failed=1
|
||||
}
|
||||
done
|
||||
[ "$failed" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "nonempty provider fetch configuration overrides global input with one key" {
|
||||
check_fetch_overlap override
|
||||
}
|
||||
|
||||
@test "empty provider fetch configuration retains the legacy global fallback" {
|
||||
check_fetch_overlap empty
|
||||
}
|
||||
|
||||
check_profiling_flags() {
|
||||
local rendered
|
||||
rendered="$BATS_TEST_TMPDIR/profiling.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api \
|
||||
--set cluster-api-operator.profilerAddress=:6061 \
|
||||
--set cluster-api-operator.contentionProfiling=true "$@" > "$rendered"
|
||||
grep -q -- '--profiler-address=localhost:6061' "$rendered"
|
||||
grep -q -- '--contention-profiling=true' "$rendered"
|
||||
grep -q '^[[:space:]]*- containerPort: 6061$' "$rendered"
|
||||
}
|
||||
|
||||
@test "profiling flags remain effective when leader election is disabled" {
|
||||
check_profiling_flags --set cluster-api-operator.leaderElection.enabled=false
|
||||
}
|
||||
|
||||
@test "profiling flags remain effective when the optional leader election block is absent" {
|
||||
check_profiling_flags --set-json cluster-api-operator.leaderElection=null
|
||||
}
|
||||
|
||||
check_global_fetch_type() {
|
||||
local mode="$1" group provider kind template entry rendered actual failed=0
|
||||
local -a flags
|
||||
for entry in 'infrastructure docker InfrastructureProvider infra.yaml' \
|
||||
'ipam in-cluster IPAMProvider ipam.yaml'; do
|
||||
read -r group provider kind template <<< "$entry"
|
||||
flags=(--set "cluster-api-operator.$group.$provider.createNamespace=false")
|
||||
case "$mode" in
|
||||
selector)
|
||||
flags+=(--set-json "cluster-api-operator.fetchConfig.$provider.selector={\"matchLabels\":{\"example\":\"manifests\"},\"matchExpressions\":[{\"key\":\"release\",\"operator\":\"In\",\"values\":[\"v1\"]}]}")
|
||||
;;
|
||||
empty)
|
||||
flags+=(--set-json "cluster-api-operator.fetchConfig.$provider.selector={}")
|
||||
;;
|
||||
oci)
|
||||
flags+=(--set-string "cluster-api-operator.fetchConfig.$provider.oci=oci://registry.example/provider:v1")
|
||||
;;
|
||||
esac
|
||||
rendered="$BATS_TEST_TMPDIR/$kind-fetch-type-$mode.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api "${flags[@]}" \
|
||||
--show-only "charts/cluster-api-operator/templates/$template" > "$rendered"
|
||||
[ "$(grep -c '^ fetchConfig:' "$rendered")" -eq 1 ]
|
||||
if [ "$mode" = oci ]; then
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.fetchConfig.oci" "$rendered")"
|
||||
[ "$actual" = 'oci://registry.example/provider:v1' ]
|
||||
continue
|
||||
fi
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.fetchConfig.selector | tag" "$rendered")"
|
||||
if [ "$actual" != '!!map' ]; then
|
||||
echo "$kind $mode selector must be an object, got $actual" >&2
|
||||
failed=1
|
||||
continue
|
||||
fi
|
||||
if [ "$mode" = selector ]; then
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.fetchConfig.selector.matchLabels.example" "$rendered")"
|
||||
[ "$actual" = manifests ]
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.fetchConfig.selector.matchExpressions[0].key" "$rendered")"
|
||||
[ "$actual" = release ]
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.fetchConfig.selector.matchExpressions[0].operator" "$rendered")"
|
||||
[ "$actual" = In ]
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.fetchConfig.selector.matchExpressions[0].values[0]" "$rendered")"
|
||||
[ "$actual" = v1 ]
|
||||
fi
|
||||
done
|
||||
[ "$failed" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "global fetch selectors preserve nested label and expression objects" {
|
||||
check_global_fetch_type selector
|
||||
}
|
||||
|
||||
@test "empty global fetch selectors remain objects rather than strings" {
|
||||
check_global_fetch_type empty
|
||||
}
|
||||
|
||||
@test "global OCI fetch configuration remains a string source" {
|
||||
check_global_fetch_type oci
|
||||
}
|
||||
|
||||
check_global_fetch_entry() {
|
||||
local value="$1" expected="$2" group provider kind template entry rendered actual failed=0
|
||||
for entry in 'infrastructure docker InfrastructureProvider infra.yaml' \
|
||||
'ipam in-cluster IPAMProvider ipam.yaml'; do
|
||||
read -r group provider kind template <<< "$entry"
|
||||
rendered="$BATS_TEST_TMPDIR/$kind-entry.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api \
|
||||
--set "cluster-api-operator.$group.$provider.version=v1.13.7" \
|
||||
--set-json "cluster-api-operator.fetchConfig.$provider=$value" \
|
||||
--show-only "charts/cluster-api-operator/templates/$template" > "$rendered"
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.fetchConfig | tag" "$rendered")"
|
||||
[ "$actual" = "$expected" ] || {
|
||||
echo "$kind global entry $value: expected $expected, got $actual" >&2
|
||||
failed=1
|
||||
}
|
||||
done
|
||||
[ "$failed" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "empty global fetch entries preserve default source selection" {
|
||||
check_global_fetch_entry '{}' '!!null'
|
||||
}
|
||||
|
||||
@test "null global fetch entries preserve default source selection" {
|
||||
check_global_fetch_entry null '!!null'
|
||||
}
|
||||
|
||||
@test "malformed global fetch primitives are not silently replaced by a default source" {
|
||||
check_global_fetch_entry false '!!bool'
|
||||
check_global_fetch_entry 0 '!!int'
|
||||
check_global_fetch_entry '"invalid"' '!!str'
|
||||
check_global_fetch_entry '[]' '!!seq'
|
||||
}
|
||||
|
||||
check_provider_scalar_types() {
|
||||
local mode="$1" metrics="$2" name="$3" namespace="$4" expected="$5"
|
||||
local group provider kind entry rendered path actual failed=0
|
||||
local -a flags
|
||||
for entry in 'core cluster-api CoreProvider' 'bootstrap kubeadm BootstrapProvider' \
|
||||
'controlPlane kubeadm ControlPlaneProvider' 'infrastructure docker InfrastructureProvider' \
|
||||
'ipam in-cluster IPAMProvider' 'addon example AddonProvider'; do
|
||||
read -r group provider kind <<< "$entry"
|
||||
flags=("--set-$mode" "cluster-api-operator.$group.$provider.manager.metrics.diagnosticsAddress=$metrics"
|
||||
"--set-$mode" "cluster-api-operator.$group.$provider.configSecret.name=$name"
|
||||
"--set-$mode" "cluster-api-operator.$group.$provider.configSecret.namespace=$namespace")
|
||||
rendered="$BATS_TEST_TMPDIR/$kind-scalars-$mode.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api "${flags[@]}" > "$rendered"
|
||||
for path in manager.metrics.diagnosticsAddress configSecret.name configSecret.namespace; do
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.$path | tag" "$rendered")"
|
||||
[ "$actual" = "$expected" ] || {
|
||||
echo "$kind $path: expected YAML type $expected, got $actual" >&2
|
||||
failed=1
|
||||
}
|
||||
done
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.manager.metrics.diagnosticsAddress" "$rendered")"
|
||||
[ "$actual" = "$metrics" ]
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.configSecret.name" "$rendered")"
|
||||
[ "$actual" = "$name" ]
|
||||
actual="$(yq --no-doc "select(.kind == \"$kind\") | .spec.configSecret.namespace" "$rendered")"
|
||||
[ "$actual" = "$namespace" ]
|
||||
done
|
||||
[ "$failed" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "provider metric disable values and numeric secret identifiers stay strings" {
|
||||
check_provider_scalar_types string 0 123 456 '!!str'
|
||||
}
|
||||
|
||||
@test "provider secret identifiers that resemble YAML keywords stay strings" {
|
||||
check_provider_scalar_types string 0 true null '!!str'
|
||||
}
|
||||
|
||||
@test "invalid numeric provider string inputs are not coerced into valid strings" {
|
||||
check_provider_scalar_types json 123 123 456 '!!int'
|
||||
}
|
||||
|
||||
@test "invalid boolean provider string inputs are not coerced into valid strings" {
|
||||
check_provider_scalar_types json true true true '!!bool'
|
||||
}
|
||||
|
||||
@test "provider config Secrets override global defaults" {
|
||||
local group provider kind rendered entry
|
||||
for entry in 'core cluster-api CoreProvider' 'bootstrap kubeadm BootstrapProvider' \
|
||||
'controlPlane kubeadm ControlPlaneProvider' 'infrastructure docker InfrastructureProvider' \
|
||||
'ipam in-cluster IPAMProvider' 'addon example AddonProvider'; do
|
||||
read -r group provider kind <<< "$entry"
|
||||
rendered="$BATS_TEST_TMPDIR/$kind-secret-precedence.yaml"
|
||||
helm template capi-operator "$OPERATOR" \
|
||||
--set cluster-api-operator.configSecret.name=global-config \
|
||||
--set cluster-api-operator.configSecret.namespace=global-namespace \
|
||||
--set "cluster-api-operator.$group.$provider.configSecret.name=provider-config" \
|
||||
--set "cluster-api-operator.$group.$provider.configSecret.namespace=provider-namespace" > "$rendered"
|
||||
[ "$(yq --no-doc "select(.kind == \"$kind\") | .spec.configSecret.name" "$rendered")" = provider-config ]
|
||||
[ "$(yq --no-doc "select(.kind == \"$kind\") | .spec.configSecret.namespace" "$rendered")" = provider-namespace ]
|
||||
done
|
||||
}
|
||||
|
||||
@test "operator profiling preserves an explicit host address" {
|
||||
local rendered="$BATS_TEST_TMPDIR/profiler-host.yaml"
|
||||
helm template capi-operator "$OPERATOR" \
|
||||
--set cluster-api-operator.profilerAddress=127.0.0.1:6061 > "$rendered"
|
||||
grep --quiet --fixed-strings -- '--profiler-address=127.0.0.1:6061' "$rendered"
|
||||
}
|
||||
|
||||
@test "operator ports retain port-only addresses" {
|
||||
local rendered
|
||||
rendered="$BATS_TEST_TMPDIR/operator.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api \
|
||||
--set cluster-api-operator.healthAddr=:9440 \
|
||||
--set cluster-api-operator.diagnosticsAddress=:8443 > "$rendered"
|
||||
[ "$(grep -c '^[[:space:]]*port: 9440$' "$rendered")" -eq 2 ]
|
||||
grep -q '^[[:space:]]*- containerPort: 8443$' "$rendered"
|
||||
}
|
||||
|
||||
@test "operator ports preserve explicit IPv4 host addresses" {
|
||||
local rendered
|
||||
rendered="$BATS_TEST_TMPDIR/operator.yaml"
|
||||
helm template capi-operator "$OPERATOR" --namespace cozy-cluster-api \
|
||||
--set cluster-api-operator.healthAddr=0.0.0.0:9440 \
|
||||
--set cluster-api-operator.diagnosticsAddress=0.0.0.0:8443 > "$rendered"
|
||||
[ "$(grep -c '^[[:space:]]*port: 9440$' "$rendered")" -eq 2 ]
|
||||
grep -q '^[[:space:]]*- containerPort: 8443$' "$rendered"
|
||||
grep -q -- '--health-addr=0.0.0.0:9440' "$rendered"
|
||||
grep -q -- '--diagnostics-address=0.0.0.0:8443' "$rendered"
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
#!/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 upgrade Job is kept until the next attempt, after a success too" {
|
||||
[ "$(yq --no-doc 'select(.kind == "Job") | .metadata.annotations."helm.sh/hook-delete-policy"' "$RENDERED")" = before-hook-creation ]
|
||||
[ "$(yq --no-doc 'select(.kind != "Job" and .metadata.annotations."helm.sh/hook" != null) | .metadata.annotations."helm.sh/hook-delete-policy"' "$RENDERED" | sort --unique)" = before-hook-creation,hook-succeeded ]
|
||||
}
|
||||
|
||||
@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 "intermediate bundles carry no label a legacy version-less selector matches" {
|
||||
local rendered="$BATS_TEST_TMPDIR/operator.yaml"
|
||||
helm template capi-operator "$REPO_ROOT/packages/system/capi-operator" --namespace test-capi > "$rendered"
|
||||
yq --output-format=json --no-doc 'select(.kind == "ConfigMap" and .metadata.annotations."helm.sh/resource-policy" == "keep")' "$rendered" |
|
||||
jq --slurp --exit-status 'length == 2 and all(.[]; .metadata.labels == {"provider.cluster.x-k8s.io/version": .metadata.name})'
|
||||
}
|
||||
|
||||
@test "the hook image follows the cluster images registry" {
|
||||
local image mirrored
|
||||
image="$(yq --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].image' "$RENDERED")"
|
||||
[ "$image" = "$(yq '.upgrade.image' "$CORE/values.yaml")" ]
|
||||
mirrored="$(helm template capi-providers-core "$CORE" --namespace test-capi --kube-version 1.33.0 --set-string '_cluster.images-registry=registry.example.test' |
|
||||
yq --no-doc 'select(.kind == "Job") | .spec.template.spec.containers[0].image')"
|
||||
[ "$mirrored" = "registry.example.test/$image" ]
|
||||
}
|
||||
|
||||
@test "the packaged chart ships the cozy-lib subchart its templates include" {
|
||||
local source="$REPO_ROOT/packages/core/platform/sources/capi-provider-core.yaml"
|
||||
[ "$(yq '.spec.variants[] | select(.name == "default") | .libraries[] | select(.name == "cozy-lib") | .path' "$source")" = library/cozy-lib ]
|
||||
[ "$(yq '.spec.variants[] | select(.name == "default") | .components[] | select(.name == "capi-providers-core") | .libraries[] | select(. == "cozy-lib")' "$source")" = cozy-lib ]
|
||||
}
|
||||
|
||||
@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"
|
||||
}
|
||||
@@ -0,0 +1,400 @@
|
||||
#!/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 --argjson bridge "$(rendered_configmaps capi-operator templates/upgrade-bundles.yaml)" '
|
||||
def provider($name; $suffix): {
|
||||
metadata: {name: $name, uid: $name, generation: 1},
|
||||
spec: {version: ("v1.10.1-" + $suffix), fetchConfig: {selector: {matchLabels: ({($suffix + "-components"): "cozy"} + if $suffix == "bootstrap" then {"bootstrap-provider": "kubeadm"} else {} end)}}},
|
||||
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},
|
||||
configmaps: ([
|
||||
{name: "v1.10.1-core", labels: {"core-components": "cozy"}},
|
||||
{name: "v1.10.1-bootstrap", labels: {"bootstrap-components": "cozy", "bootstrap-provider": "kubeadm"}}
|
||||
] + $bridge)
|
||||
}' > "$CAPI_TEST_STATE"
|
||||
}
|
||||
|
||||
rendered_configmaps() {
|
||||
helm template "$1" "$REPO_ROOT/packages/system/$1" --namespace test-capi --kube-version 1.33.0 --show-only "$2" |
|
||||
yq --output-format=json --no-doc 'select(.kind == "ConfigMap") | {"name": .metadata.name, "labels": .metadata.labels}' |
|
||||
jq --slurp --compact-output '.'
|
||||
}
|
||||
|
||||
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 ".configmaps += $(rendered_configmaps capi-providers-core templates/configmaps.yaml)"
|
||||
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 "a core upgrade stalls while another installed provider selects two repositories" {
|
||||
fixture '.configmaps += [{name: "v1.10.2-bootstrap", labels: {"bootstrap-components": "cozy", "bootstrap-provider": "kubeadm"}}]'
|
||||
export CAPI_TEST_CLOCK_JUMP=61
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" == *"cluster-api timed out"* ]]
|
||||
[ "$(accepted_patches)" = '[{"name":"cluster-api","version":"v1.13.8-core"}]' ]
|
||||
}
|
||||
|
||||
@test "the live legacy kubeadm selector matches only its own repository during the core step" {
|
||||
jq --exit-status '.providers.kubeadm.spec.fetchConfig.selector.matchLabels as $s |
|
||||
[.configmaps[] | select(.labels as $l | $s | to_entries | all(.[]; $l[.key] == .value))] | map(.name) == ["v1.10.1-bootstrap"]' "$CAPI_TEST_STATE"
|
||||
}
|
||||
|
||||
@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 "providers that never finished installing take the fresh installation path" {
|
||||
fixture 'del(.providers[].status.installedVersion)'
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(accepted_patches)" = '[]' ]
|
||||
}
|
||||
|
||||
@test "a kubeadm installation completing during the core upgrade is staged to the bridge" {
|
||||
fixture '.bootstrapAfterCore = .providers.kubeadm | del(.providers.kubeadm.status.installedVersion)'
|
||||
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 "an unfinished kubeadm installation at an old requested version is staged to the bridge" {
|
||||
fixture 'del(.providers.kubeadm.status.installedVersion)'
|
||||
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 "an unfinished kubeadm target request does not wait for the final bootstrap chart" {
|
||||
fixture 'del(.providers.kubeadm.status.installedVersion) | .providers.kubeadm.spec.version = "v1.14.4-bootstrap" | .providers.kubeadm.spec.fetchConfig.selector.matchLabels = {"provider.cluster.x-k8s.io/version": "v1.14.4-bootstrap"}'
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(accepted_patches)" = '[{"name":"cluster-api","version":"v1.13.8-core"}]' ]
|
||||
jq --exit-status '.providers.kubeadm | .spec.version == "v1.14.4-bootstrap" and (.status | has("installedVersion") | not)' "$CAPI_TEST_STATE"
|
||||
}
|
||||
|
||||
@test "an unfinished kubeadm request within the upgrade window is left to the final manifests" {
|
||||
fixture 'del(.providers.kubeadm.status.installedVersion) | .providers.kubeadm.spec.version = "v1.13.7-bootstrap"'
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(accepted_patches)" = '[{"name":"cluster-api","version":"v1.13.8-core"}]' ]
|
||||
jq --exit-status '.providers.kubeadm | .spec.version == "v1.13.7-bootstrap" and (.status | has("installedVersion") | not)' "$CAPI_TEST_STATE"
|
||||
}
|
||||
|
||||
@test "an unfinished kubeadm installation with a malformed request is rejected" {
|
||||
fixture 'del(.providers.kubeadm.status.installedVersion) | .providers.kubeadm.spec.version = "invalid"'
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" == *"invalid requested version: invalid"* ]]
|
||||
[ "$(accepted_patches)" = '[]' ]
|
||||
}
|
||||
|
||||
@test "an unfinished kubeadm installation with no requested version is rejected" {
|
||||
fixture 'del(.providers.kubeadm.status.installedVersion, .providers.kubeadm.spec.version)'
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" == *"invalid requested version:"* ]]
|
||||
[ "$(accepted_patches)" = '[]' ]
|
||||
}
|
||||
|
||||
@test "a kubeadm replacement during the core upgrade is not adopted" {
|
||||
fixture '.bootstrapAfterCore = (.providers.kubeadm | .metadata.uid = "replacement") | del(.providers.kubeadm.status.installedVersion)'
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" == *"kubeadm was replaced during the upgrade"* ]]
|
||||
[ "$(accepted_patches)" = '[{"name":"cluster-api","version":"v1.13.8-core"}]' ]
|
||||
}
|
||||
|
||||
@test "a kubeadm version installed during the core upgrade is revalidated" {
|
||||
fixture '.bootstrapAfterCore = (.providers.kubeadm | .status.installedVersion = "v1.14.5-bootstrap") | del(.providers.kubeadm.status.installedVersion)'
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" == *"bootstrap provider downgrades are not supported"* ]]
|
||||
[ "$(accepted_patches)" = '[{"name":"cluster-api","version":"v1.13.8-core"}]' ]
|
||||
}
|
||||
|
||||
@test "an installed kubeadm without an installed core provider is refused" {
|
||||
fixture 'del(.providers["cluster-api"].status.installedVersion)'
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" == *"kubeadm is installed without an installed core provider"* ]]
|
||||
[ "$(accepted_patches)" = '[]' ]
|
||||
}
|
||||
|
||||
@test "a malformed requested version is reported as the requested one" {
|
||||
fixture '.providers["cluster-api"].spec.version = "invalid"'
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" == *"invalid requested version: invalid"* ]]
|
||||
[ "$(accepted_patches)" = '[]' ]
|
||||
}
|
||||
|
||||
@test "a malformed target release is not reported as an installed version" {
|
||||
export TARGET_VERSION=invalid
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" == *"invalid target version: invalid"* ]]
|
||||
[ "$(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 "a bridge selector that keeps legacy labels is narrowed to the version label" {
|
||||
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 ]
|
||||
jq --exit-status 'all(.providers[]; .spec.fetchConfig.selector.matchLabels == {"provider.cluster.x-k8s.io/version": .spec.version})' "$CAPI_TEST_STATE"
|
||||
}
|
||||
|
||||
@test "a bridge selector with extra expressions is narrowed to the version label" {
|
||||
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}, matchExpressions: [{key: "core-components", operator: "Exists"}]})'
|
||||
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"
|
||||
}
|
||||
@@ -6407,7 +6407,10 @@ EOF
|
||||
fi
|
||||
|
||||
# Wait for all machine deployment replicas to be ready (timeout after 10 minutes)
|
||||
kubectl wait machinedeployment kubernetes-${test_name}-md0 -n tenant-test --timeout=10m --for=jsonpath='{.status.v1beta2.readyReplicas}'=2
|
||||
# Named at v1beta1: status.v1beta2.readyReplicas exists only there, and a bare
|
||||
# resource name follows whichever version the cluster prefers, which is
|
||||
# v1beta2 from Cluster API v1.11. v1beta1 is served until v1.16.
|
||||
kubectl wait machinedeployments.v1beta1.cluster.x-k8s.io kubernetes-${test_name}-md0 -n tenant-test --timeout=10m --for=jsonpath='{.status.v1beta2.readyReplicas}'=2
|
||||
|
||||
for component in cilium coredns csi vsnap-crd; do
|
||||
kubectl wait hr "kubernetes-${test_name}-${component}" -n tenant-test --timeout=5m --for=condition=ready
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
sleep() {
|
||||
if [[ -n "${CAPI_TEST_CLOCK_JUMP:-}" ]]; then
|
||||
SECONDS=$((SECONDS + CAPI_TEST_CLOCK_JUMP))
|
||||
else
|
||||
command sleep "$@"
|
||||
fi
|
||||
}
|
||||
Vendored
+154
@@ -0,0 +1,154 @@
|
||||
#!/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 selected(selector):
|
||||
return [cm for cm in state.get("configmaps", []) if all(cm["labels"].get(k) == v for k, v in selector.items())]
|
||||
|
||||
|
||||
def repository_ready(name, obj):
|
||||
own = selected(obj["spec"].get("fetchConfig", {}).get("selector", {}).get("matchLabels", {}))
|
||||
if len(own) != 1 or own[0]["labels"].get("provider.cluster.x-k8s.io/version", own[0]["name"]) != obj["spec"]["version"]:
|
||||
return False
|
||||
# A version change makes cluster-api-operator resolve the repository of every
|
||||
# other installed provider, refusing a selector that matches more than one ConfigMap.
|
||||
return obj["status"].get("installedVersion") == obj["spec"]["version"] or all(
|
||||
len(selected(other["spec"].get("fetchConfig", {}).get("selector", {}).get("matchLabels", {}))) == 1
|
||||
for other_name, other in state["providers"].items()
|
||||
if other_name != name and other["status"].get("installedVersion")
|
||||
)
|
||||
|
||||
|
||||
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 repository_ready(name, obj):
|
||||
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]
|
||||
if name == "capi-controller-manager" and "bootstrapAfterCore" in state and obj["status"]["readyReplicas"] == 1:
|
||||
state["providers"]["kubeadm"] = state.pop("bootstrapAfterCore")
|
||||
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")
|
||||
Reference in new issue
Block a user