diff --git a/README.md b/README.md index 0d1c5a1..e3857c3 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,15 @@ A NFS persistent volume static provisioner, which allows you to quickly bind an ## Description The provisioner listens PVC CREATE and UPDATE events, when the PVC has demanded annotations, the provisioner will create/update a NFS PV and bind it with the PVC automatically. -| Annotation | Required | Default Value | Explanation | Example Values | -|--------------------------------------------|----------|---------------|--------------------------------------------------------------|-----------------------------------------| -| storage.kubesphere.io/nfs-static-provision | Y | "false" | must set to "true" in order to use this provisioner | "true" | -| storage.kubesphere.io/nfs-server | Y | "" | nfs server hostname or IP address (PV.spec.nfs.server) | "example.nfs.server.com", "192.168.0.5" | -| storage.kubesphere.io/nfs-path | Y | "" | nfs volume absolute path (PV.spec.nfs.path) | "/exports/volume1" | -| storage.kubesphere.io/nfs-readonly | N | "false" | whether the volume is read-only (PV.spec.nfs.readOnly) | "false", "true" | -| storage.kubesphere.io/reclaim-policy* | N | "Delete" | reclaim policy of PV (PV.spec.persistentVolumeReclaimPolicy) | "Delete", "Retain" | -| storage.kubesphere.io/mount-options | N | "" | mount options of PV (PV.spec.mountOptions) | `"[\"nfsvers=3\",\"nolock\",\"hard\"]"` | +| Annotation | Required | Default Value | Explanation | Example Values | +|--------------------------------------------|----------|----------------------|--------------------------------------------------------------|-----------------------------------------| +| storage.kubesphere.io/nfs-static-provision | Y | "false" | must set to "true" in order to use this provisioner | "true" | +| storage.kubesphere.io/nfs-server | Y | "" | nfs server hostname or IP address (PV.spec.nfs.server) | "example.nfs.server.com", "192.168.0.5" | +| storage.kubesphere.io/nfs-path | Y | "" | nfs volume absolute path (PV.spec.nfs.path) | "/exports/volume1" | +| storage.kubesphere.io/nfs-readonly | N | "false" | whether the volume is read-only (PV.spec.nfs.readOnly) | "false", "true" | +| storage.kubesphere.io/reclaim-policy* | N | "Delete" | reclaim policy of PV (PV.spec.persistentVolumeReclaimPolicy) | "Delete", "Retain" | +| storage.kubesphere.io/mount-options | N | "" | mount options of PV (PV.spec.mountOptions) | `"[\"nfsvers=3\",\"nolock\",\"hard\"]"` | +| storage.kubesphere.io/pv-name | N | "pvc-${random uuid}" | PV name | "nfs-pv-1" | - *When reclaim policy is "Delete", the PV will be deleted when the PVC is deleted. However, this only affects the PV resource in k8s cluster, the real backend volume on NFS server still exists. diff --git a/internal/controller/nfs.go b/internal/controller/nfs.go index 125040e..525dc5e 100644 --- a/internal/controller/nfs.go +++ b/internal/controller/nfs.go @@ -13,6 +13,7 @@ import ( ) const ( + AnnotationPVName = "storage.kubesphere.io/pv-name" AnnotationNFSStaticProvision = "storage.kubesphere.io/nfs-static-provision" AnnotationNFSServer = "storage.kubesphere.io/nfs-server" AnnotationNFSPath = "storage.kubesphere.io/nfs-path" @@ -94,8 +95,8 @@ func (p NFSPVC) ParsePV() (*corev1.PersistentVolume, error) { } } - name := p.Spec.VolumeName - if name == "" { + name, ok := p.Annotations[AnnotationPVName] + if !ok || name == "" { name = fmt.Sprintf("pvc-%s", uuid.NewUUID()) }