mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-03 21:53:20 +09:00
feat(linstor): add Blockstor as a selectable storage backend (#2942)
<!-- 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, docs, style, refactor, perf, test, build, ci, chore - Scopes are not an exhaustive list; pick the most specific scope for the change and extend the list when a genuinely new area appears. Examples: - System components: dashboard, platform, operator, cilium, kube-ovn, linstor, fluxcd, cluster-api - Managed apps: postgres, mariadb, redis, kafka, clickhouse, virtual-machine, kubernetes - Development and maintenance: api, hack, tests, ci, docs, maintenance - Breaking changes: append `!` after type/scope (`feat(api)!: ...`) or add a `BREAKING CHANGE:` footer - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `kind/backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does Adds Blockstor as a second control plane the `linstor` package can deploy, chosen at install time with `storage.backend` on the platform. LINSTOR stays the default, and a cluster that does not select blockstor renders exactly what it renders on `main`. Blockstor serves the LINSTOR REST API, so linstor-csi, piraeus-operator and the StorageClasses are the same for both. This PR is for new clusters only. Moving a cluster that already holds LINSTOR volumes to blockstor (the `storage.blockstorMigration` steps, the hook Jobs that relax piraeus's webhooks while the operator is stopped, and the README order) is split out into #5466, stacked on this one. Blockstor is experimental. The package pins blockstor 0.4.0, all three images by digest, and the chart refuses to render if the controller, apiserver and satellite tags name different releases. 0.4.0 advertises REST API 1.29, which the linstor-csi v1.13 on `main` requires. A LUKS volume formatted by blockstor 0.2.x is neither opened nor re-formatted by 0.3.0 and later, since 0.3.0 wraps a per-volume password under a master key. This only matters for clusters that ran an earlier revision of this branch; nothing on `main` ever shipped blockstor. Default path: - `helm template packages/system/linstor` is byte-identical to `main` (defaults, `talos.enabled=false`, `drbd.enabled=false`, explicit `backend=linstor`). - The platform renders the `cozystack.linstor` Package without components, as on `main`, so an upgrade rolls no new revision of the release. Selecting the backend: `storage.backend` falls back to `linstor` only when the key is absent. Any other present value fails the render, `""`, `false` and `0` included. `null` is the one case the chart can't see, Helm drops a null key before rendering. The `linstor` chart checks the value on its own too. Changing the backend of a running cluster fails the render, the same way the networking variant guard works: the platform looks up the live `cozystack.linstor` Package, and `storage.acknowledgeBackendChange: <target>` confirms the switch on a cluster that has no volumes yet. Under blockstor the package renders blockstor's controller, apiserver and satellite, plus its CRDs with `helm.sh/resource-policy: keep`, since those objects are the whole blockstor database. piraeus-operator runs in external mode against the apiserver's mTLS port and uses a client cert from the same CA for its own version probe (#4016). linstor-scheduler and linstor-gui are told only the backend by the platform and read the endpoint and client Secret from that same `LinstorCluster` (`spec.externalController.url`, `spec.apiTLS.clientSecretName`), the object that points linstor-csi there, so the names of blockstor's Service and Secret live only in the linstor package and nothing renders objects under piraeus's names. Under linstor they get no values and keep their defaults; the scheduler chart takes this through one more vendored patch. Under blockstor a `LinstorCluster` that names no external controller yet fails their render instead of falling back to linstor-controller: on a backend switch they can upgrade before the linstor release has rewritten that object, and the fallback left them on a Service the operator then deletes, with nothing to render them again. The platform's HelmReleases retry a failed render every retry interval without counting it as a failure, so they follow once the linstor release is through. Every blockstor component finds the Secret that opens its master key through `ControllerConfig/default`. A post-install/post-upgrade hook Job server-side applies `spec.passphraseSecretRef` there, pointing at piraeus's `linstor-passphrase` (key `MASTER_PASSPHRASE`, the name is the `blockstorPassphraseSecret` value), and leaves the rest of the object to blockstor. It is a Job and not a release object because the CRD comes with the same release. The controller opens nothing and creates no keyring until the reference is there, so starting before the Job is harmless. Because the passphrase Secret is always named, `linstor encryption create-passphrase` is refused under this chart: the operator creates `linstor-passphrase` by hand before the first encrypted volume. piraeus still runs a `linstor-satellite` pod on every node it picks for `linstor-csi-node`, and `LinstorCluster` has no setting that stops one without the other. So cozystack's satellite configuration, its internal CA and the satellite scrape stay under both backends: the pod is pinned to our image, with TLS, limits and host networking, and the address the operator registers a node with is the node's own. The plunger and the opt-in Talos graceful-shutdown hook stay LINSTOR-only (the hook is refused under blockstor), because they act on DRBD resources that under blockstor belong to blockstor-satellite. blockstor-satellite runs the plunger's DRBD workarounds itself, and the chart lets it act on a stalled resync (LINBIT/drbd#149) instead of only reporting it: `blockstorSatellite.stalledResyncAct`, on by default. There is one `LinstorCluster` document for both backends, only the keys that differ are gated, so the CSI part (strict topology and main's group-snapshot gate included) can't drift. RBAC and exposure: - `cozy-linstor` is shared with piraeus, so no blockstor component can read an arbitrary Secret there. Each has a namespaced Role naming only `blockstor-master-key`, `blockstor-unlock` and the passphrase Secret: the satellite gets `get`, the controller and the apiserver get `get` and `update`, plus `create`, which RBAC cannot limit by name. The named rules also allow `list` and `watch`, which newer blockstor releases use with a `metadata.name` field selector; - because that `create` is unnamed, a ValidatingAdmissionPolicy admits a Secret create by a blockstor ServiceAccount in the release namespace only for the keyring and the generated `blockstor-unlock` Secret, with the types blockstor gives them; - no component has cluster-wide Secret access; - the apiserver's plain HTTP listener is bound to `127.0.0.1`, port-forward still works; - the controller has no leader election, so its Deployment uses `Recreate`, and neither it nor the satellite gets leases; - the satellite deletes nothing but the PhysicalDevices it discovers, and the roles name every blockstor kind they grant; - the satellite's host ports (3372, 9101, 8080) are closed to the world, same as drbd-reactor's; - the controller and the apiserver get 21s to stop, so a SIGTERM does not cut a detached rollback short. The snapshot stream between satellites runs on port 3372 over mutual TLS, with a CA of its own from `ca-bootstrapper`, kept apart from the API CA. The `blockstor-satellite` DaemonSet rolls one node at a time and holds each node for `blockstorSatellite.minReadySeconds` (180 by default) after Ready, because the satellite is Ready seconds after start while its first pass over the node's DRBD resources ended 1.5 to 2.7 minutes later on a test cluster with about 110 resources per node. `maxUnavailable` is fixed at 1 and `maxSurge` at 0, and `OnDelete` is there for an upgrade checked node by node; the README describes that procedure. The trade-off to review: the HelmRelease waits for the whole rollout, about 3.5 minutes per node at the default, so on more than two or three nodes the first upgrade attempt times out and the retry finishes it, and `HelmReleaseNotReady` fires meanwhile. None of the three components sets a CPU limit, as the LINSTOR controller and satellite don't: under a 500m limit every reconcile pass got throttled and each volume create took tens of seconds. Memory stays limited. The e2e scripts prepare and check whatever `COZY_STORAGE_BACKEND` says, and refuse an unset or unknown value. Under blockstor the prep waits until every satellite reports its pool before applying StorageClasses. `make update-blockstor-crds` refreshes `definitions/` from the blockstor tag the images are pinned to. For 0.4.0 it reproduces the release's CRDs byte for byte. Every `DrbdOptions/*` key the chart sets on the controller and the e2e StorageClasses set passes the whitelist 0.4.0 enforces. ### Testing - `make test` in `packages/system/linstor`: helm-unittest 133/133 in 20 suites, Python 20/20. - `helm unittest` in `packages/core/platform`: 394/394; `packages/system/linstor-scheduler`: 31/31; `packages/system/linstor-gui`: 28/28. - `bats`: `hack/linstor-storage-mode_test.bats` 33/33, `hack/post-install-prep.bats` 25/25, `hack/platform-packages_test.bats` 16/16. - Every guard was checked by reverting it and watching its test fail: empty backend, shared strict topology, loopback bind, `Recreate`, the satellite role, the pool report wait, the pool guard retrying a read that exits 2, the graceful-shutdown refusal, the stream port and its TLS, no cluster-wide Secret access, the named Secret grants, the admission policy, the stop grace, the one-release image check, the rollout strategy and pause. - `hack/check-commit-trailers.sh origin/main..HEAD`: OK. ### Not tested - A live run on 0.4.0 passed on a three-node stand installed with `storage.backend: blockstor` and upgraded to this PR's pin, see https://github.com/cozystack/cozystack/pull/2942#issuecomment-7225299079: Filesystem and Block PVCs, LUKS, snapshot and restore, group snapshots across nodes, online resize, `vmdisk-clone`, and the `vminstance` chainsaw suite including the VM backup roundtrips. That run predates the scheduler and GUI render guard above, which is unit-tested only. No CI lane can run blockstor: every e2e lane runs Talos in containers without DRBD. - The passphrase hook Job and the admission policy are rendered and unit-tested here; this PR has no run of them on a fresh install. - The satellite rollout strategy has not rolled on a live cluster; the timing figures come from a manual node-by-node `OnDelete` upgrade. ### Screenshots N/A, no UI change. ### Downstream repositories <!-- Cozystack is upstream for repositories that are NOT kept in sync with it automatically, and nothing in CI compares the two sides, so a change here can break them silently. Which change forces what, and which file to touch, is the trigger map in docs/agents/contributing.md under "Downstream Repositories". Walk it before you tick anything. --> - [ ] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: https://github.com/cozystack/website/pull/667 documents the backend, `storage.acknowledgeBackendChange` and this chart. It still describes blockstor 0.2.0 and has to follow this PR to 0.4.0 and to the master key opened from `linstor-passphrase`. Its LINSTOR to Blockstor migration guide belongs with #5466. It stays unticked and merges after this PR. - [ ] [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: I walked the trigger map against the diff. Only the website is affected: the new `storage.backend` key in `packages/core/platform/values.yaml` and the backend docs, both in website#667. No app package, installer values, variant, bundle, `hack/package.mk` or `hack/update-crd.sh` is touched. ### Release note ```release-note feat(linstor): Blockstor can be selected as the storage control plane for new clusters with `storage.backend: blockstor` on the platform. LINSTOR stays the default and existing clusters are unchanged. Blockstor is experimental, and moving a cluster that already has LINSTOR volumes to it is not part of this change. ```
This commit is contained in:
68 files changed
+7931
-40
No files matched your search
@@ -493,6 +493,52 @@ cozy_wait_schedulable_node() {
|
||||
done
|
||||
}
|
||||
|
||||
# The storage control plane the cluster under test runs, as the install was
|
||||
# told (COZY_STORAGE_BACKEND, forwarded into the sandbox). Unset means linstor,
|
||||
# the default every lane installs; anything else unknown is refused rather than
|
||||
# read as linstor, which would poll a controller that does not exist.
|
||||
_cozy_storage_backend() {
|
||||
case "${COZY_STORAGE_BACKEND:-linstor}" in
|
||||
linstor | blockstor) printf '%s\n' "${COZY_STORAGE_BACKEND:-linstor}" ;;
|
||||
*)
|
||||
echo "» ERROR: COZY_STORAGE_BACKEND must be linstor or blockstor, got '${COZY_STORAGE_BACKEND}'" >&2
|
||||
return 2
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Print `<free_kib>:<node>` for every ZFS pool that reports a free capacity.
|
||||
# The LINSTOR path asks the controller, whose `sp l` serves one outer array of
|
||||
# pool objects with free_capacity in KiB; OFFLINE satellites omit it, and the
|
||||
# DISKLESS placeholder carries a Long.MAX_VALUE sentinel, so both are skipped.
|
||||
# The blockstor path reads the StoragePool objects, whose status.freeCapacity
|
||||
# is in KiB too; there is no controller pod to exec into.
|
||||
_cozy_pool_free_rows() {
|
||||
_backend=$(_cozy_storage_backend) || return 2
|
||||
if [ "$_backend" = blockstor ]; then
|
||||
# Read first and filter second: piped, the read's status is jq's, and jq
|
||||
# on empty input succeeds.
|
||||
_pools_json=$(kubectl get storagepools.blockstor.org --request-timeout=20s -o json) || return 1
|
||||
printf '%s\n' "$_pools_json" |
|
||||
jq -r '.items[] | select((.spec.providerKind | test("^ZFS")) and .status.freeCapacity != null) | "\(.status.freeCapacity):\(.spec.nodeName)"'
|
||||
return
|
||||
fi
|
||||
# jq lives inside the controller pod (Debian-bookworm base, `sh` is dash,
|
||||
# so the script stays POSIX).
|
||||
kubectl -n cozy-linstor exec deploy/linstor-controller -- sh -c '
|
||||
linstor --machine-readable sp l 2>/dev/null |
|
||||
jq -r "first | .[] | select((.provider_kind | test(\"^ZFS\")) and .free_capacity != null) | \"\(.free_capacity):\(.node_name)\""
|
||||
'
|
||||
}
|
||||
|
||||
_cozy_pool_diagnostics() {
|
||||
if [ "$(_cozy_storage_backend 2>/dev/null)" = blockstor ]; then
|
||||
kubectl get storagepools.blockstor.org -o wide --request-timeout=20s 2>&1
|
||||
return
|
||||
fi
|
||||
kubectl -n cozy-linstor exec deploy/linstor-controller -- linstor --no-color sp l 2>&1
|
||||
}
|
||||
|
||||
# Block until every ZFS storage pool on every LINSTOR satellite reports at
|
||||
# least _min_free_gib of FreeCapacity. Motivation is proven from a
|
||||
# cozyreport artefact captured by hack/cozyreport.sh (see PR #3044 run
|
||||
@@ -524,36 +570,34 @@ cozy_wait_linstor_pool_free() {
|
||||
_timeout="${2:-300}"
|
||||
_min_free_kib=$(( _min_free_gib * 1024 * 1024 ))
|
||||
_deadline=$(( $(date +%s) + _timeout ))
|
||||
# Settled once, before polling. Inside the loop every non-zero status is a
|
||||
# read that failed and is retried: the remote jq exits 2 on the truncated or
|
||||
# error output a restarting controller can print, so no status of the read
|
||||
# can double as "give up".
|
||||
_cozy_storage_backend >/dev/null || return 2
|
||||
while :; do
|
||||
# jq lives inside the controller pod (Debian-bookworm base, `sh` is
|
||||
# dash — keep the heredoc POSIX-safe). LINSTOR's `--machine-readable`
|
||||
# output for `sp l` on LINSTOR 1.33.x is a one-element outer array
|
||||
# whose sole element is a flat array of storage-pool objects; each
|
||||
# pool object exposes free_capacity at the top level in KiB. Filter
|
||||
# to ZFS variants (both `ZFS` and `ZFS_THIN`) so DISKLESS
|
||||
# placeholders (whose free_capacity is a Long.MAX_VALUE sentinel)
|
||||
# and any future non-ZFS driver are skipped. Also guard against
|
||||
# OFFLINE satellites, whose pool objects omit free_capacity entirely
|
||||
# (StoragePool schema marks it optional) — without the null guard
|
||||
# `sort -n` would rank the string "null" ahead of real numbers and
|
||||
# the loop would silently poll to timeout. Emit
|
||||
# `<free_capacity_kib>:<node>` lines so a single sort yields the
|
||||
# smallest pool and its owner in one round-trip.
|
||||
_min_line=$(kubectl -n cozy-linstor exec deploy/linstor-controller -- sh -c '
|
||||
linstor --machine-readable sp l 2>/dev/null |
|
||||
jq -r "first | .[] | select((.provider_kind | test(\"^ZFS\")) and .free_capacity != null) | \"\(.free_capacity):\(.node_name)\"" |
|
||||
sort -n | head -n 1
|
||||
' 2>/dev/null) || _min_line=""
|
||||
# Filter to ZFS variants (both `ZFS` and `ZFS_THIN`) so DISKLESS
|
||||
# placeholders and any future non-ZFS driver are skipped, and to pools
|
||||
# that report a free capacity at all, or `sort -n` would rank a missing
|
||||
# one ahead of real numbers. The read keeps its own status: piped
|
||||
# straight into `head` it took head's, so a failed read, a 403 and a
|
||||
# pool that is genuinely full all looked alike.
|
||||
_rows_rc=0
|
||||
_rows=$(_cozy_pool_free_rows 2>/dev/null) || _rows_rc=$?
|
||||
_min_line=""
|
||||
if [ "$_rows_rc" -eq 0 ]; then
|
||||
_min_line=$(printf '%s\n' "$_rows" | grep . | sort -n | head -n 1)
|
||||
fi
|
||||
_min_kib="${_min_line%%:*}"
|
||||
_min_node="${_min_line#*:}"
|
||||
if [ -n "$_min_kib" ] && [ "$_min_kib" -ge "$_min_free_kib" ] 2>/dev/null; then
|
||||
echo "» LINSTOR ZFS pool free: smallest satellite ${_min_node} has $(( _min_kib / 1024 / 1024 )) GiB (>= ${_min_free_gib} GiB threshold)"
|
||||
echo "» ZFS pool free: smallest satellite ${_min_node} has $(( _min_kib / 1024 / 1024 )) GiB (>= ${_min_free_gib} GiB threshold)"
|
||||
return 0
|
||||
fi
|
||||
if [ "$(date +%s)" -ge "$_deadline" ]; then
|
||||
echo "» ERROR: LINSTOR ZFS pool free did not reach ${_min_free_gib} GiB on every satellite within ${_timeout}s (smallest observed: ${_min_kib:-unknown} KiB on ${_min_node:-unknown})" >&2
|
||||
echo "» ERROR: ZFS pool free did not reach ${_min_free_gib} GiB on every satellite within ${_timeout}s (smallest observed: ${_min_kib:-unknown} KiB on ${_min_node:-unknown}; last read exited ${_rows_rc})" >&2
|
||||
_pool_diag_rc=0
|
||||
_pool_diag=$(kubectl -n cozy-linstor exec deploy/linstor-controller -- linstor --no-color sp l 2>&1) || _pool_diag_rc=$?
|
||||
_pool_diag=$(_cozy_pool_diagnostics) || _pool_diag_rc=$?
|
||||
if [ "$_pool_diag_rc" -ne 0 ]; then
|
||||
echo " linstor-pool: diagnostic read failed with exit $_pool_diag_rc" >&2
|
||||
fi
|
||||
@@ -582,19 +626,34 @@ _cozy_linstor_pool_baseline_file() {
|
||||
# `data-srvN` in container mode, where every node's pool is imported into one
|
||||
# shared kernel. Every read carries its own ceiling, so a wedged controller or
|
||||
# satellite fails the poll within 35s instead of holding the caller for good.
|
||||
#
|
||||
# On the blockstor backend the pools are StoragePool objects rather than
|
||||
# controller rows, the zpool is whichever StorDriver property names it, and the
|
||||
# satellite is blockstor's own DaemonSet.
|
||||
_cozy_linstor_pool_datasets() {
|
||||
_pools=$(timeout -k 5 30 kubectl -n cozy-linstor exec deploy/linstor-controller -- sh -c '
|
||||
linstor --machine-readable sp l 2>/dev/null |
|
||||
jq -r "first | .[] | select(.provider_kind | test(\"^ZFS\")) | \"\(.node_name) \(.props[\"StorDriver/StorPoolName\"] // \"\")\""
|
||||
' 2>/dev/null) || return 1
|
||||
_backend=$(_cozy_storage_backend) || return 1
|
||||
if [ "$_backend" = blockstor ]; then
|
||||
_pools_json=$(timeout -k 5 30 kubectl get storagepools.blockstor.org --request-timeout=20s -o json 2>/dev/null) || return 1
|
||||
_pools=$(printf '%s\n' "$_pools_json" |
|
||||
jq -r '.items[] | select(.spec.providerKind | test("^ZFS")) | "\(.spec.nodeName) \(.spec.props["StorDriver/StorPoolName"] // .spec.props["StorDriver/ZPoolThin"] // .spec.props["StorDriver/ZPool"] // "")"') || return 1
|
||||
_satellite_selector=app=blockstor-satellite
|
||||
_satellite_container=satellite
|
||||
else
|
||||
_pools=$(timeout -k 5 30 kubectl -n cozy-linstor exec deploy/linstor-controller -- sh -c '
|
||||
linstor --machine-readable sp l 2>/dev/null |
|
||||
jq -r "first | .[] | select(.provider_kind | test(\"^ZFS\")) | \"\(.node_name) \(.props[\"StorDriver/StorPoolName\"] // \"\")\""
|
||||
' 2>/dev/null) || return 1
|
||||
_satellite_selector=app.kubernetes.io/component=linstor-satellite
|
||||
_satellite_container=linstor-satellite
|
||||
fi
|
||||
[ -n "$_pools" ] || return 1
|
||||
_satellites=$(timeout -k 5 30 kubectl -n cozy-linstor get pods -l app.kubernetes.io/component=linstor-satellite \
|
||||
_satellites=$(timeout -k 5 30 kubectl -n cozy-linstor get pods -l "$_satellite_selector" \
|
||||
-o jsonpath='{range .items[*]}{.spec.nodeName} {.metadata.name}{"\n"}{end}' 2>/dev/null) || return 1
|
||||
while read -r _node _zpool; do
|
||||
[ -n "$_node" ] && [ -n "$_zpool" ] || return 1
|
||||
_pod=$(printf '%s\n' "$_satellites" | awk -v node="$_node" '$1 == node { print $2; exit }')
|
||||
[ -n "$_pod" ] || return 1
|
||||
_datasets=$(timeout -k 5 30 kubectl -n cozy-linstor exec "$_pod" --container=linstor-satellite -- \
|
||||
_datasets=$(timeout -k 5 30 kubectl -n cozy-linstor exec "$_pod" --container="$_satellite_container" -- \
|
||||
zfs list -H -o name -t filesystem,volume,snapshot -r "$_zpool" </dev/null 2>/dev/null) || return 1
|
||||
[ -n "$_datasets" ] || return 1
|
||||
printf '%s\n' "$_datasets" | awk -v node="$_node" '{ print node " " $0 }'
|
||||
|
||||
@@ -181,6 +181,11 @@
|
||||
# Wait for operator to create the platform PackageSource
|
||||
timeout 120 sh -ec 'until kubectl get packagesource cozystack.cozystack-platform >/dev/null 2>&1; do sleep 2; done'
|
||||
|
||||
# The storage control plane this install deploys. Set once here and read by
|
||||
# both the generator, which passes it to the platform, and the prep, which
|
||||
# needs it to take the matching branch and will not guess.
|
||||
export COZY_STORAGE_BACKEND="${COZY_STORAGE_BACKEND:-linstor}"
|
||||
|
||||
# Stage the generated manifest instead of piping it into kubectl: cozytest
|
||||
# runs under /bin/sh without pipefail, so a generator failure in a pipeline
|
||||
# could be hidden by kubectl successfully applying empty input.
|
||||
|
||||
@@ -3,6 +3,7 @@ set -eu
|
||||
|
||||
api_server_endpoint=${COZY_APISERVER_ENDPOINT:-https://192.168.123.10:6443}
|
||||
linstor_drbd_enabled=${COZY_LINSTOR_DRBD_ENABLED:-true}
|
||||
storage_backend=${COZY_STORAGE_BACKEND:-linstor}
|
||||
|
||||
# Container-mode Talos shares the runner kernel and cannot load DRBD. Keep the
|
||||
# normal package graph for QEMU, and let that lane replace two Packages instead:
|
||||
@@ -24,6 +25,32 @@ case "$linstor_drbd_enabled" in
|
||||
;;
|
||||
esac
|
||||
|
||||
# The storage control plane the cluster installs, passed to the platform as
|
||||
# storage.backend. Blockstor creates its zpool on the QEMU lane's private
|
||||
# /dev/vdc, which the container lane does not have, so the pair is refused
|
||||
# rather than installed into a prep that cannot finish.
|
||||
case "$storage_backend" in
|
||||
linstor) ;;
|
||||
blockstor)
|
||||
if [ "$linstor_drbd_enabled" = false ]; then
|
||||
echo "COZY_STORAGE_BACKEND=blockstor is not supported with COZY_LINSTOR_DRBD_ENABLED=false" >&2
|
||||
exit 2
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "COZY_STORAGE_BACKEND must be linstor or blockstor, got: $storage_backend" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
# Only when asked: the linstor default renders the same Package it always has.
|
||||
storage_values=
|
||||
if [ "$storage_backend" = blockstor ]; then
|
||||
storage_values=' storage:
|
||||
backend: blockstor
|
||||
'
|
||||
fi
|
||||
|
||||
# Packages left out of this install. The container lane always drops the two it
|
||||
# replaces below; COZY_DISABLED_PACKAGES adds the complement computed by
|
||||
# hack/select-install.sh for the selected suites. Both land under one
|
||||
@@ -68,7 +95,7 @@ spec:
|
||||
publishing:
|
||||
host: "example.org"
|
||||
apiServerEndpoint: "$api_server_endpoint"
|
||||
# Must match Tenant/root spec.monitoring, which the install sets to
|
||||
${storage_values} # Must match Tenant/root spec.monitoring, which the install sets to
|
||||
# false. Left true, cozystack-basics renders Services into
|
||||
# cozy-monitoring, which a narrow suite selection never creates.
|
||||
monitoring:
|
||||
|
||||
@@ -57,6 +57,26 @@ validate_linstor_storage_mode() {
|
||||
esac
|
||||
}
|
||||
|
||||
# Which storage control plane the install deployed. The caller passes what it
|
||||
# installed rather than this script guessing: a probe run here would race the
|
||||
# install it runs alongside, since the namespace it would look in does not
|
||||
# exist yet when the script starts, and it would fail open to linstor on any
|
||||
# error. An unknown value is refused for the same reason the platform chart
|
||||
# refuses one: it would otherwise take whichever branch is the fallback.
|
||||
validate_storage_backend() {
|
||||
case "${COZY_STORAGE_BACKEND:-}" in
|
||||
linstor | blockstor) return 0 ;;
|
||||
"")
|
||||
echo "[post-install-prep] COZY_STORAGE_BACKEND must be set to linstor or blockstor" >&2
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
echo "[post-install-prep] COZY_STORAGE_BACKEND must be linstor or blockstor, got '${COZY_STORAGE_BACKEND}'" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# KUBECTL_BOUND prefixes the cluster calls in the helpers below with a wall-clock
|
||||
# bound. The main body sets it; it stays empty when unit tests source the
|
||||
# helpers, because `timeout` execs a binary and would bypass the kubectl shell
|
||||
@@ -132,6 +152,45 @@ patch_local_cdi_storage_profile() {
|
||||
-p '{"spec":{"claimPropertySets":[{"accessModes":["ReadWriteOnce"],"volumeMode":"Block"}]}}'
|
||||
}
|
||||
|
||||
# count_true <text>: how many lines of <text> are exactly True.
|
||||
count_true() {
|
||||
printf '%s\n' "$1" | grep -c '^True$' || true
|
||||
}
|
||||
|
||||
# count_lines <text>: how many non-empty lines <text> has.
|
||||
count_lines() {
|
||||
printf '%s\n' "$1" | grep -c . || true
|
||||
}
|
||||
|
||||
render_blockstor_node() {
|
||||
cat <<EOF
|
||||
apiVersion: blockstor.org/v1alpha1
|
||||
kind: Node
|
||||
metadata:
|
||||
name: $1
|
||||
spec:
|
||||
type: SATELLITE
|
||||
netInterfaces:
|
||||
- {name: default, address: $2}
|
||||
EOF
|
||||
}
|
||||
|
||||
# The CRD's CEL rule pins metadata.name to <poolName>.<nodeName>.
|
||||
render_blockstor_storage_pool() {
|
||||
cat <<EOF
|
||||
apiVersion: blockstor.org/v1alpha1
|
||||
kind: StoragePool
|
||||
metadata:
|
||||
name: data.$1
|
||||
spec:
|
||||
nodeName: $1
|
||||
poolName: data
|
||||
providerKind: ZFS_THIN
|
||||
props:
|
||||
StorDriver/ZPoolThin: data
|
||||
EOF
|
||||
}
|
||||
|
||||
# Unit tests source the pure helpers above without reaching a cluster.
|
||||
if [ "${E2E_POST_INSTALL_PREP_LIB:-false}" = true ]; then
|
||||
return 0 2>/dev/null || exit 0
|
||||
@@ -141,6 +200,17 @@ if ! validate_linstor_storage_mode; then
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if ! validate_storage_backend; then
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# The blockstor branch creates its zpool on the QEMU lane's private /dev/vdc.
|
||||
# The container lane has no such disk, and runs no DRBD for blockstor to drive.
|
||||
if [ "$COZY_STORAGE_BACKEND" = blockstor ] && [ "${COZY_LINSTOR_DRBD_ENABLED:-true}" = false ]; then
|
||||
echo "[post-install-prep] COZY_STORAGE_BACKEND=blockstor is not supported with COZY_LINSTOR_DRBD_ENABLED=false" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Every call that does work carries a bound, not only the waits: the caller
|
||||
# blocks in `wait` on this script, so one call that never returns holds the
|
||||
# install open until the job's own ceiling instead of failing the step. A
|
||||
@@ -281,6 +351,11 @@ wait_for_object() {
|
||||
|
||||
wait_for_linstor "linstor HelmRelease to be Ready" \
|
||||
helmrelease/linstor -n cozy-linstor --for=condition=Ready
|
||||
|
||||
echo "[post-install-prep] storage backend: $COZY_STORAGE_BACKEND"
|
||||
|
||||
if [ "$COZY_STORAGE_BACKEND" = linstor ]; then
|
||||
|
||||
wait_for_linstor "linstor-controller Deployment to be Available" \
|
||||
deployment/linstor-controller -n cozy-linstor --for=condition=available
|
||||
|
||||
@@ -331,6 +406,162 @@ for pid in $pids; do
|
||||
wait "$pid"
|
||||
done
|
||||
|
||||
else # COZY_STORAGE_BACKEND = blockstor
|
||||
|
||||
# piraeus-operator runs in external mode here: there is no in-cluster
|
||||
# linstor-controller to exec into. The zpool is made inside the
|
||||
# blockstor-satellite pod, which carries the /dev, /run/udev and /lib/modules
|
||||
# mounts libzfs needs, and the pool is then declared as a StoragePool.
|
||||
wait_for_linstor "blockstor-apiserver Deployment to be Available" \
|
||||
deployment/blockstor-apiserver -n cozy-linstor --for=condition=available
|
||||
wait_for_linstor "blockstor-controller Deployment to be Available" \
|
||||
deployment/blockstor-controller -n cozy-linstor --for=condition=available
|
||||
wait_for_linstor "LinstorCluster to be Available" \
|
||||
linstorcluster/linstorcluster --for=condition=Available
|
||||
|
||||
# Available says the operator reached the API once. It does not say a
|
||||
# satellite reconcile finished, and the two came apart in the field: the
|
||||
# operator probes /v1/controller/version before every LinstorSatellite
|
||||
# reconcile, so a probe it cannot complete leaves each satellite at
|
||||
# Applied=False with its DaemonSet frozen at a spec the chart no longer
|
||||
# renders, while every HelmRelease reports Ready. That surfaces only when a pod
|
||||
# is recreated, on a node that then loses its satellite for good, so the
|
||||
# per-satellite condition is asserted here.
|
||||
#
|
||||
# Both reads are checked: a gate comparing two counts passes on no data when
|
||||
# both reads fail and each count comes out zero. A cluster with no node is
|
||||
# not a pass either.
|
||||
echo "[post-install-prep] waiting for every LinstorSatellite to report Applied"
|
||||
applied_deadline=$(( $(date +%s) + 300 ))
|
||||
while :; do
|
||||
sat_rc=0
|
||||
sat_applied=$(timeout -k 5 30 kubectl get linstorsatellite --request-timeout=10s \
|
||||
-o jsonpath='{range .items[*]}{.status.conditions[?(@.type=="Applied")].status}{"\n"}{end}' \
|
||||
2>/dev/null) || sat_rc=$?
|
||||
node_rc=0
|
||||
node_names=$(timeout -k 5 30 kubectl get nodes --request-timeout=10s \
|
||||
-o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null) || node_rc=$?
|
||||
if [ "$sat_rc" -eq 0 ] && [ "$node_rc" -eq 0 ]; then
|
||||
node_count=$(count_lines "$node_names")
|
||||
applied_count=$(count_true "$sat_applied")
|
||||
if [ "$node_count" -gt 0 ] && [ "$applied_count" -eq "$node_count" ]; then
|
||||
break
|
||||
fi
|
||||
applied_state="$applied_count of $node_count LinstorSatellite objects Applied"
|
||||
else
|
||||
applied_state="LinstorSatellite read exited $sat_rc, Node read exited $node_rc"
|
||||
fi
|
||||
if [ "$(date +%s)" -ge "$applied_deadline" ]; then
|
||||
echo "[post-install-prep] timed out after 300s waiting for every LinstorSatellite to report Applied: $applied_state" >&2
|
||||
timeout -k 5 30 kubectl get linstorsatellite --request-timeout=10s \
|
||||
-o jsonpath='{range .items[*]}{.metadata.name}{": "}{.status.conditions[?(@.type=="Applied")].message}{"\n"}{end}' \
|
||||
2>&1 | tail -n 30 >&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
|
||||
echo "[post-install-prep] waiting for a Ready blockstor-satellite pod on each of $node_count nodes"
|
||||
sat_deadline=$(( $(date +%s) + 300 ))
|
||||
while :; do
|
||||
ready_rc=0
|
||||
sat_ready=$(timeout -k 5 30 kubectl get pods -n cozy-linstor -l app=blockstor-satellite \
|
||||
--request-timeout=10s \
|
||||
-o jsonpath='{range .items[*]}{.status.conditions[?(@.type=="Ready")].status}{"\n"}{end}' \
|
||||
2>/dev/null) || ready_rc=$?
|
||||
if [ "$ready_rc" -eq 0 ] && [ "$(count_true "$sat_ready")" -eq "$node_count" ]; then
|
||||
break
|
||||
fi
|
||||
if [ "$(date +%s)" -ge "$sat_deadline" ]; then
|
||||
echo "[post-install-prep] timed out after 300s waiting for $node_count Ready blockstor-satellite pods (read exited $ready_rc)" >&2
|
||||
timeout -k 5 30 kubectl get pods -n cozy-linstor -l app=blockstor-satellite -o wide \
|
||||
--request-timeout=10s 2>&1 | tail -n 30 >&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
|
||||
# Node CRs carrying each node's InternalIP must exist before replicated volumes
|
||||
# can resolve their DRBD peers: the label-sync controller only patches Node CRs
|
||||
# that already exist. The reads are assignments, not `for` lists, so a failed
|
||||
# one stops the script under set -e instead of registering nothing and going on.
|
||||
echo "[post-install-prep] registering blockstor Node CRs for DRBD peer resolution"
|
||||
node_rows=$($KUBECTL_BOUND kubectl get nodes --request-timeout=60s \
|
||||
-o jsonpath='{range .items[*]}{.metadata.name} {.status.addresses[?(@.type=="InternalIP")].address}{"\n"}{end}')
|
||||
if [ "$(count_lines "$node_rows")" -ne "$node_count" ]; then
|
||||
echo "[post-install-prep] expected $node_count nodes with an address, read: $node_rows" >&2
|
||||
exit 1
|
||||
fi
|
||||
while read -r node ip; do
|
||||
[ -n "$node" ] || continue
|
||||
if [ -z "$ip" ]; then
|
||||
echo "[post-install-prep] node $node has no InternalIP" >&2
|
||||
exit 1
|
||||
fi
|
||||
render_blockstor_node "$node" "$ip" | $KUBECTL_BOUND kubectl apply --request-timeout=60s -f -
|
||||
done <<EOF
|
||||
$node_rows
|
||||
EOF
|
||||
|
||||
echo "[post-install-prep] creating the 'data' zpool and StoragePool on each satellite (parallel)"
|
||||
sat_pods=$($KUBECTL_BOUND kubectl get pods -n cozy-linstor -l app=blockstor-satellite \
|
||||
--request-timeout=60s -o jsonpath='{range .items[*]}{.metadata.name} {.spec.nodeName}{"\n"}{end}')
|
||||
if [ "$(count_lines "$sat_pods")" -ne "$node_count" ]; then
|
||||
echo "[post-install-prep] expected $node_count blockstor-satellite pods, read: $sat_pods" >&2
|
||||
exit 1
|
||||
fi
|
||||
pids=""
|
||||
while read -r pod node; do
|
||||
[ -n "$pod" ] || continue
|
||||
(
|
||||
# Partition first and hand zpool the partition: a whole-disk create needs
|
||||
# a GPT rescan that fails inside the container's devtmpfs view.
|
||||
$KUBECTL_BOUND kubectl exec -n cozy-linstor "$pod" -- sh -ec '
|
||||
if zpool list data >/dev/null 2>&1; then
|
||||
echo "zpool data already exists on '"$node"'"
|
||||
exit 0
|
||||
fi
|
||||
wipefs -af /dev/vdc* 2>/dev/null || true
|
||||
sgdisk --zap-all /dev/vdc 2>/dev/null || true
|
||||
sgdisk --new=1:0:0 -t 1:bf01 /dev/vdc
|
||||
partprobe /dev/vdc 2>/dev/null || true
|
||||
sleep 1
|
||||
zpool create -f -o cachefile=none data /dev/vdc1
|
||||
echo "zpool data created on '"$node"'"
|
||||
'
|
||||
render_blockstor_storage_pool "$node" | $KUBECTL_BOUND kubectl apply --request-timeout=60s -f -
|
||||
) &
|
||||
pids="$pids $!"
|
||||
done <<EOF
|
||||
$sat_pods
|
||||
EOF
|
||||
for pid in $pids; do
|
||||
wait "$pid"
|
||||
done
|
||||
|
||||
# Applying a StoragePool only declares it. Placement counts a pool once its
|
||||
# satellite has opened the zpool and reported a free capacity, so the first
|
||||
# three-replica volume would otherwise race the satellites and fail on "not
|
||||
# enough pools" with nothing here to say why.
|
||||
echo "[post-install-prep] waiting for every satellite to report its 'data' pool"
|
||||
pool_deadline=$(( $(date +%s) + 300 ))
|
||||
while :; do
|
||||
pools_rc=0
|
||||
reported=$(timeout -k 5 30 kubectl get storagepools.blockstor.org --request-timeout=20s \
|
||||
-o jsonpath='{range .items[?(@.spec.poolName=="data")]}{.spec.nodeName} {.status.freeCapacity}{"\n"}{end}') || pools_rc=$?
|
||||
if [ "$pools_rc" -eq 0 ] && [ "$(printf '%s\n' "$reported" | awk 'NF == 2' | grep -c .)" -eq "$node_count" ]; then
|
||||
break
|
||||
fi
|
||||
if [ "$(date +%s)" -ge "$pool_deadline" ]; then
|
||||
echo "[post-install-prep] timed out after 300s waiting for $node_count reported 'data' pools (read exited $pools_rc): $reported" >&2
|
||||
timeout -k 5 30 kubectl get storagepools.blockstor.org -o yaml --request-timeout=20s 2>&1 | tail -n 80 >&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
|
||||
fi # COZY_STORAGE_BACKEND
|
||||
|
||||
echo "[post-install-prep] applying StorageClasses"
|
||||
render_linstor_storageclasses | $KUBECTL_BOUND kubectl apply --request-timeout=60s -f -
|
||||
|
||||
|
||||
@@ -704,3 +704,187 @@ idle_pool_datasets() {
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# The blockstor backend has no controller pod to exec into: the pool guard
|
||||
# reads StoragePool objects and lists datasets through blockstor's own
|
||||
# satellite. These pin that it does, and that the LINSTOR path is not touched.
|
||||
blockstor_storage_pools_json() {
|
||||
printf '%s' '{"items":[
|
||||
{"spec":{"nodeName":"srv1","providerKind":"ZFS_THIN","props":{"StorDriver/ZPoolThin":"data"}},"status":{"freeCapacity":104857600}},
|
||||
{"spec":{"nodeName":"srv1","providerKind":"DISKLESS","props":{}},"status":{}},
|
||||
{"spec":{"nodeName":"srv2","providerKind":"ZFS_THIN","props":{"StorDriver/ZPoolThin":"data"}},"status":{"freeCapacity":'"${1:-104857600}"'}},
|
||||
{"spec":{"nodeName":"srv3","providerKind":"ZFS_THIN","props":{"StorDriver/ZPoolThin":"data"}},"status":{"freeCapacity":104857600}}
|
||||
]}'
|
||||
}
|
||||
|
||||
@test "the blockstor pool floor is read from StoragePool objects, not a controller" {
|
||||
# shellcheck source=/dev/null
|
||||
. "$HACK_DIR/e2e-chainsaw/_lib/run-kubernetes.sh"
|
||||
COZY_STORAGE_BACKEND=blockstor
|
||||
calls="_out/tmp/blockstor-calls-$$"
|
||||
mkdir -p _out/tmp
|
||||
: >"$calls"
|
||||
kubectl() {
|
||||
printf '%s\n' "$*" >>"$calls"
|
||||
case "$*" in
|
||||
'get storagepools.blockstor.org '*-o\ json*) blockstor_storage_pools_json ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
fake_linstor_clock
|
||||
|
||||
rc=0
|
||||
output=$(cozy_wait_linstor_pool_free 90 300 2>&1) || rc=$?
|
||||
rm -f "$clock_file"
|
||||
unset COZY_STORAGE_BACKEND
|
||||
|
||||
if [ "$rc" -ne 0 ]; then
|
||||
echo "the blockstor floor failed on pools that all hold 100 GiB: $output" >&2
|
||||
return 1
|
||||
fi
|
||||
if grep -q 'linstor-controller' "$calls"; then
|
||||
echo "the blockstor floor reached for the LINSTOR controller" >&2
|
||||
return 1
|
||||
fi
|
||||
rm -f "$calls"
|
||||
}
|
||||
|
||||
@test "a blockstor pool below the floor fails the guard and names the node" {
|
||||
# shellcheck source=/dev/null
|
||||
. "$HACK_DIR/e2e-chainsaw/_lib/run-kubernetes.sh"
|
||||
COZY_STORAGE_BACKEND=blockstor
|
||||
kubectl() {
|
||||
case "$*" in
|
||||
'get storagepools.blockstor.org '*-o\ json*) blockstor_storage_pools_json 87127923 ;;
|
||||
*) printf 'STUB-POOL-TABLE\n' ;;
|
||||
esac
|
||||
}
|
||||
fake_linstor_clock
|
||||
|
||||
rc=0
|
||||
output=$(cozy_wait_linstor_pool_free 90 300 2>&1) || rc=$?
|
||||
rm -f "$clock_file"
|
||||
unset COZY_STORAGE_BACKEND
|
||||
|
||||
if [ "$rc" -eq 0 ]; then
|
||||
echo "the blockstor floor passed with srv2 at 83 GiB" >&2
|
||||
return 1
|
||||
fi
|
||||
if ! printf '%s\n' "$output" | grep -q '87127923 KiB on srv2'; then
|
||||
echo "the blockstor floor failure does not name the short node: $output" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@test "a pool read that fails is told apart from a full pool" {
|
||||
# shellcheck source=/dev/null
|
||||
. "$HACK_DIR/e2e-chainsaw/_lib/run-kubernetes.sh"
|
||||
COZY_STORAGE_BACKEND=blockstor
|
||||
kubectl() {
|
||||
case "$*" in
|
||||
'get storagepools.blockstor.org '*-o\ json*)
|
||||
echo 'Error from server (Forbidden): storagepools is forbidden' >&2
|
||||
return 1 ;;
|
||||
esac
|
||||
}
|
||||
fake_linstor_clock
|
||||
|
||||
rc=0
|
||||
output=$(cozy_wait_linstor_pool_free 90 300 2>&1) || rc=$?
|
||||
rm -f "$clock_file"
|
||||
unset COZY_STORAGE_BACKEND
|
||||
|
||||
if [ "$rc" -eq 0 ]; then
|
||||
echo "the floor passed on a read that failed" >&2
|
||||
return 1
|
||||
fi
|
||||
if printf '%s\n' "$output" | grep -q 'last read exited 0'; then
|
||||
echo "a failed read was reported as a successful one: $output" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@test "the blockstor dataset listing goes through blockstor's satellite" {
|
||||
# shellcheck source=/dev/null
|
||||
. "$HACK_DIR/e2e-chainsaw/_lib/run-kubernetes.sh"
|
||||
COZY_STORAGE_BACKEND=blockstor
|
||||
calls="_out/tmp/blockstor-calls-$$"
|
||||
mkdir -p _out/tmp
|
||||
: >"$calls"
|
||||
kubectl() {
|
||||
printf '%s\n' "$*" >>"$calls"
|
||||
case "$*" in
|
||||
'get storagepools.blockstor.org '*) blockstor_storage_pools_json ;;
|
||||
*'-l app=blockstor-satellite'*)
|
||||
printf 'srv1 blockstor-satellite-a\nsrv2 blockstor-satellite-b\nsrv3 blockstor-satellite-c\n' ;;
|
||||
*'--container=satellite -- zfs list'*) printf 'data\n' ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
timeout() {
|
||||
[ "${1:-}" = -k ] && [ "${3:-0}" -gt 0 ] || return 97
|
||||
shift 3
|
||||
"$@"
|
||||
}
|
||||
|
||||
rc=0
|
||||
rows=$(_cozy_linstor_pool_datasets) || rc=$?
|
||||
unset COZY_STORAGE_BACKEND
|
||||
|
||||
if [ "$rc" -ne 0 ] || [ "$rows" != "$(printf 'srv1 data\nsrv2 data\nsrv3 data')" ]; then
|
||||
echo "the blockstor dataset listing returned rc=$rc rows=$rows" >&2
|
||||
cat "$calls" >&2
|
||||
return 1
|
||||
fi
|
||||
if grep -q 'linstor-controller\|linstor-satellite' "$calls"; then
|
||||
echo "the blockstor listing reached for LINSTOR's own pods" >&2
|
||||
return 1
|
||||
fi
|
||||
rm -f "$calls"
|
||||
}
|
||||
|
||||
@test "an unknown storage backend stops the pool guard before it reads anything" {
|
||||
# shellcheck source=/dev/null
|
||||
. "$HACK_DIR/e2e-chainsaw/_lib/run-kubernetes.sh"
|
||||
COZY_STORAGE_BACKEND=blokstor
|
||||
kubectl() { printf 'UNEXPECTED_READ\n'; }
|
||||
fake_linstor_clock
|
||||
|
||||
rc=0
|
||||
output=$(cozy_wait_linstor_pool_free 90 300 2>&1) || rc=$?
|
||||
rm -f "$clock_file"
|
||||
unset COZY_STORAGE_BACKEND
|
||||
|
||||
if [ "$rc" -ne 2 ] || printf '%s\n' "$output" | grep -q UNEXPECTED_READ; then
|
||||
echo "an unknown backend was read as some backend: rc=$rc $output" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@test "a pool read that exits 2 keeps the guard polling instead of giving up" {
|
||||
# shellcheck source=/dev/null
|
||||
. "$HACK_DIR/e2e-chainsaw/_lib/run-kubernetes.sh"
|
||||
reads="_out/tmp/linstor-reads-$$"
|
||||
mkdir -p _out/tmp
|
||||
: >"$reads"
|
||||
# jq inside the controller pod exits 2 on the error banner a restarting
|
||||
# controller prints, and kubectl exec passes that status through.
|
||||
kubectl() {
|
||||
printf 'read\n' >>"$reads"
|
||||
case "$*" in
|
||||
*'exec deploy/linstor-controller'*) return 2 ;;
|
||||
esac
|
||||
}
|
||||
fake_linstor_clock
|
||||
|
||||
rc=0
|
||||
output=$(cozy_wait_linstor_pool_free 90 300 2>&1) || rc=$?
|
||||
rm -f "$clock_file"
|
||||
count=$(grep -c read "$reads")
|
||||
rm -f "$reads"
|
||||
|
||||
if [ "$rc" -ne 1 ] || [ "$count" -lt 2 ]; then
|
||||
echo "a read exiting 2 ended the guard: rc=$rc after $count read(s): $output" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -201,3 +201,44 @@ load test_helper
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
@test "the linstor default leaves the platform Package without a storage block" {
|
||||
manifest=$(hack/e2e-platform-packages.sh)
|
||||
if printf '%s\n' "$manifest" | grep -q '^ storage:'; then
|
||||
echo "the default install names a storage backend it never used to" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@test "blockstor reaches the platform as storage.backend" {
|
||||
manifest=$(COZY_STORAGE_BACKEND=blockstor hack/e2e-platform-packages.sh)
|
||||
backend=$(printf '%s\n' "$manifest" | yq 'select(.metadata.name == "cozystack.cozystack-platform") | .spec.components.platform.values.storage.backend')
|
||||
if [ "$backend" != blockstor ]; then
|
||||
echo "storage.backend is '$backend', want blockstor" >&2
|
||||
return 1
|
||||
fi
|
||||
# The block sits in the values, not inside bundles.
|
||||
bundles=$(printf '%s\n' "$manifest" | yq 'select(.metadata.name == "cozystack.cozystack-platform") | .spec.components.platform.values.bundles | keys | join(",")')
|
||||
if [ "$bundles" != enabledPackages ]; then
|
||||
echo "bundles carries '$bundles'" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@test "an unknown storage backend fails before emitting YAML" {
|
||||
if manifest=$(COZY_STORAGE_BACKEND=blokstor hack/e2e-platform-packages.sh); then
|
||||
echo "an unknown backend unexpectedly succeeded" >&2
|
||||
return 1
|
||||
fi
|
||||
if [ -n "$manifest" ]; then
|
||||
echo "an unknown backend emitted a partial manifest" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@test "blockstor on the container lane is refused" {
|
||||
if manifest=$(COZY_STORAGE_BACKEND=blockstor COZY_LINSTOR_DRBD_ENABLED=false hack/e2e-platform-packages.sh); then
|
||||
echo "blockstor without a block device unexpectedly succeeded" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -129,6 +129,39 @@ case "$*" in
|
||||
'get hr -A '*)
|
||||
echo "cozy-linstor linstor False dependency 'cozy-system/piraeus-operator' is not ready"
|
||||
echo "STUB-HR cozy-kubeovn kubeovn False install retries exhausted" ;;
|
||||
'get linstorsatellite '*)
|
||||
if [ -n "${STUB_SAT_READ_FAIL:-}" ]; then
|
||||
echo 'Error from server (Forbidden): linstorsatellites is forbidden' >&2
|
||||
exit 1
|
||||
fi
|
||||
printf '%s\n' "${STUB_SAT_APPLIED:-True True True}" | tr ' ' '\n' ;;
|
||||
'get nodes '*InternalIP*)
|
||||
if [ -n "${STUB_NODE_ROWS_FAIL:-}" ]; then
|
||||
echo 'Error from server (Forbidden): nodes is forbidden' >&2
|
||||
exit 1
|
||||
fi
|
||||
for n in ${STUB_NODES:-srv1 srv2 srv3}; do echo "$n 192.0.2.$((${#n} + 10))"; done ;;
|
||||
'get nodes '*)
|
||||
if [ -n "${STUB_NODES_READ_FAIL:-}" ]; then
|
||||
echo 'Error from server (Forbidden): nodes is forbidden' >&2
|
||||
exit 1
|
||||
fi
|
||||
for n in ${STUB_NODES:-srv1 srv2 srv3}; do echo "$n"; done ;;
|
||||
'get storagepools.blockstor.org '*freeCapacity*)
|
||||
# STUB_POOLS_UNREPORTED names nodes whose satellite has not reported its
|
||||
# pool yet: the object exists, its free capacity does not.
|
||||
for n in ${STUB_NODES:-srv1 srv2 srv3}; do
|
||||
case " ${STUB_POOLS_UNREPORTED:-} " in
|
||||
*" $n "*) echo "$n " ;;
|
||||
*) echo "$n 104857600" ;;
|
||||
esac
|
||||
done ;;
|
||||
'get pods -n cozy-linstor -l app=blockstor-satellite '*spec.nodeName*)
|
||||
for n in ${STUB_NODES:-srv1 srv2 srv3}; do echo "blockstor-satellite-$n $n"; done ;;
|
||||
'get pods -n cozy-linstor -l app=blockstor-satellite '*Ready*)
|
||||
for n in ${STUB_NODES:-srv1 srv2 srv3}; do echo True; done ;;
|
||||
'apply '*)
|
||||
cat >> "${STUB_APPLIED:-/dev/null}" ;;
|
||||
'get pods '*)
|
||||
if [ -n "${STUB_PODS_FAIL:-}" ]; then
|
||||
echo "Error from server (Forbidden): pods is forbidden" >&2
|
||||
@@ -187,6 +220,8 @@ run_prep() {
|
||||
STUB_CLOCK="$d/clock" STUB_CALLS="$d/calls" \
|
||||
STUB_HR_READY_AT=$2 STUB_DEPLOY_READY_AT=$3 \
|
||||
STUB_EVENTS_FAIL="${4:-}" STUB_PODS_FAIL="${5:-}" \
|
||||
STUB_APPLIED="$d/applied" \
|
||||
COZY_STORAGE_BACKEND="${STUB_BACKEND-linstor}" \
|
||||
PATH="$d/bin:$PATH" \
|
||||
"$SCRIPT" > "$d/out" 2> "$d/err" && echo 0 > "$d/rc" || echo $? > "$d/rc"
|
||||
}
|
||||
@@ -516,3 +551,162 @@ run_prep() {
|
||||
fi
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
# run_prep_blockstor <dir>
|
||||
# The blockstor branch. Every wait before the satellite gate is answered as
|
||||
# ready, so what a test sees is the gate and what follows it.
|
||||
run_prep_blockstor() {
|
||||
STUB_BACKEND=blockstor run_prep "$1" 0 0
|
||||
}
|
||||
|
||||
@test "the prep refuses to run without being told the storage backend" {
|
||||
tmp=$(mktemp -d)
|
||||
prep_sandbox "$tmp"
|
||||
|
||||
STUB_BACKEND="" run_prep "$tmp" 0 0
|
||||
|
||||
# A guess here races the install it runs alongside and fails open to linstor.
|
||||
[ "$(cat "$tmp/rc")" -eq 2 ]
|
||||
grep -q 'COZY_STORAGE_BACKEND must be set' "$tmp/err"
|
||||
if grep -q '^wait ' "$tmp/calls"; then
|
||||
echo "the prep waited on the cluster before it knew the backend" >&2
|
||||
return 1
|
||||
fi
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
@test "the prep refuses a storage backend it does not know" {
|
||||
tmp=$(mktemp -d)
|
||||
prep_sandbox "$tmp"
|
||||
|
||||
STUB_BACKEND=blokstor run_prep "$tmp" 0 0
|
||||
|
||||
[ "$(cat "$tmp/rc")" -eq 2 ]
|
||||
grep -q "got 'blokstor'" "$tmp/err"
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
@test "the blockstor prep registers a Node CR and a StoragePool for every node" {
|
||||
tmp=$(mktemp -d)
|
||||
prep_sandbox "$tmp"
|
||||
|
||||
run_prep_blockstor "$tmp"
|
||||
|
||||
cat "$tmp/err" >&2
|
||||
[ "$(cat "$tmp/rc")" -eq 0 ]
|
||||
grep -q '\[post-install-prep\] done' "$tmp/out"
|
||||
for n in srv1 srv2 srv3; do
|
||||
# The durable outcome, not whether a wait returned: the objects applied.
|
||||
grep -A8 '^kind: Node$' "$tmp/applied" | grep -q "^ name: $n$"
|
||||
grep -A8 '^kind: StoragePool$' "$tmp/applied" | grep -q "^ name: data.$n$"
|
||||
grep -A8 '^kind: StoragePool$' "$tmp/applied" | grep -q "^ nodeName: $n$"
|
||||
grep -q "^exec -n cozy-linstor blockstor-satellite-$n -- sh -ec" "$tmp/calls"
|
||||
done
|
||||
if grep '^UNBOUNDED ' "$tmp/calls" >&2; then
|
||||
echo "unbounded kubectl calls on the blockstor path" >&2
|
||||
return 1
|
||||
fi
|
||||
# Never the LINSTOR path's own controller.
|
||||
if grep -q 'linstor-controller' "$tmp/calls"; then
|
||||
echo "the blockstor prep reached for the LINSTOR controller" >&2
|
||||
return 1
|
||||
fi
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
@test "the blockstor prep fails when a satellite never reports Applied" {
|
||||
tmp=$(mktemp -d)
|
||||
prep_sandbox "$tmp"
|
||||
|
||||
export STUB_SAT_APPLIED="True False True"
|
||||
run_prep_blockstor "$tmp"
|
||||
unset STUB_SAT_APPLIED
|
||||
|
||||
[ "$(cat "$tmp/rc")" -ne 0 ]
|
||||
grep -q '2 of 3 LinstorSatellite objects Applied' "$tmp/err"
|
||||
if grep -q '^kind: StoragePool$' "$tmp/applied" 2>/dev/null; then
|
||||
echo "pools were created past a satellite that never applied" >&2
|
||||
return 1
|
||||
fi
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
@test "the satellite gate does not pass when both of its reads fail" {
|
||||
tmp=$(mktemp -d)
|
||||
prep_sandbox "$tmp"
|
||||
|
||||
# Two failed reads each count zero, and zero equals zero.
|
||||
export STUB_SAT_READ_FAIL=1 STUB_NODES_READ_FAIL=1
|
||||
run_prep_blockstor "$tmp"
|
||||
unset STUB_SAT_READ_FAIL STUB_NODES_READ_FAIL
|
||||
|
||||
[ "$(cat "$tmp/rc")" -ne 0 ]
|
||||
grep -q 'LinstorSatellite read exited 1, Node read exited 1' "$tmp/err"
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
@test "the satellite gate does not pass on a cluster with no node" {
|
||||
tmp=$(mktemp -d)
|
||||
prep_sandbox "$tmp"
|
||||
|
||||
export STUB_NODES=" " STUB_SAT_APPLIED=" "
|
||||
run_prep_blockstor "$tmp"
|
||||
unset STUB_NODES STUB_SAT_APPLIED
|
||||
|
||||
[ "$(cat "$tmp/rc")" -ne 0 ]
|
||||
grep -q '0 of 0 LinstorSatellite objects Applied' "$tmp/err"
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
@test "a failed node read stops the blockstor prep before it registers anything" {
|
||||
tmp=$(mktemp -d)
|
||||
prep_sandbox "$tmp"
|
||||
|
||||
# A read used as a for-list is not covered by set -e: it registers nothing
|
||||
# and the script reports done.
|
||||
export STUB_NODE_ROWS_FAIL=1
|
||||
run_prep_blockstor "$tmp"
|
||||
unset STUB_NODE_ROWS_FAIL
|
||||
|
||||
[ "$(cat "$tmp/rc")" -ne 0 ]
|
||||
if grep -q '\[post-install-prep\] done' "$tmp/out"; then
|
||||
echo "the prep reported done after a failed node read" >&2
|
||||
return 1
|
||||
fi
|
||||
if grep -q '^kind: \(Node\|StoragePool\)$' "$tmp/applied" 2>/dev/null; then
|
||||
echo "objects were registered after the node read failed" >&2
|
||||
return 1
|
||||
fi
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
@test "the blockstor prep waits for every satellite to report its pool" {
|
||||
tmp=$(mktemp -d)
|
||||
prep_sandbox "$tmp"
|
||||
|
||||
run_prep_blockstor "$tmp"
|
||||
|
||||
[ "$(cat "$tmp/rc")" -eq 0 ]
|
||||
grep -q "waiting for every satellite to report its 'data' pool" "$tmp/out"
|
||||
grep -q '^get storagepools.blockstor.org .*freeCapacity' "$tmp/calls"
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
@test "the blockstor prep fails when a satellite never reports its pool" {
|
||||
tmp=$(mktemp -d)
|
||||
prep_sandbox "$tmp"
|
||||
|
||||
# A declared pool no satellite has opened is one placement cannot use, so
|
||||
# the first three-replica volume would fail on it.
|
||||
export STUB_POOLS_UNREPORTED=srv2
|
||||
run_prep_blockstor "$tmp"
|
||||
unset STUB_POOLS_UNREPORTED
|
||||
|
||||
[ "$(cat "$tmp/rc")" -ne 0 ]
|
||||
grep -q "timed out after 300s waiting for 3 reported 'data' pools" "$tmp/err"
|
||||
if grep -q 'applying StorageClasses' "$tmp/out"; then
|
||||
echo "StorageClasses were applied over a pool nobody reported" >&2
|
||||
return 1
|
||||
fi
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
@@ -150,6 +150,8 @@ for raw in $(collect_refs); do
|
||||
# ghcr.io/cozystack — see those packages' values.yaml)
|
||||
# - ghcr.io/cozystack/ingress-nginx-with-protobuf-exporter/*, which is a
|
||||
# cozystack-org repo but sits outside $REGISTRY's path
|
||||
# - ghcr.io/cozystack/blockstor-*, released from the blockstor repository
|
||||
# under its own version (see packages/system/linstor/values.yaml)
|
||||
# - non-ref scalars, e.g. a "--migrate-image=..." arg string
|
||||
# Note kilo, kube-ovn and keycloak-operator are NOT in that list: all three
|
||||
# are built and pushed to $REGISTRY, and are selected by shapes 3 and 4. An
|
||||
|
||||
Reference in new issue
Block a user