Files
cozystack/hack/testdata
Aleksei Sviridkin f5ceed0e24 feat(linstor, platform): upgrade snapshot-controller to v8.7.0 and enable VolumeGroupSnapshots (#5239)
## What this PR does

Windows VMs with three or more disks cannot get an
application-consistent Velero backup on Cozystack today. Velero takes
one CSI snapshot per PVC, one after the other, while virt-freezer holds
the guest frozen, and on LINSTOR each snapshot takes 2 to 4 s. With
three disks or more the freeze runs past the 10 s that Windows VSS
allows, VSS aborts with `0x80042314`, and the backup fails. The only
workaround is `kubevirt.io/skip-backup-hooks=true` on the VM, which
gives up application consistency.

The fix is a VolumeGroupSnapshot: one snapshot request for all the PVCs
of a VM, taken inside the freeze. linstor-csi has implemented the CSI
GroupController since v1.11 (the package ships v1.11.2), and it creates
the whole group in a single LINSTOR `Resources.CreateSnapshots` call, so
every volume of the VM is captured at the same instant and the freeze
lasts one snapshot instead of N. Velero 1.18 drives VolumeGroupSnapshots
through `groupsnapshot.storage.k8s.io/v1beta2`. What is missing is on
the Cozystack side: snapshot-controller v8.0.1 serves the group snapshot
API only as v1alpha1 and runs without the `CSIVolumeGroupSnapshot` gate,
and piraeus-operator turns the gate off on the csi-snapshotter sidecar
when it does not find v1beta2.

This PR:

- Upgrades the vendored Piraeus `snapshot-controller` chart from 3.0.5
(v8.0.1) to 5.4.0 (v8.7.0) with the package's `make update`. The
`snapshot.storage.k8s.io` CRDs stay at v1. The
`groupsnapshot.storage.k8s.io` CRDs go from v1alpha1 only to v1beta1,
v1beta2 and v1, with v1beta2 as the storage version. The controller runs
with `--feature-gates=CSIVolumeGroupSnapshot=true`, the chart's default.
The validating webhook is gone upstream, replaced by CEL rules in the
CRDs. The new optional conversion webhook stays disabled, as upstream
ships it, since no cluster holds group snapshot objects to convert.
- Sets `keepCRDs: true`. The chart now renders its CRDs from a template
instead of `crds/`, so without it an uninstall of the release would
delete every VolumeSnapshot with the CRDs.
- Patches the vendored CRD template (`patches/skip-foreign-crds.diff`,
applied by `make update`) so a CRD is rendered only when it is absent or
already carries this release's `meta.helm.sh/release-name` and
`meta.helm.sh/release-namespace`. A CRD a distribution ships, or that
another release owns, stays out of the manifest, so helm-controller
neither takes it over nor rewrites it on upgrade. On a fresh install,
and for the CRDs migration 62 adopts, the output is unchanged.
- Adds migration 62 and bumps `migrations.targetVersion` to 63
(renumbered from 61 after upstream took migration 61 for the Strimzi v1
conversion). The CRDs `crds/` created carry no Helm ownership metadata,
and the patched chart renders only the CRDs that do, so the migration
annotates the three `snapshot.storage.k8s.io` CRDs the release installed
for adoption, which keeps them in its manifest. The three group snapshot
CRDs cannot be adopted: the apiserver rejects an update that drops
v1alpha1 while it is listed in `status.storedVersions`. The old
controller never ran with the gate, so no v1alpha1 object was ever acted
on, and the migration deletes each of these CRDs when it is empty and
creates it again straight away at v1beta2, from copies `make
image-migrations` renders out of the snapshot-controller chart with the
release's ownership metadata (as it already bakes the etcd-operator CRDs
for migration 50). Every HelmRelease waits for this pre-upgrade hook, so
the linstor release renders against the v1beta2 API even when it
upgrades before snapshot-controller. A CRD that still holds objects is
kept and recorded on the `cozystack-version` ConfigMap as
`cozystack.io/migration-62-needs-attention`, and the CRD stays out of
the release, which carries no Helm ownership on it, so
snapshot-controller still upgrades with that group snapshot API at
v1alpha1 and group snapshots off. Nothing re-renders either release once
the CRD is cleaned up, so the migration's warning gives the whole
recovery: delete the objects and the CRD, force a snapshot-controller
HelmRelease upgrade so the chart creates the CRD at v1beta2, restart the
snapshot-controller Deployment, which sets up its group snapshot watches
only when it starts, then force a linstor HelmRelease upgrade. The
migration only touches CRDs that helm-controller labelled as installed
by `cozy-snapshot-controller/snapshot-controller`, and the chart leaves
the others out of the release, so a distribution that ships its own
snapshot CRDs keeps them in both places. Whether the release is
installed is read from its HelmRelease rather than from those labels, so
a retry after a failed create still recreates the group CRDs it deleted
when only they carried the labels; without the HelmRelease the migration
changes nothing. The version is stamped only once every release-owned
v1beta2 group snapshot CRD is Established, whichever path brought it
there, so a retry after a timed-out wait waits again rather than letting
linstor render before the API is served.
- Sets `FEATURE_GATE_CSI_VOLUME_GROUP_SNAPSHOT=true` on the linstor-csi
`csi-snapshotter` sidecar through the LinstorCluster pod template.
piraeus-operator v2.10.2 probes for the v1beta2 API once, when it
starts, and adds a patch that sets the variable to `false` when the
probe fails. On a cluster upgraded from v1alpha1 the operator started
before the new CRDs existed, so the gate would stay off until the
operator next restarted. The pod template is merged after the operator's
own patch. The variable is always set, to `true` only when the apiserver
serves all three `groupsnapshot.storage.k8s.io/v1beta2` kinds and to
`false` otherwise: the operator's probe looks at VolumeGroupSnapshot
alone, and csi-snapshotter with the gate on and a group API missing
waits for its group snapshot caches before it starts the ordinary
snapshot workers. The class below renders under the same check.
- Adds a default `VolumeGroupSnapshotClass` `linstor-group-snapshots`
for `linstor.csi.linbit.com`, next to the existing `linstor-snapshots`
VolumeSnapshotClass, with the `velero.io/csi-volumegroupsnapshot-class:
"true"` label Velero selects a group snapshot class by. Only on a
cluster where migration 62 kept a populated v1alpha1 CRD do they wait
for the forced linstor upgrade at the end of that recovery.

