Skip to content

Commit 212a936

Browse files
authored
Merge pull request #32673 from RaunakShah/3151-docs
Add docs for preventing volume mode conversion
2 parents e1f79ef + b656cd8 commit 212a936

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

content/en/docs/concepts/storage/volume-snapshots.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ spec:
120120
driver: hostpath.csi.k8s.io
121121
source:
122122
volumeHandle: ee0cfb94-f8d4-11e9-b2d8-0242ac110002
123+
sourceVolumeMode: Filesystem
123124
volumeSnapshotClassName: csi-hostpath-snapclass
124125
volumeSnapshotRef:
125126
name: new-snapshot-test
@@ -141,13 +142,59 @@ spec:
141142
driver: hostpath.csi.k8s.io
142143
source:
143144
snapshotHandle: 7bdd0de3-aaeb-11e8-9aae-0242ac110002
145+
sourceVolumeMode: Filesystem
144146
volumeSnapshotRef:
145147
name: new-snapshot-test
146148
namespace: default
147149
```
148150

149151
`snapshotHandle` is the unique identifier of the volume snapshot created on the storage backend. This field is required for the pre-provisioned snapshots. It specifies the CSI snapshot id on the storage system that this `VolumeSnapshotContent` represents.
150152

153+
`sourceVolumeMode` is the mode of the volume whose snapshot is taken. The value
154+
of the `sourceVolumeMode` field can be either `Filesystem` or `Block`. If the
155+
source volume mode is not specified, Kubernetes treats the snapshot as if the
156+
source volume's mode is unknown.
157+
158+
## Converting the volume mode of a Snapshot {#convert-volume-mode}
159+
160+
If the `VolumeSnapshots` API installed on your cluster supports the `sourceVolumeMode`
161+
field, then the API has the capability to prevent unauthorized users from converting
162+
the mode of a volume.
163+
164+
To check if your cluster has capability for this feature, run the following command:
165+
166+
```yaml
167+
$ kubectl get crd volumesnapshotcontent -o yaml
168+
```
169+
170+
If you want to allow users to create a `PersistentVolumeClaim` from an existing
171+
`VolumeSnapshot`, but with a different volume mode than the source, the annotation
172+
`snapshot.storage.kubernetes.io/allowVolumeModeChange: "true"`needs to be added to
173+
the `VolumeSnapshotContent` that corresponds to the `VolumeSnapshot`.
174+
175+
For pre-provisioned snapshots, `Spec.SourceVolumeMode` needs to be populated
176+
by the cluster administrator.
177+
178+
An example `VolumeSnapshotContent` resource with this feature enabled would look like:
179+
180+
```yaml
181+
apiVersion: snapshot.storage.k8s.io/v1
182+
kind: VolumeSnapshotContent
183+
metadata:
184+
name: new-snapshot-content-test
185+
annotations:
186+
- snapshot.storage.kubernetes.io/allowVolumeModeChange: "true"
187+
spec:
188+
deletionPolicy: Delete
189+
driver: hostpath.csi.k8s.io
190+
source:
191+
snapshotHandle: 7bdd0de3-aaeb-11e8-9aae-0242ac110002
192+
sourceVolumeMode: Filesystem
193+
volumeSnapshotRef:
194+
name: new-snapshot-test
195+
namespace: default
196+
```
197+
151198
## Provisioning Volumes from Snapshots
152199

153200
You can provision a new volume, pre-populated with data from a snapshot, by using

content/en/docs/reference/labels-annotations-taints/_index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,20 @@ you through the steps you follow to apply a seccomp profile to a Pod or to one o
578578
its containers. That tutorial covers the supported mechanism for configuring seccomp in Kubernetes,
579579
based on setting `securityContext` within the Pod's `.spec`.
580580

581+
### snapshot.storage.kubernetes.io/allowVolumeModeChange
582+
583+
Example: `snapshot.storage.kubernetes.io/allowVolumeModeChange: "true"`
584+
585+
Used on: VolumeSnapshotContent
586+
587+
Value can either be `true` or `false`.
588+
This determines whether a user can modify the mode of the source volume when a
589+
{{< glossary_tooltip text="PersistentVolumeClaim" term_id="persistent-volume-claim" >}} is being
590+
created from a VolumeSnapshot.
591+
592+
Refer to [Converting the volume mode of a Snapshot](/docs/concepts/storage/volume-snapshots/#convert-volume-mode)
593+
and the [Kubernetes CSI Developer Documentation](https://kubernetes-csi.github.io/docs/) for more information.
594+
581595
## Annotations used for audit
582596

583597
<!-- sorted by annotation -->

0 commit comments

Comments
 (0)