From e5e15f922cc47b969b5e641d26d9477e9cb95027 Mon Sep 17 00:00:00 2001 From: Aleksandr Cupacenko Date: Mon, 2 Dec 2024 13:51:00 +0200 Subject: [PATCH] refactor persistent volume configuration (#565) Co-authored-by: Aleksandr Cupacenko --- charts/helm-dashboard/README.md | 3 +- charts/helm-dashboard/templates/pvc.yaml | 43 ++++--------------- charts/helm-dashboard/values.yaml | 14 +++--- .../cypress/fixtures/defaultReleases.json | 6 ++- 4 files changed, 24 insertions(+), 42 deletions(-) diff --git a/charts/helm-dashboard/README.md b/charts/helm-dashboard/README.md index e57db250..9be30b01 100644 --- a/charts/helm-dashboard/README.md +++ b/charts/helm-dashboard/README.md @@ -75,7 +75,8 @@ The following table lists the configurable parameters of the chart and their def | `dashboard.persistence.accessModes` | Persistent Volume access modes | `["ReadWriteOnce"]` | | `dashboard.persistence.storageClass` | Persistent Volume storage class | `""` | | `dashboard.persistence.size` | Persistent Volume size | `100M` | -| `dashboard.persistence.hostPath` | Set path in case you want to use local host path volumes (not recommended in production) | `""` | +| `dashboard.persistence.finalizers` | Finalizers for the Persistent Volume Claim | `[kubernetes.io/pvc-protection]` | +| `dashboard.persistence.lookupVolumeName` | Lookup volume name for the Persistent Volume Claim | `true` | | `updateStrategy.type` | Set up update strategy for helm-dashboard installation. | `RollingUpdate` | | `extraArgs` | Set the arguments to be supplied to the helm-dashboard binary | `[--no-browser, --bind=0.0.0.0]` | | `testImage.repository` | Test image registry/name | `busybox` | diff --git a/charts/helm-dashboard/templates/pvc.yaml b/charts/helm-dashboard/templates/pvc.yaml index 68e0df39..e8662d4e 100644 --- a/charts/helm-dashboard/templates/pvc.yaml +++ b/charts/helm-dashboard/templates/pvc.yaml @@ -10,47 +10,22 @@ metadata: annotations: {{- toYaml . | nindent 4 }} {{- end }} -spec: - {{- if .Values.dashboard.persistence.hostPath }} - storageClassName: "" - {{- else }} - {{- if kindIs "string" .Values.dashboard.persistence.storageClass }} - storageClassName: "{{ .Values.dashboard.persistence.storageClass }}" - {{- end }} + {{- with .Values.dashboard.persistence.finalizers }} + finalizers: + {{- toYaml . | nindent 4 }} {{- end }} +spec: accessModes: - {{- if not (empty .Values.dashboard.persistence.accessModes) }} {{- range .Values.dashboard.persistence.accessModes }} - {{ . | quote }} {{- end }} - {{- end }} resources: requests: storage: {{ .Values.dashboard.persistence.size | quote }} -{{- end }} - ---- -{{- if and .Values.dashboard.persistence.enabled .Values.dashboard.persistence.hostPath -}} -apiVersion: v1 -kind: PersistentVolume -metadata: - name: {{ include "helm-dashboard.fullname" . }} - namespace: {{ .Release.Namespace | quote }} - labels: - {{- include "helm-dashboard.labels" . | nindent 4 }} - {{- with .Values.dashboard.persistence.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -spec: - accessModes: - {{- if not (empty .Values.dashboard.persistence.accessModes) }} - {{- range .Values.dashboard.persistence.accessModes }} - - {{ . | quote }} + {{- if and (.Values.dashboard.persistence.lookupVolumeName) (lookup "v1" "PersistentVolumeClaim" .Release.Namespace (include "helm-dashboard.fullname" .)) }} + volumeName: {{ (lookup "v1" "PersistentVolumeClaim" .Release.Namespace (include "helm-dashboard.fullname" .)).spec.volumeName }} {{- end }} + {{- with .Values.dashboard.persistence.storageClassName }} + storageClassName: {{ . }} {{- end }} - capacity: - storage: {{ .Values.dashboard.persistence.size | quote }} - hostPath: - path: {{ .Values.dashboard.persistence.hostPath | quote }} -{{- end -}} +{{- end }} diff --git a/charts/helm-dashboard/values.yaml b/charts/helm-dashboard/values.yaml index 516b80bc..d9ecfccf 100644 --- a/charts/helm-dashboard/values.yaml +++ b/charts/helm-dashboard/values.yaml @@ -49,12 +49,11 @@ dashboard: enabled: true ## If defined, storageClassName: - ## If set to "-", storageClassName: "", which disables dynamic provisioning ## If undefined (the default) or set to null, no storageClassName spec is ## set, choosing the default provisioner. (gp2 on AWS, standard on ## GKE, AWS & OpenStack) ## - storageClass: null + # storageClassName: default ## Helm Dashboard Persistent Volume access modes ## Must match those of existing PV or dynamic provisioner @@ -71,14 +70,19 @@ dashboard: ## annotations: {} - ## Set path in case you want to use local host path volumes (not recommended in production) + ## Finalizer to ensure PVC is not deleted until the pod is terminated ## - hostPath: "" + finalizers: + - kubernetes.io/pvc-protection ## Helm Dashboard data Persistent Volume size ## size: 100M - + + ## If 'lookupVolumeName' is set to true, Helm will attempt to retrieve + ## the current value of 'spec.volumeName' and incorporate it into the template. + lookupVolumeName: true + ## @param.updateStrategy.type Set up update strategy for helm-dashboard installation. ## Set to Recreate if you use persistent volume that cannot be mounted by more than one pods to make sure the pods is destroyed first. ## ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy diff --git a/frontend/cypress/fixtures/defaultReleases.json b/frontend/cypress/fixtures/defaultReleases.json index 9a352775..73e68c0a 100644 --- a/frontend/cypress/fixtures/defaultReleases.json +++ b/frontend/cypress/fixtures/defaultReleases.json @@ -74,12 +74,14 @@ }, "enabled":true, - "hostPath":"", "labels":{ }, "size":"100M", - "storageClass":null + "finalizers":[ + "kubernetes.io/pvc-protection" + ], + "lookupVolumeName": true } }, "debug":false,