mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
fix(capi-providers-core): let a never-installed provider take the fresh path
A provider whose first installation never completed has no status.installedVersion. The hook and the kubeadm chart guard both refused it, so a later chart version that could fix the installation could not be applied without deleting the provider by hand. cluster-api-operator installs such a provider from scratch at whatever version it requests, so it needs no intermediate step: the hook now skips it and the chart guard lets it through. An installed kubeadm provider still requires an installed core provider, because it cannot be moved to the intermediate release without one. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <f@lex.la>
This commit is contained in:
4 files changed
+36
-15
No files matched your search
@@ -193,11 +193,26 @@ accepted_patches() {
|
||||
[ "$(accepted_patches)" = '[]' ]
|
||||
}
|
||||
|
||||
@test "an uninitialised provider is not mistaken for a fresh installation" {
|
||||
@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 provider that never finished installing is left to the final manifests" {
|
||||
fixture 'del(.providers.kubeadm.status.installedVersion)'
|
||||
run bash "$UPGRADE_SCRIPT"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(accepted_patches)" = '[{"name":"cluster-api","version":"v1.13.8-core"}]' ]
|
||||
[ "$(jq --raw-output '.providers.kubeadm.spec.version' "$CAPI_TEST_STATE")" = v1.10.1-bootstrap ]
|
||||
}
|
||||
|
||||
@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" == *"installed version is not recorded"* ]]
|
||||
[[ "$output" == *"kubeadm is installed without an installed core provider"* ]]
|
||||
[ "$(accepted_patches)" = '[]' ]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
{{- 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 -}}
|
||||
{{- $installed := dig "status" "installedVersion" "" ($provider | default dict) -}}
|
||||
{{- if and (kindIs "string" $installed) (ne $installed "") -}}
|
||||
{{- $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)) -}}
|
||||
|
||||
@@ -94,15 +94,18 @@ tests:
|
||||
- isKind:
|
||||
of: BootstrapProvider
|
||||
|
||||
- it: refuses an existing provider without an installed version
|
||||
- it: treats a provider that never finished installing as a fresh installation
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- <<: *legacy
|
||||
status: {}
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: kubeadm
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: "installed version is not recorded"
|
||||
- isKind:
|
||||
of: BootstrapProvider
|
||||
|
||||
- it: refuses a downgrade
|
||||
kubernetesProvider:
|
||||
|
||||
@@ -39,16 +39,23 @@ target_minor="$(minor_version "$TARGET_VERSION")"
|
||||
|
||||
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"
|
||||
# cluster-api-operator installs a provider with no installed version from
|
||||
# scratch at whatever version it requests, so it needs no intermediate step.
|
||||
installed_version() {
|
||||
jq --raw-output '.status.installedVersion // empty' <<< "$1"
|
||||
}
|
||||
if [[ -n "$bootstrap" && -z "$(installed_version "$bootstrap")" ]]; then
|
||||
bootstrap=""
|
||||
fi
|
||||
if [[ -z "$core" || -z "$(installed_version "$core")" ]]; then
|
||||
[[ -z "$bootstrap" ]] || fail "kubeadm is installed without an installed 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"
|
||||
installed="$(installed_version "$object")"
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user