kubernetes-csi / csi-driver-smb

This driver allows Kubernetes to access SMB Server on both Linux and Windows nodes.
Apache License 2.0
485 stars 132 forks source link

Define/influence generated PV names #814

Closed chr0n1x closed 2 months ago

chr0n1x commented 2 months ago

Hello, there's nothing in the examples as far as I can see, so Im requesting here:

Would it make sense to have some way for us to define a StorageClass with a generateName annotation?

I currently have the SMB driver/controller and longhorn installed. ALL PVs created by both CSI drivers start with pvc-......

I'd like to have all SMB-generated PVs to be prefixed with smb-pvc-... instead. Ideally, for my usecases I'd like to do something like defining a naming template e.g.: generateName: "${pod.name}-smb-pvc-"

Apologies if there's already documentation for this and I missed this.

andyzhangx commented 2 months ago

https://github.com/kubernetes-csi/csi-driver-smb/blob/master/docs/driver-parameters.md#subdir-parameter-supports-following-pvpvc-metadata-conversion

ONLY subDir parameter supports following pv/pvc metadata conversion

if subDir value contains following string, it would be converted into corresponding pv/pvc name or namespace

  • ${pvc.metadata.name}
  • ${pvc.metadata.namespace}
  • ${pv.metadata.name}
chr0n1x commented 2 months ago

Great! thanks @andyzhangx, I'll take a look!

chr0n1x commented 2 months ago

@andyzhangx sorry but I might be misunderstanding something. for chart version ~1.9, the controller isn't creating a new PersistentVolume.

My StorageClass:

---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: smb
  namespace: {{ .Release.Namespace }}
provisioner: smb.csi.k8s.io
parameters:
  source: {{ .Values.smb.host }}
  csi.storage.k8s.io/provisioner-secret-name: {{ .Values.smb.credsName | default "smbcreds" }}
  csi.storage.k8s.io/provisioner-secret-namespace: {{ .Release.Namespace }}
  csi.storage.k8s.io/node-stage-secret-name: {{ .Values.smb.credsName | default "smbcreds" }}
  csi.storage.k8s.io/node-stage-secret-namespace: {{ .Release.Namespace }}
reclaimPolicy: Retain # available values: Delete, Retain
volumeBindingMode: Immediate
mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=1001
  - gid=1001

I tried adding it as a parameter, e.g.:

parameters:
  subDir: ${pvc.metadata.name}--${pvc.metadata.namespace}/${pv.metadata.name}

note the / at the end. the controller then errors with:

'ProvisioningFailed' failed to provision volume with StorageClass "smb": rpc
error: code = Internal desc = failed to make subdirectory:
mkdir /tmp/pvc-6134acb6-0879-4eb3-acb9-b7c03f0a431a/smb-pvc--smb-pvc-example/pvc-6134acb6-0879-4eb3-acb9-b7c03f0a431a: no such file or directory

overall though, this doesn't really suit my needs. what I would really like to do is to pass in parameters from the PVC itself.

So in a separate namespace I have this PersistentVolumeClaim that I'm kubectl apply -f ...'ing:

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: smb-pvc
  namespace: smb-pvc-example
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50Mi
  storageClassName: smb

The documentation that you linked states that I can use volumeAttributes.subDir for PV/PVCs. But I can't seem to get it to work with the manifest above.

Ideally I would like to define the name of the generated PV IN the PVC itself when it uses the cluster-defined storage class smb that I defined above. So something like:

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: smb-pvc
  namespace: smb-pvc-example
  # THIS is effectively what I want
  labels:
    csi.storage.k8s.io/pv-generate-name: ${pvc.metadata.name}--${pvc.metadata.namespace}--<name of deployment that Im going to attach to>--${UUID}
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50Mi
  storageClassName: smb

is that possible at all? thanks in advance!

andyzhangx commented 2 months ago

@chr0n1x there is not supported in the upstream: https://github.com/kubernetes-csi/external-provisioner/issues/760, and / is also not allowed in subDir parameter

chr0n1x commented 2 months ago

@andyzhangx oh that issue is closed ☹️

chr0n1x commented 2 months ago

I guess they're looking for contrubutors per https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/issues/1018 . Ill close this issue, thanks for the help!