Skip to content

Commit 96c8939

Browse files
authored
Merge pull request #28610 from bswartz/volume-populators
[1.22] Volume populators redesign #1495
2 parents 85be5bb + 2fd8c14 commit 96c8939

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

content/en/docs/concepts/storage/persistent-volumes.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,82 @@ spec:
795795
storage: 10Gi
796796
```
797797

798+
## Volume populators and data sources
799+
800+
{{< feature-state for_k8s_version="v1.22" state="alpha" >}}
801+
802+
{{< note >}}
803+
Kubernetes supports custom volume populators; this alpha feature was introduced
804+
in Kubernetes 1.18. Kubernetes 1.22 reimplemented the mechanism with a redesigned API.
805+
Check that you are reading the version of the Kubernetes documentation that matches your
806+
cluster. {{% version-check %}}
807+
To use custom volume populators, you must enable the `AnyVolumeDataSource`
808+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) for
809+
the kube-apiserver and kube-controller-manager.
810+
{{< /note >}}
811+
812+
Volume populators take advantage of a PVC spec field called `dataSourceRef`. Unlike the
813+
`dataSource` field, which can only contain either a reference to another PersistentVolumeClaim
814+
or to a VolumeSnapshot, the `dataSourceRef` field can contain a reference to any object in the
815+
same namespace, except for core objects other than PVCs. For clusters that have the feature
816+
gate enabled, use of the `dataSourceRef` is preferred over `dataSource`.
817+
818+
## Data source references
819+
820+
The `dataSourceRef` field behaves almost the same as the `dataSource` field. If either one is
821+
specified while the other is not, the API server will give both fields the same value. Neither
822+
field can be changed after creation, and attempting to specify different values for the two
823+
fields will result in a validation error. Therefore the two fields will always have the same
824+
contents.
825+
826+
There are two differences between the `dataSourceRef` field and the `dataSource` field that
827+
users should be aware of:
828+
* The `dataSource` field ignores invalid values (as if the field was blank) while the
829+
`dataSourceRef` field never ignores values and will cause an error if an invalid value is
830+
used. Invalid values are any core object (objects with no apiGroup) except for PVCs.
831+
* The `dataSourceRef` field may contain different types of objects, while the `dataSource` field
832+
only allows PVCs and VolumeSnapshots.
833+
834+
Users should always use `dataSourceRef` on clusters that have the feature gate enabled, and
835+
fall back to `dataSource` on clusters that do not. It is not necessary to look at both fields
836+
under any circumstance. The duplicated values with slightly different semantics exist only for
837+
backwards compatibility. In particular, a mixture of older and newer controllers are able to
838+
interoperate because the fields are the same.
839+
840+
### Using volume populators
841+
842+
Volume populators are {{< glossary_tooltip text="controllers" term_id="controller" >}} that can
843+
create non-empty volumes, where the contents of the volume are determined by a Custom Resource.
844+
Users create a populated volume by referring to a Custom Resource using the `dataSourceRef` field:
845+
846+
```yaml
847+
apiVersion: v1
848+
kind: PersistentVolumeClaim
849+
metadata:
850+
name: populated-pvc
851+
spec:
852+
dataSourceRef:
853+
name: example-name
854+
kind: ExampleDataSource
855+
apiGroup: example.storage.k8s.io
856+
accessModes:
857+
- ReadWriteOnce
858+
resources:
859+
requests:
860+
storage: 10Gi
861+
```
862+
863+
Because volume populators are external components, attempts to create a PVC that uses one
864+
can fail if not all the correct components are installed. External controllers should generate
865+
events on the PVC to provide feedback on the status of the creation, including warnings if
866+
the PVC cannot be created due to some missing component.
867+
868+
You can install the alpha [volume data source validator](https://github.com/kubernetes-csi/volume-data-source-validator)
869+
controller into your cluster. That controller generates warning Events on a PVC in the case that no populator
870+
is registered to handle that kind of data source. When a suitable populator is installed for a PVC, it's the
871+
responsibility of that populator controller to report Events that relate to volume creation and issues during
872+
the process.
873+
798874
## Writing Portable Configuration
799875

800876
If you're writing configuration templates or examples that run on a wide range of clusters

0 commit comments

Comments
 (0)