diff --git a/packages/core/platform/templates/_helpers.tpl b/packages/core/platform/templates/_helpers.tpl index 289cfbccb..8d7c43d64 100644 --- a/packages/core/platform/templates/_helpers.tpl +++ b/packages/core/platform/templates/_helpers.tpl @@ -73,7 +73,7 @@ nothing: helm template, client-side dry-run, first install. {{- $ack = dig "acknowledgeBackendChange" "" .Values.storage | toString -}} {{- end -}} {{- if and (ne $liveBackend $backend) (ne $ack $backend) -}} -{{- fail (printf "the live cozystack.linstor Package runs the %q storage backend and this render would switch it to %q. The volumes this cluster already has are known only to the current backend: after the switch the CSI driver cannot attach, resize, snapshot or delete them. Restore storage.backend: %q, or, if the cluster holds no volumes, set storage.acknowledgeBackendChange: %q to confirm this exact switch." $liveBackend $backend $liveBackend $backend) -}} +{{- fail (printf "the live cozystack.linstor Package runs the %q storage backend and this render would switch it to %q. The volumes this cluster already has are known only to the current backend: after the switch the CSI driver cannot attach, resize, snapshot or delete them. Restore storage.backend: %q, or set storage.acknowledgeBackendChange: %q to confirm this exact switch. On a cluster that holds no volumes that is enough. A cluster with LINSTOR volumes moves to blockstor only together with storage.blockstorMigration: hold, in the order packages/system/linstor/README.md gives." $liveBackend $backend $liveBackend $backend) -}} {{- end -}} {{- end -}} {{- end }} @@ -273,10 +273,12 @@ cozystack-scheduler (emitted with its own variant in both branches) LinstorCluster the linstor package renders, the object that points linstor-csi there too, so the names of blockstor's Service and Secret stay in that package alone. Under linstor they get nothing and keep - their own defaults, linstor-controller and linstor-client-tls. The - backend is passed rather than left to the lookup alone so that a - switch changes their values and Helm renders them again. */ -}} -{{- if eq (include "cozystack.platform.storage.backend" $root) "blockstor" }} + their own defaults, linstor-controller and linstor-client-tls, and so + they do while a blockstorMigration is in progress (see + blockstorServesApi). The backend is passed rather than left to the + lookup alone so that a switch changes their values and Helm renders + them again. */ -}} +{{- if include "cozystack.platform.storage.blockstorServesApi" $root }} {{- $schedulerComponents := dict "linstor-scheduler" (dict "values" (dict "linstor-scheduler" (dict "linstor" (dict "backend" "blockstor")))) -}} {{include "cozystack.platform.package" (list "cozystack.linstor-scheduler" "default" $root $schedulerComponents) }} {{- else }} @@ -296,6 +298,25 @@ cozystack-scheduler (emitted with its own variant in both branches) {{- end }} {{- end }} +{{- /* +The migration step for the linstor package, empty when none is in progress. +Checked here as well as in the linstor chart, so a typo fails the platform +render instead of leaving the cozystack.linstor HelmRelease failing. +*/ -}} +{{- define "cozystack.platform.storage.blockstorMigration" -}} +{{- $migration := "" -}} +{{- if and (kindIs "map" .Values.storage) (hasKey .Values.storage "blockstorMigration") -}} +{{- $migration = .Values.storage.blockstorMigration -}} +{{- end -}} +{{- if not (and (kindIs "string" $migration) (has $migration (list "" "hold" "adopt"))) -}} +{{- fail (printf "storage.blockstorMigration must be \"\", \"hold\" or \"adopt\", got %#v" $migration) -}} +{{- end -}} +{{- if and $migration (ne (include "cozystack.platform.storage.backend" .) "blockstor") -}} +{{- fail (printf "storage.blockstorMigration %q is only valid with storage.backend: blockstor; remove it together with switching the backend back" $migration) -}} +{{- end -}} +{{- $migration -}} +{{- end -}} + {{- /* Resolve the storage backend for the linstor package. @@ -323,6 +344,23 @@ before rendering, so it reads as absent. {{- $backend -}} {{- end -}} +{{- /* +Whether the LINSTOR API consumers outside the linstor package are told the +blockstor backend, and so follow the LinstorCluster to blockstor-apiserver: +backend blockstor once blockstorMigration is cleared, the same step in which +piraeus-operator repoints linstor-csi there. Until then LINSTOR's state is the +one CSI acts on, while blockstor-apiserver serves nothing (hold, before the +converted manifests are in) or Resources it has not adopted yet, with no +volume state. linstor-scheduler reads a replica's disk state from the first +volume of every Resource of a pod's volume, and on a Resource without volumes +it panics rather than answering. Left on the stopped linstor-controller, it +fails a scheduling attempt instead, the pod stays Pending and is retried, and +nothing is placed on what blockstor half knows. +*/ -}} +{{- define "cozystack.platform.storage.blockstorServesApi" -}} +{{- if and (eq (include "cozystack.platform.storage.backend" .) "blockstor") (not (include "cozystack.platform.storage.blockstorMigration" .)) }}true{{ end -}} +{{- end -}} + {{/* The block Cilium takes its own addresses from on the kube-ovn variants, the last /21 of the pod CIDR, which kube-ovn is told to exclude. Called with the diff --git a/packages/core/platform/templates/bundles/system.yaml b/packages/core/platform/templates/bundles/system.yaml index 8636368da..b63787426 100644 --- a/packages/core/platform/templates/bundles/system.yaml +++ b/packages/core/platform/templates/bundles/system.yaml @@ -138,9 +138,12 @@ {{include "cozystack.platform.package.full" (list "cozystack.multus" "default" $ $multusComponents) }} {{- end }} {{- if eq (include "cozystack.platform.storage.backend" $) "blockstor" }} -{{- $linstorComponents := dict "linstor" (dict "values" (dict "backend" "blockstor")) -}} +{{- $linstorValues := dict "backend" "blockstor" -}} +{{- with include "cozystack.platform.storage.blockstorMigration" $ }}{{ $_ := set $linstorValues "blockstorMigration" . }}{{ end -}} +{{- $linstorComponents := dict "linstor" (dict "values" $linstorValues) -}} {{include "cozystack.platform.package" (list "cozystack.linstor" "default" $ $linstorComponents) }} {{- else }} +{{- $_ := include "cozystack.platform.storage.blockstorMigration" $ }} {{include "cozystack.platform.package.default" (list "cozystack.linstor" $) }} {{- end }} {{include "cozystack.platform.package" (list "cozystack.cozystack-scheduler" "linstor" $) }} @@ -239,6 +242,7 @@ {{- if eq (include "cozystack.platform.storage.backend" $) "blockstor" -}} {{- $_ := set $linstorValues "backend" "blockstor" -}} {{- end -}} +{{- with include "cozystack.platform.storage.blockstorMigration" $ }}{{ $_ := set $linstorValues "blockstorMigration" . }}{{ end -}} {{- $linstorComponents := dict "linstor" (dict "values" $linstorValues) -}} {{include "cozystack.platform.package" (list "cozystack.linstor" "default" $ $linstorComponents) }} {{include "cozystack.platform.package" (list "cozystack.cozystack-scheduler" "linstor" $) }} @@ -527,7 +531,7 @@ variants and opt-in on the slim ones. */}} {{include "cozystack.platform.package.optional.default" (list "cozystack.external-secrets-operator" $) }} {{- /* Told only the backend, as linstor-scheduler is in the common-packages helper: the linstor package's LinstorCluster says where the API is. */ -}} -{{- if eq (include "cozystack.platform.storage.backend" $) "blockstor" }} +{{- if include "cozystack.platform.storage.blockstorServesApi" $ }} {{- $guiComponents := dict "linstor-gui" (dict "values" (dict "linstor" (dict "backend" "blockstor"))) -}} {{include "cozystack.platform.package.optional.default" (list "cozystack.linstor-gui" $ $guiComponents) }} {{- else }} diff --git a/packages/core/platform/tests/bundles_storage_backend_test.yaml b/packages/core/platform/tests/bundles_storage_backend_test.yaml index 325a10c59..0afe6440b 100644 --- a/packages/core/platform/tests/bundles_storage_backend_test.yaml +++ b/packages/core/platform/tests/bundles_storage_backend_test.yaml @@ -146,6 +146,59 @@ tests: path: metadata.name value: cozystack.linstor-gui + # During a migration step LINSTOR's state is still the one CSI acts on, and + # blockstor-apiserver serves Resources it has not adopted, which the + # scheduler extender cannot read. The consumers move with linstor-csi, when + # the step is cleared. + - it: leaves the linstor-scheduler on LINSTOR during a migration step + set: + storage: + backend: blockstor + blockstorMigration: hold + bundles: + system: + enabled: true + variant: isp-full + asserts: + - notExists: + path: spec.components + documentSelector: + path: metadata.name + value: cozystack.linstor-scheduler + + - it: leaves the linstor-scheduler on LINSTOR while adopting on the generic variant + set: + storage: + backend: blockstor + blockstorMigration: adopt + bundles: + system: + enabled: true + variant: isp-full-generic + asserts: + - notExists: + path: spec.components + documentSelector: + path: metadata.name + value: cozystack.linstor-scheduler + + - it: leaves linstor-gui on LINSTOR during a migration step + set: + storage: + backend: blockstor + blockstorMigration: adopt + bundles: + system: + enabled: true + variant: isp-full + enabledPackages: [cozystack.linstor-gui] + asserts: + - notExists: + path: spec.components + documentSelector: + path: metadata.name + value: cozystack.linstor-gui + - it: leaves linstor-gui on its defaults under linstor set: bundles: @@ -208,3 +261,107 @@ tests: asserts: - failedTemplate: errorMessage: 'storage must be a map with a backend key, got blockstor' + + # A migration step has to reach the linstor package, which renders piraeus + # unchanged while it is set; left behind in the platform it would deploy the + # finished switch at once. + - it: passes the blockstor migration step through + set: + storage: + backend: blockstor + blockstorMigration: hold + bundles: + system: + enabled: true + variant: isp-full + asserts: + - equal: + path: spec.components.linstor.values + value: + backend: blockstor + blockstorMigration: hold + documentSelector: + path: metadata.name + value: cozystack.linstor + + - it: passes the blockstor migration step through on the generic variant + set: + storage: + backend: blockstor + blockstorMigration: adopt + bundles: + system: + enabled: true + variant: isp-full-generic + asserts: + - equal: + path: spec.components.linstor.values + value: + backend: blockstor + blockstorMigration: adopt + talos: + enabled: false + documentSelector: + path: metadata.name + value: cozystack.linstor + + # The empty default must not add a key: every blockstor cluster would roll a + # new revision of the linstor release for nothing. + - it: states no migration step once it is removed + set: + storage: + backend: blockstor + blockstorMigration: "" + bundles: + system: + enabled: true + variant: isp-full + asserts: + - equal: + path: spec.components.linstor.values + value: + backend: blockstor + documentSelector: + path: metadata.name + value: cozystack.linstor + + - it: fails the render on an unknown migration step + set: + storage: + backend: blockstor + blockstorMigration: adopted + bundles: + system: + enabled: true + variant: isp-full + asserts: + - failedTemplate: + errorMessage: 'storage.blockstorMigration must be "", "hold" or "adopt", got "adopted"' + + # The way back to linstor has to drop the step in the same change, or the + # next switch to blockstor would come up holding. + - it: fails the render on a migration step under the linstor backend + set: + storage: + backend: linstor + blockstorMigration: hold + bundles: + system: + enabled: true + variant: isp-full + asserts: + - failedTemplate: + errorMessage: 'storage.blockstorMigration "hold" is only valid with storage.backend: blockstor; remove it together with switching the backend back' + + - it: fails the render on a migration step under linstor on the generic variant + set: + storage: + backend: linstor + blockstorMigration: adopt + bundles: + system: + enabled: true + variant: isp-full-generic + asserts: + - failedTemplate: + errorMessage: 'storage.blockstorMigration "adopt" is only valid with storage.backend: blockstor; remove it together with switching the backend back' diff --git a/packages/core/platform/values.yaml b/packages/core/platform/values.yaml index a68ef57af..8bde66819 100644 --- a/packages/core/platform/values.yaml +++ b/packages/core/platform/values.yaml @@ -111,21 +111,27 @@ migrations: # Which storage control plane the cluster runs. # # linstor — the default, and what every existing cluster runs. -# blockstor — EXPERIMENTAL, for new clusters. A -# LINSTOR-API-compatible control plane serving the same -# CSI driver and StorageClasses. This value does not move -# a cluster that already holds LINSTOR volumes: blockstor -# adopts them with its own linstor-migrate runbook, which -# this platform does not run: -# https://blockstor.org/docs/migration/ +# blockstor — EXPERIMENTAL. A LINSTOR-API-compatible control plane +# serving the same CSI driver and StorageClasses. A new +# cluster selects it here. A cluster that already holds +# LINSTOR volumes moves only through blockstorMigration +# below, in the order packages/system/linstor/README.md +# gives; changing this value alone does not adopt them. # # Anything else fails the render rather than defaulting, so a typo # cannot quietly deploy the wrong storage control plane. Changing the -# backend of a running cluster fails the render too; on a cluster that -# holds no volumes yet, set storage.acknowledgeBackendChange to the new -# backend to confirm the switch. +# backend of a running cluster fails the render too until +# storage.acknowledgeBackendChange names the new backend. On a cluster +# that holds no volumes yet that confirms the whole switch; on one with +# LINSTOR volumes it goes together with blockstorMigration: hold. +# +# blockstorMigration is set only while blockstor adopts the volumes of a +# LINSTOR cluster: "hold", then "adopt", then removed. Until it is removed +# the linstor package deploys blockstor but leaves every piraeus object as +# it is under linstor. The steps are in packages/system/linstor/README.md. storage: backend: linstor + blockstorMigration: "" # Bundle deployment configuration bundles: diff --git a/packages/system/linstor/README.md b/packages/system/linstor/README.md index 8f6785bb9..7b2ad1778 100644 --- a/packages/system/linstor/README.md +++ b/packages/system/linstor/README.md @@ -1,4 +1,6 @@ -# Talos satellite graceful shutdown +# linstor + +## Talos satellite graceful shutdown Cozystack's Talos configuration removes the systemd `drbd-shutdown-guard`. The optional satellite preStop hook releases unused Secondary DRBD resources so their backing devices, including ZFS zvols, can be released during normal shutdown. @@ -26,6 +28,29 @@ Related upstream discussion: [Piraeus orderly shutdown on Talos](https://github. Run `make test` in this directory with Helm, helm-unittest and Python 3.11 or later. The tests cover rendering with each feature flag, resource selection and rechecks, bounded errors and timeouts, dry-run behavior, and logging in the shared pod PID namespace. +## Moving a LINSTOR cluster to blockstor + +**Experimental.** blockstor is experimental, and this procedure has been run on test clusters only. Run it in a maintenance window, after the runbook's pre-flight checks. + +blockstor adopts the volumes of a LINSTOR cluster in place with `linstor-migrate`, following [blockstor's migration runbook](https://github.com/cozystack/blockstor/blob/main/docs/linstor-migration.md). The runbook freezes CSI and stops LINSTOR first, deploys blockstor, applies the converted manifests, waits for adoption, and repoints CSI last. Setting `storage.backend: blockstor` alone does all of that in one step: piraeus-operator goes to external mode, deletes linstor-controller and repoints linstor-csi before a single volume is adopted, and the blockstor controller starts before its manifests are in. + +`storage.blockstorMigration` on the `cozystack.cozystack-platform` Package, passed to this chart as `blockstorMigration`, splits the switch into the runbook's steps. With `hold` or `adopt` every piraeus object renders exactly as under backend `linstor`. `hold` keeps the blockstor controller at zero replicas, and the release owns that count, so a retried upgrade does not start it. linstor-scheduler and linstor-gui stay on LINSTOR through both steps and move to blockstor-apiserver with linstor-csi, when the value is removed: until then blockstor serves no Resources, or Resources it has not adopted, and the scheduler extender cannot place a pod on those. + +piraeus-operator keeps running throughout, as in the runbook. Given LINSTOR's shape it has nothing to change: it applies its Deployments without a replica count, since the `LinstorCluster` sets none, so `linstor-controller` and `linstor-csi-controller` stay at the zero the freeze gave them, and with linstor-controller down its calls to the LINSTOR API fail and are retried. Its validating webhooks keep serving, so the release passes them at every step. + +Run each step below as its own change, never together with a Cozystack upgrade. A platform upgrade can bring a new piraeus-operator or linstor-csi, and the running operator would roll their pods out in the middle of the migration. + +Each step says how to go back from it. Every way back up to step 4 ends the same way, called "back to LINSTOR" below: set `storage: {backend: linstor, acknowledgeBackendChange: linstor}` without `blockstorMigration` in one change and wait for the `linstor` release, which removes blockstor's controller, apiserver and satellites, then scale `linstor-controller` to 1, unlock it, and scale `linstor-csi-controller` back to its count from step 1. The restarted controller starts with its master key locked, because the `LinstorCluster` this chart renders sets no `linstorPassphraseSecret`: existing LUKS volumes keep running and moving, but a new LUKS volume fails with `Unable to create encrypt key without having a master key` until `linstor encryption enter-passphrase` is given the value of `MASTER_PASSPHRASE` in the `linstor-passphrase` Secret. Any restart of linstor-controller under this chart behaves the same; setting `linstorPassphraseSecret: linstor-passphrase` on the `LinstorCluster` would unlock it on start instead. The blockstor CRDs and their objects stay behind; nothing reads them under `linstor`. + +Starting the migration again after a way back begins at step 1 with a fresh dump and conversion; the old manifests describe a LINSTOR state that has moved on. A way back from step 1 or 2 leaves no converted objects, and applying the new keyring Secret replaces the old one. A way back from step 3 or 4 leaves every converted `Node`, `StoragePool`, `ResourceGroup`, `ResourceDefinition`, `Resource` and `Snapshot` in place. The new server-side apply overwrites the objects that come back under the same names, but not the others: one for a volume deleted under LINSTOR meanwhile stays and is brought back by the next adoption. Do not remove those objects with a plain `kubectl delete`. A blockstor satellite holds a finalizer on each `Resource` and `Snapshot` and releases it only after it has deleted that replica's storage, so the delete waits while no satellite runs and destroys the volume, LINSTOR's included, as soon as the next `hold` starts one. If such objects are left, clear their finalizers while the backend is `linstor`, with no blockstor satellite running, and only then delete them; this path has not been tested. A retry after step 3 or 4 also finds the old `Resource`s' LUKS passwords wrapped under the keyring already in the cluster, so convert into that keyring with `-keyring-in` (the `keyring.json` key of the `blockstor-master-key` Secret in `cozy-linstor`) and `-blockstor-passphrase-file` (the LINSTOR passphrase, which opens it), as the runbook describes, rather than writing a new one with `-keyring-out`. + +1. Do the runbook's pre-flight checks and write down the replica count of `deploy/linstor-csi-controller`. Freeze: scale `deploy/linstor-csi-controller` and then `deploy/linstor-controller` to 0. Take the dump and convert it now, with nothing left to write to the LINSTOR database, and apply the converted keyring Secret into `cozy-linstor`. Back: scale `linstor-controller` to 1, unlock it as above, and scale `linstor-csi-controller` back; the keyring Secret is not read under `linstor` and can be deleted. +2. Set `storage: {backend: blockstor, acknowledgeBackendChange: blockstor, blockstorMigration: hold}` and wait for the `linstor` HelmRelease to become Ready. blockstor-apiserver and the satellites run, the controller is 0/0, and `ControllerConfig/default` names the passphrase Secret. Nothing of piraeus's own objects changes, and linstor-scheduler still points at linstor-controller. Back: back to LINSTOR. +3. Confirm that the `keyID` in the keyring Secret's `keyring.json` matches `luksKey.keyID` in the manifests; `blockstor encryption list-passphrases` cannot tell here, it prints `encryption: unset` while the controller is at zero. Then apply the converted manifests server-side, `kubectl apply --server-side --field-manager=linstor-migrate -f `. `ControllerConfig/default` among them carries LINSTOR's cluster-wide DRBD options, and a client-side apply leaves them owned by `kubectl-client-side-apply`, which any later `kubectl apply --server-side` of that object, by whoever runs it, takes over and removes along with every field it does not name; the satellites then adjust every resource to the defaults on live connections. The release's own hook only merge-patches `passphraseSecretRef` and cannot do that, but a hand-run apply still could. Back: back to LINSTOR. With the controller never started, the applied objects have acted on nothing. +4. Set `blockstorMigration: adopt`. The controller starts; wait for adoption to converge as the runbook describes. Back: back to LINSTOR, which is the runbook's rollback (scale blockstor to 0, `linstor-controller` back to 1, CSI still on LINSTOR); the runbook calls it a control-plane-only revert for most replicas, and its rollback section lists the cases where it is not. +5. Remove `blockstorMigration`. `LinstorCluster` goes to external mode; the operator deletes linstor-controller, repoints linstor-csi at blockstor-apiserver and rolls its satellite pods. linstor-scheduler and linstor-gui are repointed at blockstor-apiserver in the same change, and each shows one `UpgradeFailed` (`the LinstorCluster has no spec.externalController.url yet`) before the `linstor` release has written the external controller. That is expected: they retry on their own and are Ready about 30 seconds later. Back: none is documented or tested from here on. The linstor-controller Deployment is gone and CSI already talks to blockstor, so treat this step as the point of no return and do it only once step 4 has converged. +6. Scale `linstor-csi-controller` back by hand to the count from step 1: the operator repoints it in step 5 but keeps the 0 it found, and nothing in the release sets it. Then run the runbook's verification. Back: none. From here new volumes exist in blockstor only, and LINSTOR knows nothing of them. + ## Upgrading the blockstor satellites The `blockstor-satellite` DaemonSet replaces its pods one node at a time and holds the rollout on each node for `blockstorSatellite.minReadySeconds` (180 by default) after the new pod turns Ready. Ready only means the satellite's caches have synced, which takes seconds; its first pass, which re-renders and adjusts every DRBD resource on the node, ended 1.5 to 2.7 minutes after Ready on a test cluster with about 110 resources per node. The default covers that, so first passes on two nodes do not overlap; a node with more resources needs a longer pause. `maxUnavailable` is always 1 and `maxSurge` always 0, and the chart refuses other values: a wider rollout would run several first passes at once, and a second satellite on the node would drive the same DRBD resources. diff --git a/packages/system/linstor/hack/blockstor-controllerconfig.sh b/packages/system/linstor/hack/blockstor-controllerconfig.sh new file mode 100644 index 000000000..15503cbbb --- /dev/null +++ b/packages/system/linstor/hack/blockstor-controllerconfig.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Points ControllerConfig/default at the passphrase Secret, the one field of +# that object this chart owns; blockstor and linstor-migrate write the rest. +# +# PATCH JSON merge patch that sets spec.passphraseSecretRef +# MANIFEST the whole object, for a cluster that has none yet +# +# A merge patch rather than `kubectl apply --server-side`, because the apply +# can delete fields it does not name. After a server-side apply kubectl looks +# for a manager with an Update entry that owns the last-applied-configuration +# annotation, merges every field that manager owns into the applying manager +# and sends the apply again (migrateToSSAIfNecessary in +# k8s.io/kubectl/pkg/cmd/apply/apply.go, csaupgrade.UpgradeManagedFieldsPatch +# in k8s.io/client-go/util/csaupgrade, v0.33). A ControllerConfig last +# written by a client-side `kubectl apply`, such as linstor-migrate's output +# applied without --server-side, then hands its extraProps and drbdOptions to +# this manager, and the second apply, which names only passphraseSecretRef, +# removes them: LINSTOR's cluster-wide DRBD options are gone and the +# satellites adjust every resource to the defaults. No field manager avoids +# that, since the upgrade moves the fields to whichever manager applies. A +# merge patch replaces the fields it carries and touches nothing else, whoever +# owns the rest. +# +# A create that loses a race to blockstor creating the object fails; the Job +# retries and the next attempt patches. +set -eu + +patch=${PATCH:?PATCH holds the merge patch for spec.passphraseSecretRef} +manifest=${MANIFEST:?MANIFEST holds the ControllerConfig to create when there is none} +resource=controllerconfigs.blockstor.org +manager=cozystack-linstor + +current=$(kubectl get "$resource" default --ignore-not-found -o name) +if [ -n "$current" ]; then + kubectl patch "$resource" default --type=merge --field-manager="$manager" --patch "$patch" +else + printf '%s\n' "$manifest" | kubectl create --field-manager="$manager" -f - +fi diff --git a/packages/system/linstor/templates/_backend.tpl b/packages/system/linstor/templates/_backend.tpl new file mode 100644 index 000000000..04b2952d5 --- /dev/null +++ b/packages/system/linstor/templates/_backend.tpl @@ -0,0 +1,12 @@ +{{- /* +Whether piraeus-operator runs in external mode against blockstor-apiserver. +That is backend blockstor once blockstorMigration is cleared, and not before: +while blockstor adopts a LINSTOR cluster's volumes, every piraeus object +(LinstorCluster, LinstorSatelliteConfiguration and what they reference) +renders exactly as under backend linstor, so the operator, which keeps +running, finds nothing to change and keeps linstor-csi on LINSTOR. Templates +of blockstor's own components follow .Values.backend instead. +*/ -}} +{{- define "linstor.piraeusExternal" -}} +{{- if and (eq .Values.backend "blockstor") (not .Values.blockstorMigration) }}true{{ end -}} +{{- end -}} diff --git a/packages/system/linstor/templates/backend-guard.yaml b/packages/system/linstor/templates/backend-guard.yaml index 75f1dc98e..c2b5422a8 100644 --- a/packages/system/linstor/templates/backend-guard.yaml +++ b/packages/system/linstor/templates/backend-guard.yaml @@ -8,6 +8,18 @@ any other way, a hand-set component value for one, is checked here too. {{- fail (printf "linstor: backend must be \"linstor\" or \"blockstor\", got %q" (toString .Values.backend)) }} {{- end }} {{- /* +blockstorMigration holds piraeus in the LINSTOR shape. A value the chart +does not know would render it as complete, and with backend linstor there +is nothing to migrate to: both are refused rather than read as off. +*/ -}} +{{- $migration := .Values.blockstorMigration | default "" }} +{{- if not (has $migration (list "" "hold" "adopt")) }} +{{- fail (printf "linstor: blockstorMigration must be \"\", \"hold\" or \"adopt\", got %q" (toString $migration)) }} +{{- end }} +{{- if and $migration (ne .Values.backend "blockstor") }} +{{- fail (printf "linstor: blockstorMigration %q is only valid with backend blockstor; clear it together with switching the backend back" $migration) }} +{{- end }} +{{- /* blockstor's three images are one release: the controller, apiserver and satellite share a wire protocol and the CRDs under definitions/, which `make update-blockstor-crds` fetches for the controller's tag. Pinning one diff --git a/packages/system/linstor/templates/blockstor-controller.yaml b/packages/system/linstor/templates/blockstor-controller.yaml index e4a9b1383..993225541 100644 --- a/packages/system/linstor/templates/blockstor-controller.yaml +++ b/packages/system/linstor/templates/blockstor-controller.yaml @@ -116,7 +116,13 @@ metadata: app: blockstor-controller app.kubernetes.io/component: blockstor-controller spec: - replicas: 1 + {{- /* + Stopped in the hold step of a migration: started before the converted + manifests are applied, the controller would place replicas of its own + under definitions whose adopted Resources have not arrived yet. The + release owns the count, so an upgrade or a retry does not bring the + pod back while the manifests go in, as a scale by hand would. */}} + replicas: {{ eq .Values.blockstorMigration "hold" | ternary 0 1 }} {{- /* One reconciler at a time. The binary runs without leader election, so a rolling update would run the old and the new pod side by side against the diff --git a/packages/system/linstor/templates/blockstor-controllerconfig.yaml b/packages/system/linstor/templates/blockstor-controllerconfig.yaml index b098bed1c..b35068ade 100644 --- a/packages/system/linstor/templates/blockstor-controllerconfig.yaml +++ b/packages/system/linstor/templates/blockstor-controllerconfig.yaml @@ -10,12 +10,13 @@ kind in a release before it applies any, so a ControllerConfig here fails the first install of the blockstor backend on a kind that does not exist yet. And blockstor writes the same object at runtime (controller - properties, node connections) and creates it on first use, so the chart - owns one field, not the object: a server-side apply under its own field - manager sets passphraseSecretRef and leaves the rest alone, on a - ControllerConfig blockstor or linstor-migrate created as well as on a - missing one. --force-conflicts makes the value authoritative over a ref - set by hand. + properties, node connections) and creates it on first use, and on a + migrated cluster it carries LINSTOR's cluster-wide DRBD options, so the + chart owns one field, not the object: hack/blockstor-controllerconfig.sh + sets passphraseSecretRef with a merge patch, which leaves every other + field alone whoever owns it, and creates the object when there is none. + The patch makes the value authoritative over a ref set by hand. The + script says why not a server-side apply. The controller may start before this runs. That costs nothing: with no ref it unlocks nothing and creates no keyring, and it picks the ref up @@ -31,7 +32,7 @@ metadata: helm.sh/hook-weight: "-1" --- {{- /* - An apply that finds no object creates it, which needs create, and create + The script creates the object when there is none, which needs create, and create cannot be limited by name. ControllerConfig is a singleton named default; blockstor reads no other. */}} apiVersion: rbac.authorization.k8s.io/v1 @@ -87,13 +88,15 @@ spec: runAsGroup: 65534 seccompProfile: {type: RuntimeDefault} containers: - - name: apply + - name: patch image: {{ .Values.kubectl.image.repository }}:{{ .Values.kubectl.image.tag }} imagePullPolicy: IfNotPresent - command: [sh, -ec, 'printf "%s\n" "$MANIFEST" | kubectl apply --server-side --field-manager=cozystack-linstor --force-conflicts -f -'] + command: [sh, -ec, '$(SCRIPT)', blockstor-controllerconfig.sh] env: - name: HOME value: /tmp + - name: PATCH + value: {{ dict "spec" (dict "passphraseSecretRef" (dict "name" .Values.blockstorPassphraseSecret "key" "MASTER_PASSPHRASE")) | toJson | quote }} - name: MANIFEST value: | apiVersion: blockstor.org/v1alpha1 @@ -104,6 +107,9 @@ spec: passphraseSecretRef: name: {{ .Values.blockstorPassphraseSecret }} key: MASTER_PASSPHRASE + - name: SCRIPT + value: | +{{ required "ControllerConfig script is missing" (.Files.Get "hack/blockstor-controllerconfig.sh") | indent 16 }} securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true diff --git a/packages/system/linstor/templates/cluster.yaml b/packages/system/linstor/templates/cluster.yaml index 271611b26..f5b1c387b 100644 --- a/packages/system/linstor/templates/cluster.yaml +++ b/packages/system/linstor/templates/cluster.yaml @@ -1,3 +1,6 @@ +{{- /* See linstor.piraeusExternal in _backend.tpl for why this follows it + rather than .Values.backend. */ -}} +{{- $external := include "linstor.piraeusExternal" . -}} apiVersion: piraeus.io/v1 kind: LinstorCluster metadata: @@ -7,7 +10,7 @@ metadata: spec: #nodeSelector: # node-role.kubernetes.io/linstor: "" - {{- if eq .Values.backend "blockstor" }} + {{- if $external }} {{- /* External mode: piraeus-operator runs no linstor-controller of its own. linstor-csi talks to blockstor-apiserver, which serves the LINSTOR REST API on the mTLS port :3371 only. The URL has to match @@ -25,7 +28,7 @@ spec: {{- end }} apiTLS: certManager: - {{- if eq .Values.backend "blockstor" }} + {{- if $external }} {{- /* The operator issues linstor-csi-{controller,node}-tls from this Issuer, so the CSI pods present a client certificate chained to the CA blockstor-apiserver verifies. */}} @@ -34,7 +37,7 @@ spec: name: linstor-api-ca {{- end }} kind: Issuer - {{- if eq .Values.backend "blockstor" }} + {{- if $external }} {{- /* The operator is a client of the API itself: it probes /v1/controller/version before every LinstorCluster and LinstorSatellite reconcile. In external mode it issues no @@ -64,7 +67,7 @@ spec: value: "20" - name: DrbdOptions/Net/timeout value: "100" - {{- if eq .Values.backend "linstor" }} + {{- if not $external }} controller: enabled: true podTemplate: @@ -182,7 +185,7 @@ spec: - name: linstor-wait-node-online image: {{ .Values.linstorCSI.image.repository }}:{{ .Values.linstorCSI.image.tag }} patches: - {{- if eq .Values.backend "linstor" }} + {{- if not $external }} - target: kind: Deployment name: linstor-controller diff --git a/packages/system/linstor/templates/linstor-api-tls.yaml b/packages/system/linstor/templates/linstor-api-tls.yaml index c178b1a67..a66c8234f 100644 --- a/packages/system/linstor/templates/linstor-api-tls.yaml +++ b/packages/system/linstor/templates/linstor-api-tls.yaml @@ -1,4 +1,4 @@ -{{- if eq .Values.backend "linstor" }} +{{- if not (include "linstor.piraeusExternal" .) }} --- apiVersion: cert-manager.io/v1 kind: Certificate diff --git a/packages/system/linstor/templates/plunger/configmap-scripts.yaml b/packages/system/linstor/templates/plunger/configmap-scripts.yaml index 871a554d2..388e861a0 100644 --- a/packages/system/linstor/templates/plunger/configmap-scripts.yaml +++ b/packages/system/linstor/templates/plunger/configmap-scripts.yaml @@ -1,4 +1,4 @@ -{{- if eq .Values.backend "linstor" }} +{{- if not (include "linstor.piraeusExternal" .) }} {{- $files := .Files.Glob "hack/plunger/*.sh" -}} {{/* TODO Add checksum of scripts to the pod selectors */}} --- diff --git a/packages/system/linstor/templates/podscrape.yaml b/packages/system/linstor/templates/podscrape.yaml index 2ed584d38..f19cd7aa3 100644 --- a/packages/system/linstor/templates/podscrape.yaml +++ b/packages/system/linstor/templates/podscrape.yaml @@ -20,7 +20,7 @@ spec: selector: matchLabels: app.kubernetes.io/component: linstor-satellite -{{- if eq .Values.backend "linstor" }} +{{- if not (include "linstor.piraeusExternal" .) }} --- apiVersion: operator.victoriametrics.com/v1beta1 kind: VMPodScrape diff --git a/packages/system/linstor/templates/satellites-plunger.yaml b/packages/system/linstor/templates/satellites-plunger.yaml index 8a0fc603a..f193b19aa 100644 --- a/packages/system/linstor/templates/satellites-plunger.yaml +++ b/packages/system/linstor/templates/satellites-plunger.yaml @@ -1,4 +1,4 @@ -{{- if eq .Values.backend "linstor" }} +{{- if not (include "linstor.piraeusExternal" .) }} apiVersion: piraeus.io/v1 kind: LinstorSatelliteConfiguration metadata: diff --git a/packages/system/linstor/tests/blockstor_controllerconfig_test.yaml b/packages/system/linstor/tests/blockstor_controllerconfig_test.yaml index d708e887e..28eeb1aa2 100644 --- a/packages/system/linstor/tests/blockstor_controllerconfig_test.yaml +++ b/packages/system/linstor/tests/blockstor_controllerconfig_test.yaml @@ -53,18 +53,39 @@ tests: path: kind value: Job asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: PATCH + value: '{"spec":{"passphraseSecretRef":{"key":"MASTER_PASSPHRASE","name":"my-passphrase"}}}' - matchRegex: - path: spec.template.spec.containers[0].env[1].value + path: spec.template.spec.containers[0].env[2].value pattern: '(?m)^ name: my-passphrase$' - - it: owns only the fields it applies, and wins over a ref set by hand + # A server-side apply of this one field removes the migrated DRBD options + # from a ControllerConfig a client-side kubectl apply wrote: kubectl first + # hands every field of the client-side manager to the applying one. The + # merge patch touches only what it carries. tests/test_controllerconfig_hook.py + # runs the script against such an object. + - it: sets the ref with a merge patch, never a server-side apply documentSelector: path: kind value: Job asserts: + - equal: + path: spec.template.spec.containers[0].command + value: [sh, -ec, '$(SCRIPT)', blockstor-controllerconfig.sh] + - contains: + path: spec.template.spec.containers[0].env + content: + name: PATCH + value: '{"spec":{"passphraseSecretRef":{"key":"MASTER_PASSPHRASE","name":"linstor-passphrase"}}}' - matchRegex: - path: spec.template.spec.containers[0].command[2] - pattern: 'kubectl apply --server-side --field-manager=cozystack-linstor --force-conflicts -f -' + path: spec.template.spec.containers[0].env[3].value + pattern: 'kubectl patch "\$resource" default --type=merge --field-manager="\$manager" --patch "\$patch"' + - notMatchRegex: + path: spec.template.spec.containers[0].env[3].value + pattern: '(?m)^[^#]*kubectl apply' - it: pins its image by digest documentSelector: diff --git a/packages/system/linstor/tests/blockstor_migration_test.yaml b/packages/system/linstor/tests/blockstor_migration_test.yaml new file mode 100644 index 000000000..d0da1a457 --- /dev/null +++ b/packages/system/linstor/tests/blockstor_migration_test.yaml @@ -0,0 +1,196 @@ +suite: blockstor adopting a LINSTOR cluster + +# The runbook freezes CSI before blockstor adopts, and repoints CSI only once +# adoption has converged, while piraeus-operator keeps running. So hold and +# adopt render every piraeus object byte for byte as backend linstor does, +# which leaves the operator nothing to change, and only clearing the value +# moves piraeus to external mode. + +release: + name: linstor + namespace: cozy-linstor + +tests: + - it: "keeps LinstorCluster on the LINSTOR controller while holding" + set: + backend: blockstor + blockstorMigration: hold + templates: + - templates/cluster.yaml + asserts: + - notExists: + path: spec.externalController + - equal: + path: spec.internalTLS.certManager.name + value: linstor-internal-ca + - equal: + path: spec.apiTLS.certManager.name + value: linstor-api-ca + - notExists: + path: spec.apiTLS.clientSecretName + - equal: + path: spec.controller.enabled + value: true + + - it: "keeps LinstorCluster on the LINSTOR controller while adopting" + set: + backend: blockstor + blockstorMigration: adopt + templates: + - templates/cluster.yaml + asserts: + - notExists: + path: spec.externalController + - equal: + path: spec.controller.enabled + value: true + + # Dropping the plunger configuration is a change to a piraeus object too, and + # its ConfigMap is mounted by the LINSTOR controller and satellite pods the + # operator keeps in place. + - it: "keeps the plunger and the LINSTOR API CA during the migration" + set: + backend: blockstor + blockstorMigration: hold + templates: + - templates/satellites-plunger.yaml + - templates/plunger/configmap-scripts.yaml + - templates/linstor-api-tls.yaml + asserts: + - hasDocuments: + count: 1 + template: templates/satellites-plunger.yaml + - hasDocuments: + count: 1 + template: templates/plunger/configmap-scripts.yaml + - hasDocuments: + count: 2 + template: templates/linstor-api-tls.yaml + + - it: "keeps scraping the LINSTOR controller during the migration" + set: + backend: blockstor + blockstorMigration: adopt + capabilities: + apiVersions: + - operator.victoriametrics.com/v1beta1 + templates: + - templates/podscrape.yaml + asserts: + - hasDocuments: + count: 2 + + - it: "moves LinstorCluster to external mode once the migration is cleared" + set: + backend: blockstor + blockstorMigration: "" + templates: + - templates/cluster.yaml + asserts: + - equal: + path: spec.externalController.url + value: https://blockstor-apiserver.cozy-linstor.svc:3371 + - notExists: + path: spec.controller + + - it: "deploys blockstor while holding" + set: + backend: blockstor + blockstorMigration: hold + templates: + - templates/blockstor-apiserver.yaml + - templates/blockstor-satellite.yaml + - templates/crds/crds.yaml + asserts: + - isKind: + of: Deployment + template: templates/blockstor-apiserver.yaml + documentSelector: + path: kind + value: Deployment + - isKind: + of: DaemonSet + template: templates/blockstor-satellite.yaml + documentSelector: + path: kind + value: DaemonSet + - hasDocuments: + count: 8 + template: templates/crds/crds.yaml + + # Started before the converted manifests are in, the controller places + # replicas of its own under definitions whose Resources have not arrived. + # Rendered at 0 rather than scaled by hand, so a retried or repeated upgrade + # does not start it. + - it: "stops the blockstor controller while holding" + set: + backend: blockstor + blockstorMigration: hold + template: templates/blockstor-controller.yaml + documentSelector: + path: kind + value: Deployment + asserts: + - equal: + path: spec.replicas + value: 0 + + - it: "runs the blockstor controller while adopting" + set: + backend: blockstor + blockstorMigration: adopt + template: templates/blockstor-controller.yaml + documentSelector: + path: kind + value: Deployment + asserts: + - equal: + path: spec.replicas + value: 1 + + # The hook names the passphrase Secret; the controller started in adopt has + # to find it in place. + - it: "points ControllerConfig at the passphrase while holding" + set: + backend: blockstor + blockstorMigration: hold + template: templates/blockstor-controllerconfig.yaml + documentSelector: + path: kind + value: Job + asserts: + - isKind: + of: Job + + # blockstor-satellite runs on the nodes from hold on, so the hook would down + # its DRBD resources there as it would after the switch. + - it: "refuses the Talos shutdown hook during the migration" + set: + backend: blockstor + blockstorMigration: adopt + talos.gracefulShutdown.enabled: true + templates: + - templates/satellites-talos.yaml + asserts: + - failedTemplate: + errorMessage: "linstor: talos.gracefulShutdown.enabled is not supported with backend blockstor: its hook would tear down blockstor's DRBD resources" + + - it: "refuses a migration step it does not know" + set: + backend: blockstor + blockstorMigration: adopted + templates: + - templates/backend-guard.yaml + asserts: + - failedTemplate: + errorMessage: 'linstor: blockstorMigration must be "", "hold" or "adopt", got "adopted"' + + - it: "refuses a migration step under the LINSTOR backend" + set: + backend: linstor + blockstorMigration: hold + templates: + - templates/backend-guard.yaml + asserts: + - failedTemplate: + errorMessage: 'linstor: blockstorMigration "hold" is only valid with backend blockstor; clear it together with switching the backend back' diff --git a/packages/system/linstor/tests/test_controllerconfig_hook.py b/packages/system/linstor/tests/test_controllerconfig_hook.py new file mode 100644 index 000000000..8cbfbbcb4 --- /dev/null +++ b/packages/system/linstor/tests/test_controllerconfig_hook.py @@ -0,0 +1,164 @@ +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest + +SCRIPT = Path(__file__).resolve().parents[1] / "hack" / "blockstor-controllerconfig.sh" +RESOURCE = "controllerconfigs.blockstor.org" +PATCH = {"spec": {"passphraseSecretRef": {"key": "MASTER_PASSPHRASE", "name": "linstor-passphrase"}}} +MANIFEST = """apiVersion: blockstor.org/v1alpha1 +kind: ControllerConfig +metadata: + name: default +spec: + passphraseSecretRef: + name: linstor-passphrase + key: MASTER_PASSPHRASE +""" + +# kubectl stand-in: serves ControllerConfig/default from a JSON state file, +# applies merge patches to it the way the apiserver does (RFC 7386), refuses +# a create of an object that exists, and logs every call. Any other call, a +# server-side apply among them, fails the script. +FAKE_KUBECTL = r''' +import json, os, sys +state_path, log_path = os.environ["FAKE_STATE"], os.environ["FAKE_LOG"] +args = sys.argv[1:] +with open(log_path, "a") as log: + log.write(json.dumps(args) + "\n") +with open(state_path) as f: + state = json.load(f) + +def opt(name): + for arg in args: + if arg.startswith(name + "="): + return arg.split("=", 1)[1] + return args[args.index(name) + 1] + +def merge(target, patch): + if not isinstance(patch, dict): + return patch + target = dict(target) if isinstance(target, dict) else {} + for key, value in patch.items(): + if value is None: + target.pop(key, None) + else: + target[key] = merge(target.get(key), value) + return target + +def save(): + with open(state_path, "w") as f: + json.dump(state, f) + +resource = "controllerconfigs.blockstor.org" +if args[:3] == ["get", resource, "default"]: + if state.get("get_error"): + sys.exit(state["get_error"]) + assert "--ignore-not-found" in args + if state["object"] is not None: + print("controllerconfig.blockstor.org/default") + sys.exit(0) +if args[:3] == ["patch", resource, "default"]: + assert opt("--type") == "merge" + if state["object"] is None: + sys.exit("NotFound") + state["object"] = merge(state["object"], json.loads(opt("--patch"))) + save() + sys.exit(0) +if args[:1] == ["create"] and opt("-f") == "-": + if state["object"] is not None: + sys.exit("AlreadyExists") + state["created"] = sys.stdin.read() + state["object"] = {"created": True} + save() + sys.exit(0) +sys.exit("unexpected kubectl call: %s" % args) +''' + +# ControllerConfig/default as a client-side `kubectl apply` of linstor-migrate's +# output leaves it: LINSTOR's cluster-wide DRBD options in extraProps, owned +# by kubectl-client-side-apply, which also owns the last-applied annotation. +# This is the shape a server-side apply of passphraseSecretRef alone empties. +MIGRATED = { + "apiVersion": "blockstor.org/v1alpha1", + "kind": "ControllerConfig", + "metadata": { + "name": "default", + "annotations": {"kubectl.kubernetes.io/last-applied-configuration": "{}"}, + "managedFields": [{"manager": "kubectl-client-side-apply", "operation": "Update"}], + }, + "spec": { + "extraProps": { + "DrbdOptions/Net/timeout": "100", + "DrbdOptions/Net/verify-alg": "crc32c", + "DrbdOptions/Resource/on-no-data-accessible": "suspend-io", + }, + "drbdOptions": {"net": {"connect-int": "15"}}, + "passphraseSecretRef": {"name": "set-by-hand", "key": "OTHER"}, + }, +} + + +class ControllerConfigHookTest(unittest.TestCase): + def setUp(self): + self.dir = Path(self.enterContext(tempfile.TemporaryDirectory())) + kubectl = self.dir / "kubectl" + kubectl.write_text("#!/bin/sh\nexec %s %s \"$@\"\n" % (sys.executable, self.dir / "fake.py")) + kubectl.chmod(0o755) + (self.dir / "fake.py").write_text(FAKE_KUBECTL) + self.state = self.dir / "state.json" + self.log = self.dir / "log" + self.log.touch() + + def given(self, obj, **extra): + self.state.write_text(json.dumps(dict(object=obj, **extra))) + + def run_script(self): + env = dict(os.environ, PATH="%s:%s" % (self.dir, os.environ["PATH"]), PATCH=json.dumps(PATCH), + MANIFEST=MANIFEST, FAKE_STATE=str(self.state), FAKE_LOG=str(self.log)) + return subprocess.run(["sh", "-e", str(SCRIPT)], env=env, capture_output=True, text=True) + + def result(self): + return json.loads(self.state.read_text()) + + def calls(self): + return [json.loads(line)[0] for line in self.log.read_text().splitlines()] + + def test_keeps_every_field_it_does_not_set(self): + self.given(json.loads(json.dumps(MIGRATED))) + run = self.run_script() + self.assertEqual(run.returncode, 0, run.stderr) + obj = self.result()["object"] + self.assertEqual(obj["spec"]["extraProps"], MIGRATED["spec"]["extraProps"]) + self.assertEqual(obj["spec"]["drbdOptions"], MIGRATED["spec"]["drbdOptions"]) + self.assertEqual(obj["metadata"], MIGRATED["metadata"]) + self.assertEqual(self.calls(), ["get", "patch"]) + + def test_wins_over_a_ref_set_by_hand(self): + self.given(json.loads(json.dumps(MIGRATED))) + run = self.run_script() + self.assertEqual(run.returncode, 0, run.stderr) + self.assertEqual(self.result()["object"]["spec"]["passphraseSecretRef"], + {"name": "linstor-passphrase", "key": "MASTER_PASSPHRASE"}) + + def test_creates_a_missing_object(self): + self.given(None) + run = self.run_script() + self.assertEqual(run.returncode, 0, run.stderr) + self.assertEqual(self.result()["created"].rstrip("\n"), MANIFEST.rstrip("\n")) + self.assertEqual(self.calls(), ["get", "create"]) + + # The CRD may not be served yet right after a first install: the Job must + # fail and be retried, not create blindly or report success. + def test_fails_when_the_object_cannot_be_read(self): + self.given(None, get_error="the server could not find the requested resource") + run = self.run_script() + self.assertNotEqual(run.returncode, 0) + self.assertEqual(self.calls(), ["get"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/packages/system/linstor/tests/test_migration_render.py b/packages/system/linstor/tests/test_migration_render.py new file mode 100644 index 000000000..dd2a20122 --- /dev/null +++ b/packages/system/linstor/tests/test_migration_render.py @@ -0,0 +1,51 @@ +from pathlib import Path +import shutil +import subprocess +import unittest + +CHART = Path(__file__).resolve().parents[1] + +# Every template that renders a piraeus.io object, or something one of them +# references. While blockstorMigration is set the release must give piraeus +# nothing new: the operator keeps running through the migration, and has to +# find LINSTOR's shape and keep linstor-csi on LINSTOR until the value is +# cleared. helm-unittest asserts on one render at a time, so the comparison +# across renders lives here. +PIRAEUS_TEMPLATES = [ + "templates/cluster.yaml", + "templates/satellites-cozy.yaml", + "templates/satellites-plunger.yaml", + "templates/satellites-reloader.yaml", + "templates/satellites-talos.yaml", + "templates/plunger/configmap-scripts.yaml", + "templates/linstor-api-tls.yaml", + "templates/linstor-internal-tls.yaml", + "templates/podscrape.yaml", +] + + +def render(*values): + args = ["helm", "template", "linstor", str(CHART), "--namespace", "cozy-linstor", + "--api-versions", "operator.victoriametrics.com/v1beta1"] + for value in values: + args += ["--set", value] + out = subprocess.run(args, check=True, capture_output=True, text=True).stdout + sources = [f"# Source: cozy-linstor/{template}" for template in PIRAEUS_TEMPLATES] + docs = [doc.removeprefix("---\n") for doc in out.split("\n---\n")] + return [doc for doc in docs if doc.split("\n", 1)[0] in sources] + + +@unittest.skipUnless(shutil.which("helm"), "helm is required") +class MigrationLeavesPiraeusAlone(unittest.TestCase): + def test_hold_and_adopt_render_piraeus_as_linstor(self): + linstor = render("backend=linstor") + for step in ("hold", "adopt"): + with self.subTest(step=step): + self.assertEqual(render("backend=blockstor", f"blockstorMigration={step}"), linstor) + + def test_completed_migration_changes_piraeus(self): + self.assertNotEqual(render("backend=blockstor"), render("backend=linstor")) + + +if __name__ == "__main__": + unittest.main() diff --git a/packages/system/linstor/values.yaml b/packages/system/linstor/values.yaml index c893de51d..bf84c094c 100644 --- a/packages/system/linstor/values.yaml +++ b/packages/system/linstor/values.yaml @@ -10,12 +10,34 @@ # linstor-csi build, so the StorageClasses (provisioner # linstor.csi.linbit.com) are the same under either. # -# blockstor is for new clusters. This chart does not move a cluster that -# already holds LINSTOR volumes: blockstor adopts them with its own -# linstor-migrate runbook, which the chart does not run: -# https://blockstor.org/docs/migration/ +# A new cluster selects blockstor here. A cluster that already holds +# LINSTOR volumes moves only through blockstorMigration below, in the +# order README.md gives; switching backend alone does not adopt them. backend: linstor +# Set only while a cluster that holds LINSTOR volumes moves to blockstor, +# with backend blockstor. The runbook freezes CSI and stops LINSTOR before +# blockstor adopts the volumes, and repoints CSI only once adoption has +# converged; one backend flip cannot express that order. Each step is a +# value: +# +# hold — blockstor is deployed with its controller stopped. Every +# piraeus object renders as under backend linstor, so the +# operator keeps linstor-csi on LINSTOR. Apply the converted +# manifests in this step. +# adopt — the blockstor controller runs and adopts the volumes. piraeus +# is still untouched. +# "" — migration done: LinstorCluster goes external and the operator +# repoints linstor-csi at blockstor-apiserver. +# +# piraeus stays untouched because piraeus-operator keeps running through +# the migration, as blockstor's runbook has it: given LINSTOR's shape it +# has nothing to change, leaves linstor-controller and linstor-csi-controller +# at the zero replicas the freeze set, and keeps linstor-csi on LINSTOR. +# Clearing this value is the one step that changes piraeus. README.md has +# the order. +blockstorMigration: "" + piraeusServer: image: repository: ghcr.io/cozystack/cozystack/piraeus-server