Not in this PR: grouping a VM's PVCs for Velero. Velero builds a group
from the PVCs that share the value of the `velero.io/volume-group`
label, so the `vm-instance` and `vm-disk` charts would have to set it to
the VM name on every disk. That is a separate change, and an operator
can set the label by hand meanwhile.

Testing:

- Kubernetes v1.34.3, Velero 1.18.1, linstor-csi v1.11.2,
piraeus-operator v2.10.2. On that cluster the group snapshot CRDs are
v1alpha1 only, list `["v1alpha1"]` in `storedVersions`, hold no object,
and carry the helm-controller labels of
`cozy-snapshot-controller/snapshot-controller`. The csi-snapshotter
sidecar runs with `FEATURE_GATE_CSI_VOLUME_GROUP_SNAPSHOT=false`, set by
the operator's patch.
- `hack/migration-62-snapshot-crds.bats` (16 cases) runs migration 62 in
the migrations base image against a fake kubectl that keeps the CRDs in
a state file: adoption and deletion, a second run that changes nothing,
a CRD holding objects, CRDs another installer owns, CRDs that already
serve v1beta2, a cluster without the release, a release without the
group CRDs, a failing HelmRelease read, CRD read or delete that aborts
before the stamp, a failed diagnostic record that still stamps, a failed
create that aborts and is completed by the retry, release labels on the
group CRDs alone, with and without a failed first create, a timed-out
Established wait whose retry must wait again before stamping, and a
v1beta2 CRD that still stores v1alpha1, which is recorded rather than
adopted. With the delete removed from the migration, the first case
fails; with the release identity taken from the CRD labels instead of
the HelmRelease, the failed-create case with group-only labels stamps 63
without recreating the CRDs and fails. Without the wait on the adoption
path, the timed-out-wait case stamps 63 on the retry without waiting and
fails.
- New helm-unittest suites:
`packages/system/snapshot-controller/tests/crds_test.yaml` pins
`keepCRDs`, v1beta2 served and stored on the three group snapshot CRDs
and the controller gate;
`packages/system/snapshot-controller/tests/crd_ownership_test.yaml`
mocks the live CRDs and checks that one without Helm ownership and one
owned by another release are left out while an absent one and one this
release owns are rendered (it fails with the patch reverted);
`packages/system/linstor/tests/volume_group_snapshot_test.yaml` pins the
sidecar gate on with and without strict topology, off when only
VolumeGroupSnapshot or no group API is served, and the
VolumeGroupSnapshotClass rendered only when the v1beta2 API is served.
`csi-topology_test.yaml` now counts the `csi-snapshotter` entry in the
pod template.
- `helm unittest` passes for `packages/system/linstor` (30 tests),
`packages/system/snapshot-controller` (7) and `packages/core/platform`
(285). `hack/cozystack-version-stamp.bats` and
`hack/check-migrations-target.sh` pass.
- Not yet run end to end: the upgrade of a live cluster through
migration 62, and a Velero backup with a VolumeGroupSnapshot through
linstor-csi.

### Screenshots

Not a UI change.

### Downstream repositories

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

The only change to `packages/core/platform/values.yaml` is the value of
`migrations.targetVersion`. The website's `platform-package.md` lists
that key without a value, so it needs no change. No website page
mentions VolumeGroupSnapshots or documents the snapshot-controller
webhook. The rest of the diff is a vendored chart, two system packages,
a migration and its tests, none of which the trigger map reaches.

### Release note

```release-note
feat(platform): snapshot-controller is upgraded to v8.7.0 and serves VolumeGroupSnapshots as groupsnapshot.storage.k8s.io/v1beta2, and linstor-csi takes group snapshots with a default VolumeGroupSnapshotClass labelled for Velero. A platform migration hands the snapshot CRDs over to the release and removes the empty v1alpha1 group snapshot CRDs.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Added LINSTOR volume group snapshot support when all required APIs are
available, including a default snapshot class.
* Updated the snapshot controller to support newer snapshot APIs and a
conversion webhook.
* Added safer CRD installation and upgrade handling, preserving CRDs
with existing objects and recording items that need attention.

* **Bug Fixes**
* Improved snapshot-controller upgrade reliability, including recovery
from certain CRD creation failures.

* **Documentation**
* Updated chart guidance for CRD management, conversion webhooks, and
snapshot class configuration.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-23 14:12:46 +03:00
..