Skip to content

Commit

Permalink
feat: Adding Support For Existing PVC (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
paimonsoror authored Nov 30, 2024
1 parent 36b1754 commit 28169ab
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 37 deletions.
2 changes: 1 addition & 1 deletion charts/vaultwarden/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ maintainers:
- name: guerzon
email: [email protected]
url: https://github.com/guerzon
version: 0.30.1
version: 0.31.0
kubeVersion: ">=1.12.0-0"
19 changes: 17 additions & 2 deletions charts/vaultwarden/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,11 @@ Detailed configuration options can be found in the [SMTP Configuration](#smtp-co

## Persistent storage

### Building Persistant Storage Through Helm

Vaultwarden requires persistent storage for its attachments and icons cache.

To use persistent storage using a claim, set the `data` dictionary. Optionally set a different path using the `path` key. The following example sets the storage class to an already-installed Rancher's [local path storage](https://github.com/rancher/local-path-provisioner) provisioner.
To use persistent storage using a claim, set the `storage.data` dictionary. Optionally set a different path using the `path` key. The following example sets the storage class to an already-installed Rancher's [local path storage](https://github.com/rancher/local-path-provisioner) provisioner.

```yaml
data:
Expand All @@ -296,7 +298,7 @@ data:
path: "/srv/vaultwarden-data"
```

To use persistent storage for attachments, set the `attachments` dictionary. Optionally set a different path. Note that by default, the path is `/data/attachments`.
To use persistent storage for attachments, set the `storage.attachments` dictionary. Optionally set a different path. Note that by default, the path is `/data/attachments`.

```yaml
attachments:
Expand All @@ -316,6 +318,19 @@ attachments:
keepPvc: true
```

### Using an Existing Persistent Volume Claim

In case you want to use an existing PVC to store your data and attachments (i.e. NAS), `storage.existingVolumeClaim` can be set
which will update the PodSpec's to use the provided PVC. Note, that use of this value will ignore the values of both `storage.data`
and `storage.attachments` values.

```yaml
existingVolumeClaim:
claimName: "vaultwarden-pvc"
dataPath: "/data"
attachmentsPath: /data/attachments
```

## Uninstall

To uninstall/delete the `vaultwarden-demo` release:
Expand Down
2 changes: 1 addition & 1 deletion charts/vaultwarden/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Determine whether to use deployment or statefulset
{{- if .Values.resourceType }}
{{- .Values.resourceType }}
{{- else }}
{{- if (and .Values.data (ne .Values.database.type "default")) }}
{{- if (and (or .Values.storage.data .Values.storage.existingVolumeClaim) (ne .Values.database.type "default")) }}
{{- "Deployment" }}
{{- else }}
{{- "StatefulSet" }}
Expand Down
24 changes: 21 additions & 3 deletions charts/vaultwarden/templates/_podSpec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,27 @@ containers:
- containerPort: 8080
name: http
protocol: TCP
{{- if or (.Values.data) (.Values.attachments) }}
{{- if .Values.storage.existingVolumeClaim }}
{{- with .Values.storage.existingVolumeClaim }}
volumeMounts:
{{- with .Values.data }}
- name: vaultwarden-data
mountPath: {{ default "/data" .dataPath }}
- name: vaultwarden-data
mountPath: {{ default "/data/attachments" .attachmentsPath }}
{{- end }}
{{- else }}
{{- if or (.Values.storage.data) (.Values.storage.attachments) }}
volumeMounts:
{{- with .Values.storage.data }}
- name: {{ .name }}
mountPath: {{ default "/data" .path }}
{{- end }}
{{- with .Values.attachments }}
{{- with .Values.storage.attachments }}
- name: {{ .name }}
mountPath: {{ default "/data/attachments" .path }}
{{- end }}
{{- end }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 6 }}
{{- with .Values.securityContext }}
Expand Down Expand Up @@ -171,6 +181,14 @@ containers:
{{- with .Values.sidecars }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- if .Values.storage.existingVolumeClaim }}
{{- with .Values.storage.existingVolumeClaim }}
volumes:
- name: vaultwarden-data
persistentVolumeClaim:
claimName: {{ .claimName }}
{{- end }}
{{- end }}
{{- if .Values.serviceAccount.create }}
serviceAccountName: {{ .Values.serviceAccount.name }}
{{- end }}
Expand Down
6 changes: 3 additions & 3 deletions charts/vaultwarden/templates/_pvcSpec.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- define "vaultwarden.pvcSpec" }}
{{- if (or .Values.data .Values.attachments) -}}
{{- if (or .Values.storage.data .Values.storage.attachments) -}}
volumeClaimTemplates:
{{- with .Values.data }}
{{- with .Values.storage.data }}
- metadata:
name: {{ .name }}
labels:
Expand All @@ -24,7 +24,7 @@ volumeClaimTemplates:
storageClassName: {{ . | quote }}
{{- end }}
{{- end }}
{{- with .Values.attachments }}
{{- with .Values.storage.attachments }}
- metadata:
name: {{ .name }}
labels:
Expand Down
8 changes: 4 additions & 4 deletions charts/vaultwarden/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ data:
SMTP_ACCEPT_INVALID_HOSTNAMES: {{ .Values.smtp.acceptInvalidHostnames | quote }}
SMTP_ACCEPT_INVALID_CERTS: {{ .Values.smtp.acceptInvalidCerts | quote }}
{{- end }}
{{- if .Values.data }}
DATA_FOLDER: {{ default "/data" .Values.data.path | quote }}
{{- if .Values.storage.data }}
DATA_FOLDER: {{ default "/data" .Values.storage.data.path | quote }}
{{- end }}
{{- if .Values.attachments }}
ATTACHMENTS_FOLDER: {{ default "/data/attachments" .Values.attachments.path | quote }}
{{- if .Values.storage.attachments }}
ATTACHMENTS_FOLDER: {{ default "/data/attachments" .Values.storage.attachments.path | quote }}
{{- end }}
ROCKET_ADDRESS: {{ .Values.rocket.address | quote }}
ROCKET_PORT: {{ .Values.rocket.port | quote }}
Expand Down
4 changes: 2 additions & 2 deletions charts/vaultwarden/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ spec:
{{- end }}
spec:
{{- include "vaultwarden.podSpec" . | nindent 6 }}
{{- range $pvc := (fromYaml (include "vaultwarden.pvcSpec" .)).volumeClaimTemplates }}
volumes:
{{- range $pvc := (fromYaml (include "vaultwarden.pvcSpec" .)).volumeClaimTemplates }}
{{- $newName := printf "%s-%s-0" $pvc.metadata.name $.Release.Name }}
- name: {{ $pvc.metadata.name }}
persistentVolumeClaim:
claimName: {{ $newName }}
{{- end }}
{{- end }}
{{- end }}
54 changes: 33 additions & 21 deletions charts/vaultwarden/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,28 +248,40 @@ podDisruptionBudget:
## @section Persistent data configuration
##

## @param data Data directory configuration, refer to values.yaml for parameters.
##
data:
{}
# name: "vaultwarden-data"
# size: "15Gi"
# class: ""
# path: "/data"
# keepPvc: false
# accessMode: "ReadWriteOnce"

## @param attachments Attachments directory configuration, refer to values.yaml for parameters.
## By default, attachments/ is located inside the data directory.
##
attachments:
{}
# name: "vaultwarden-files"
# size: "100Gi"
# class: ""
# path: /files
# keepPvc: false
# accessMode: "ReadWriteOnce"
storage:
## @param existingVolumeClaim If defined, the values here will be used for the data and
## attachments PV's. The custom values for data and attachments will be ignored if
## a value is set here
##
existingVolumeClaim:
{}
# claimName: "vaultwarden-pvc"
# dataPath: "/data"
# attachmentsPath: /data/attachments

## @param data Data directory configuration, refer to values.yaml for parameters.
##
data:
{}
# name: "vaultwarden-data"
# size: "15Gi"
# class: ""
# path: "/data"
# keepPvc: false
# accessMode: "ReadWriteOnce"

## @param attachments Attachments directory configuration, refer to values.yaml for parameters.
## By default, attachments/ is located inside the data directory.
##
attachments:
{}
# name: "vaultwarden-files"
# size: "100Gi"
# class: ""
# path: /files
# keepPvc: false
# accessMode: "ReadWriteOnce"

## @param webVaultEnabled Enable Web Vault
##
Expand Down

0 comments on commit 28169ab

Please sign in to comment.