Skip to content

Commit 2fd8c14

Browse files
committed
[1.22] Volume populators redesign #1495
Add dataSourceRef documentation
1 parent 2923e6b commit 2fd8c14

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
@@ -785,6 +785,82 @@ spec:
785785
storage: 10Gi
786786
```
787787

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

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

0 commit comments

Comments
 (0)