diff --git a/packages/system/linstor/templates/_helpers.tpl b/packages/system/linstor/templates/_helpers.tpl new file mode 100644 index 000000000..c72f00420 --- /dev/null +++ b/packages/system/linstor/templates/_helpers.tpl @@ -0,0 +1,13 @@ +{{/* +Whether the cluster serves the VolumeGroupSnapshot API that csi-snapshotter and +Velero use. snapshot-controller can still serve v1alpha1 while this release +upgrades: migration 62 keeps a group snapshot CRD that holds objects, and the +snapshot-controller release stays Ready on its old revision until it upgrades. +With the gate on and the API missing, csi-snapshotter waits for its group +snapshot caches before it starts the ordinary snapshot workers. +*/}} +{{- define "linstor.groupSnapshotAPIServed" -}} +{{- if and (.Capabilities.APIVersions.Has "groupsnapshot.storage.k8s.io/v1beta2/VolumeGroupSnapshot") (.Capabilities.APIVersions.Has "groupsnapshot.storage.k8s.io/v1beta2/VolumeGroupSnapshotContent") (.Capabilities.APIVersions.Has "groupsnapshot.storage.k8s.io/v1beta2/VolumeGroupSnapshotClass") -}} +true +{{- end -}} +{{- end -}} diff --git a/packages/system/linstor/templates/cluster.yaml b/packages/system/linstor/templates/cluster.yaml index c648c0a8c..b53bfd3c3 100644 --- a/packages/system/linstor/templates/cluster.yaml +++ b/packages/system/linstor/templates/cluster.yaml @@ -89,6 +89,16 @@ spec: containers: - name: linstor-csi image: {{ .Values.linstorCSI.image.repository }}:{{ .Values.linstorCSI.image.tag }} + {{- /* piraeus-operator probes groupsnapshot.storage.k8s.io/v1beta2 + once, when it starts, and only for VolumeGroupSnapshot. Its + answer goes stale when the CRDs change after it started, and it + turns the gate on when that one kind is served without the + content or class kind. The gate is therefore always decided + here, from all three kinds. */}} + - name: csi-snapshotter + env: + - name: FEATURE_GATE_CSI_VOLUME_GROUP_SNAPSHOT + value: {{ include "linstor.groupSnapshotAPIServed" . | default "false" | quote }} {{- if .Values.linstorCSI.strictTopology }} {{- /* A `#` comment in a rendered template is part of the output: it is applied to the live LinstorCluster and read back on every diff --git a/packages/system/linstor/templates/volumegroupsnapshotclass.yaml b/packages/system/linstor/templates/volumegroupsnapshotclass.yaml new file mode 100644 index 000000000..bae3416cd --- /dev/null +++ b/packages/system/linstor/templates/volumegroupsnapshotclass.yaml @@ -0,0 +1,12 @@ +{{- if include "linstor.groupSnapshotAPIServed" . }} +apiVersion: groupsnapshot.storage.k8s.io/v1beta2 +kind: VolumeGroupSnapshotClass +metadata: + annotations: + groupsnapshot.storage.kubernetes.io/is-default-class: "true" + labels: + velero.io/csi-volumegroupsnapshot-class: "true" + name: linstor-group-snapshots +driver: linstor.csi.linbit.com +deletionPolicy: Delete +{{- end }} diff --git a/packages/system/linstor/tests/csi-topology_test.yaml b/packages/system/linstor/tests/csi-topology_test.yaml index 6dd9bb3ea..1b346a93e 100644 --- a/packages/system/linstor/tests/csi-topology_test.yaml +++ b/packages/system/linstor/tests/csi-topology_test.yaml @@ -55,7 +55,10 @@ tests: asserts: - lengthEqual: path: spec.csiController.podTemplate.spec.containers - count: 1 + count: 2 - equal: path: spec.csiController.podTemplate.spec.containers[0].name value: linstor-csi + - equal: + path: spec.csiController.podTemplate.spec.containers[1].name + value: csi-snapshotter diff --git a/packages/system/linstor/tests/volume_group_snapshot_test.yaml b/packages/system/linstor/tests/volume_group_snapshot_test.yaml new file mode 100644 index 000000000..096dfd8b6 --- /dev/null +++ b/packages/system/linstor/tests/volume_group_snapshot_test.yaml @@ -0,0 +1,95 @@ +suite: VolumeGroupSnapshot support for linstor-csi + +# piraeus-operator decides FEATURE_GATE_CSI_VOLUME_GROUP_SNAPSHOT for the +# csi-snapshotter sidecar from an API probe it runs only at startup, so an +# operator that started before snapshot-controller served +# groupsnapshot.storage.k8s.io/v1beta2 leaves the gate off. The podTemplate +# always sets it, on only when all three v1beta2 kinds are served: the probe +# checks VolumeGroupSnapshot alone, and the gate on without the content or class +# API stalls csi-snapshotter. The VolumeGroupSnapshotClass carries the label +# Velero selects a group snapshot class by, and is not rendered while the API is +# missing, where it would fail the upgrade. + +tests: + - it: "csi-snapshotter gets the CSIVolumeGroupSnapshot gate once v1beta2 is served" + template: templates/cluster.yaml + capabilities: &v1beta2 + apiVersions: + - groupsnapshot.storage.k8s.io/v1beta2/VolumeGroupSnapshot + - groupsnapshot.storage.k8s.io/v1beta2/VolumeGroupSnapshotContent + - groupsnapshot.storage.k8s.io/v1beta2/VolumeGroupSnapshotClass + asserts: + - contains: + path: spec.csiController.podTemplate.spec.containers + content: + name: csi-snapshotter + env: + - name: FEATURE_GATE_CSI_VOLUME_GROUP_SNAPSHOT + value: "true" + + - it: "csi-snapshotter gate is kept when strict topology is disabled" + template: templates/cluster.yaml + capabilities: *v1beta2 + set: + linstorCSI: + strictTopology: false + asserts: + - contains: + path: spec.csiController.podTemplate.spec.containers + content: + name: csi-snapshotter + env: + - name: FEATURE_GATE_CSI_VOLUME_GROUP_SNAPSHOT + value: "true" + + - it: "csi-snapshotter gate is off when only VolumeGroupSnapshot serves v1beta2" + template: templates/cluster.yaml + capabilities: + apiVersions: + - groupsnapshot.storage.k8s.io/v1beta2/VolumeGroupSnapshot + asserts: + - contains: + path: spec.csiController.podTemplate.spec.containers + content: + name: csi-snapshotter + env: + - name: FEATURE_GATE_CSI_VOLUME_GROUP_SNAPSHOT + value: "false" + + - it: "csi-snapshotter gate is off when the API is not served at all" + template: templates/cluster.yaml + asserts: + - contains: + path: spec.csiController.podTemplate.spec.containers + content: + name: csi-snapshotter + env: + - name: FEATURE_GATE_CSI_VOLUME_GROUP_SNAPSHOT + value: "false" + + - it: "linstor VolumeGroupSnapshotClass is the default class Velero selects" + template: templates/volumegroupsnapshotclass.yaml + capabilities: *v1beta2 + asserts: + - isKind: + of: VolumeGroupSnapshotClass + - isAPIVersion: + of: groupsnapshot.storage.k8s.io/v1beta2 + - equal: + path: driver + value: linstor.csi.linbit.com + - equal: + path: deletionPolicy + value: Delete + - equal: + path: metadata.labels["velero.io/csi-volumegroupsnapshot-class"] + value: "true" + - equal: + path: metadata.annotations["groupsnapshot.storage.kubernetes.io/is-default-class"] + value: "true" + + - it: "no VolumeGroupSnapshotClass while v1beta2 is not served" + template: templates/volumegroupsnapshotclass.yaml + asserts: + - hasDocuments: + count: 0