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: add pvc creation support #67

Merged
merged 9 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
10 changes: 10 additions & 0 deletions stack/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.App
{{- end }}
{{- end }}


{{- define "service.claimName" -}}
{{- if .Values.persistence.existingClaim }}
{{- printf "%s" (tpl .Values.persistence.existingClaim $) -}}
{{- else -}}
{{- printf "%s" (include "service.fullname" .) -}}
{{- end -}}
{{- end -}}

{{/*
The default values in this chart adds httpGet probes to the deployment.
Container probes cannot have both httpGet and tcpSocket fields, so we use omit to remove one of them.
Expand All @@ -115,3 +124,4 @@ Container probes cannot have both httpGet and tcpSocket fields, so we use omit t
{{- toYaml (omit . "tcpSocket") }}
{{- end }}
{{- end }}

21 changes: 17 additions & 4 deletions stack/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ spec:
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
{{- if or (and .Values.persistence.enabled .Values.persistence.mountPath) .Values.volumeMounts}}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- if and .Values.persistence.enabled .Values.persistence.mountPath) }}
- name: data
mountPath: {{ .Values.persistence.mountPath }}
{{- end }}
{{- if .Values.volumeMounts }}
{{- toYaml .Values.volumeMounts | nindent 12 }}
{{- end }}
{{- end }}
{{- include "service.configuration" . | nindent 10}}
{{- include "service.nonsensitiveEnvVars" (list $global.Values.global .Values) | nindent 10 }}
Expand All @@ -96,9 +102,16 @@ spec:
{{- end }}
dnsPolicy: {{ .Values.dnsPolicy }}
restartPolicy: {{ .Values.restartPolicy }}
{{- with .Values.volumes }}
{{- if or .Values.persistence.enabled .Values.volumes}}
volumes:
{{- toYaml . | nindent 8 }}
{{- if .Values.persistence.enabled }}
- name: data
persistentVolumeClaim:
claimName: {{ include "service.claimName" . }}
{{- end }}
{{- if .Values.volumes }}
{{- toYaml .Values.volumes | nindent 8 }}
{{- end }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
Expand Down
33 changes: 33 additions & 0 deletions stack/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{ $global := . }}
{{ range $serviceName, $serviceValues := .Values.services }}
{{- $globalValuesDict := $global.Values.global | toYaml -}}
{{- $values := fromYaml $globalValuesDict -}}
{{- $values = set $values "name" $serviceName -}}
{{- $values := mergeOverwrite $values $serviceValues -}}
{{- $service := dict "Chart" $global.Chart "Release" $global.Release "Capabilities" $global.Capabilities "Values" $values -}}
{{- with $service -}}
---
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "service.fullname" . }}
labels:
{{- include "service.labels" . | nindent 4 }}
annotations:
{{- include "stack.annotations" $service | nindent 4 }}
spec:
accessModes:
{{- range .Values.persistence.accessModes }}
- {{ . | quote }}
{{- end }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be simplified to use toYaml?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, maybe just allow the user to specify a spec and toYaml it. That way we don't have to keep adding prs to support other features and the configuration looks more like natural k8s configuration

resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{- if .Values.persistence.storageClass }}
storageClassName: {{ .Values.persistence.storageClass }}
{{- end }}
{{- end }}
---
{{- end }}
{{- end }}
8 changes: 8 additions & 0 deletions stack/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ global:
env: []
envFrom: []

persistence:
enabled: false
storageClass: ""
accessModes:
- ReadWriteOnce
size: 8Gi
existingClaim: ""
mountPath: ""
# Service overrides
services:
{}
Expand Down
Loading