Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom volume name template using parameter #479

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dergyitheron
Copy link

PR

The goal of this PR is to open discussion and potentially implement feature that allows users to specify custom name for automatically created volumes.

Proposal

My idea is to adopt similar approach as with .parameters.pathPattern where I can define go template for generated volume name. Right now the default format is"pvc-" + string(claim.UID) implemented in the controller for external provisioners.

My proposed solution is to use .parameters.volumeNamePattern which can access the same data as the pathPattern template, and define the template there.

Example

storageClass

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-path
provisioner: rancher.io/local-path
parameters:
  pathPattern: "{{ .PVC.Namespace }}/{{ .PVC.Name }}"
  volumeNamePattern: "{{ .PVC.Annotations.volumeName }}"
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete

PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-path-pvc
  annotations:
    volumeName: local-path-pv
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: local-path
  resources:
    requests:
      storage: 128Mi

TODO

The implementation I've made for this PR is simple and just to demonstrate the idea. There are few things that I would like to do if it makes sense to continue with it.

  1. Refactor the pattern parsing and parameter detection slightly to be more polished.
  2. Check for existence of the volume with the same name - right now if I create PVC and provisioner generates name for PV which was already created for some other PVC it doesn't error out and logs the volume was created.
    • Maybe helper pod could do this check in case the volume name is already taken

Let me know what you think.

D.V.

@dergyitheron dergyitheron changed the title feat: feat: custom volume name template using parameter Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant