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

Support existing persistent volume #105

Merged
merged 20 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.swp
130 changes: 67 additions & 63 deletions couchdb/README.md

Large diffs are not rendered by default.

45 changes: 43 additions & 2 deletions couchdb/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ using `lookup` and `get`. The "key", "ns", and "secretName" keys need to be prov
{{- end -}}
{{- end -}}



{{/*
Labels used to define Pods in the CouchDB statefulset
*/}}
Expand Down Expand Up @@ -102,3 +100,46 @@ Fail if couchdbConfig.couchdb.uuid is undefined
{{- define "couchdb.uuid" -}}
{{- required "A value for couchdbConfig.couchdb.uuid must be set" (.Values.couchdbConfig.couchdb | default dict).uuid -}}
{{- end -}}

{{/*
Repurpose volume claim metadata whether using the new volume claim template
or existing volume claims.
*/}}
{{- define "persistentVolume.metadata" -}}
{{- $context := index . "context" -}}
{{- $claim := index . "claim" -}}
name: {{ $claim.claimName | default "database-storage" }}
labels:
app: {{ template "couchdb.name" $context }}
release: {{ $context.Release.Name }}
{{- with $context.Values.persistentVolume.annotations }}
annotations:
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end -}}

{{/*
Repurpose volume claim spec whether using the new volume claim template
or an existing volume claim.
*/}}
{{- define "persistentVolume.spec" -}}
{{- $context := index . "context" -}}
{{- $claim := index . "claim" -}}
accessModes:
{{- range $context.Values.persistentVolume.accessModes }}
- {{ . | quote }}
{{- end }}
resources:
requests:
storage: {{ $context.Values.persistentVolume.size | quote }}
{{- if $context.Values.persistentVolume.storageClass }}
{{- if (eq "-" $context.Values.persistentVolume.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ $context.Values.persistentVolume.storageClass }}"
{{- end }}
{{- end }}
{{- if $claim.persistentVolumeName }}
volumeName: {{ $claim.persistentVolumeName }}
{{- end }}
{{- end -}}
24 changes: 24 additions & 0 deletions couchdb/templates/persistentvolume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- if and .Values.persistentVolume.enabled .Values.persistentVolume.existingClaims -}}
{{- range $claim := .Values.persistentVolume.existingClaims }}
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ $claim.persistentVolumeName }}
spec:
{{- if $.Values.persistentVolume.storageClass }}
{{- if (eq "-" $.Values.persistentVolume.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ $.Values.persistentVolume.storageClass }}"
{{- end }}
{{- end }}
accessModes:
{{- range $.Values.persistentVolume.accessModes }}
- {{ . | quote }}
{{- end }}
capacity:
storage: {{ $.Values.persistentVolume.size }}
{{ toYaml $claim.volumeSource | indent 2 }}
---
{{- end }}
{{- end }}
12 changes: 12 additions & 0 deletions couchdb/templates/persistentvolumeclaim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if and .Values.persistentVolume.enabled .Values.persistentVolume.existingClaims -}}
{{- $context := . }}
{{- range $claim := .Values.persistentVolume.existingClaims }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
{{- include "persistentVolume.metadata" (dict "context" $context "claim" $claim) | nindent 2 }}
spec:
{{- include "persistentVolume.spec" (dict "context" $context "claim" $claim) | nindent 2 }}
---
{{- end }}
{{- end }}
30 changes: 8 additions & 22 deletions couchdb/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,30 +207,16 @@ spec:
{{- if not .Values.persistentVolume.enabled }}
- name: database-storage
emptyDir: {}
{{- else if and .Values.persistentVolume.enabled .Values.persistentVolume.existingClaims }}
{{- range $claim := .Values.persistentVolume.existingClaims }}
- name: {{ $claim.volumeName }}
persistentVolumeClaim:
claimName: {{ $claim.claimName }}
{{- end }}
{{- else }}
volumeClaimTemplates:
- metadata:
name: database-storage
labels:
app: {{ template "couchdb.name" . }}
release: {{ .Release.Name }}
{{- with .Values.persistentVolume.annotations }}
annotations:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- include "persistentVolume.metadata" (dict "context" .) | nindent 8 }}
spec:
accessModes:
{{- range .Values.persistentVolume.accessModes }}
- {{ . | quote }}
{{- end }}
resources:
requests:
storage: {{ .Values.persistentVolume.size | quote }}
{{- if .Values.persistentVolume.storageClass }}
{{- if (eq "-" .Values.persistentVolume.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistentVolume.storageClass }}"
{{- end }}
{{- end }}
{{- include "persistentVolume.spec" (dict "context" .) | nindent 8 }}
{{- end }}
2 changes: 2 additions & 0 deletions couchdb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ serviceAccount:
# provisioner.
persistentVolume:
enabled: false
# NOTE: the number of existing claims must match the cluster size
existingClaims: []
annotations: {}
accessModes:
- ReadWriteOnce
Expand Down