Skip to content

Commit

Permalink
Refactor deployment and secrets templates to support new structure fo…
Browse files Browse the repository at this point in the history
…r environment variables and add minReplicas to values.yaml
  • Loading branch information
qjoly committed Dec 13, 2024
1 parent a89c59a commit 5f0636d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
32 changes: 22 additions & 10 deletions charts/common/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ metadata:
labels:
app: {{ .Release.Name }}
spec:
replicas: {{ .Values.minReplicas }}
replicas: {{ .Values.deployment.minReplicas }}
selector:
matchLabels:
app: {{ .Release.Name }}
{{- with .Values.strategy }}
{{- with .Values.deployment.strategy }}
strategy:
type: {{ .type }}
rollingUpdate:
Expand Down Expand Up @@ -49,23 +49,35 @@ spec:
{{- if .Values.deployment.cpuLimit }}
cpu: "{{ .Values.deployment.cpuLimit }}"
{{- end }}
{{- if or (.Values.variables.nonSecret) (.Values.variables.secret) }}
{{- if or (.Values.variables.nonSecret) (.Values.variables.secret) (.Values.secret.existingSecret) }}
env:
{{- if .Values.variables.nonSecret }}
{{- range $index, $value := .Values.variables.nonSecret }}
{{- if .Values.variables.nonSecret }}
{{- range $index, $value := .Values.variables.nonSecret }}
- name: {{ $index }}
value: {{ $value | toString | quote }}
{{- end }}
{{- end }}
{{- if .Values.variables.secret }}
{{- range $index, $value := .Values.variables.secret }}
{{- end }}
{{- end }}
{{- if .Values.variables.secret }}
{{- range $index, $value := .Values.variables.secret }}
- name: {{ $index }}
valueFrom:
secretKeyRef:
name: {{ $dot.Release.Name }}-{{ $index | lower | replace "_" "-" }}
key: secret
{{- end }}
{{- end }}
{{- if .Values.variables.secret.existingSecret }}
{{- range $index, $value := .Values.variables.secret.existingSecret }}
- name: {{ $value.envName }}
valueFrom:
secretKeyRef:
name: {{ $value.name }}
key: {{ $value.key }}
{{- end }}
{{- end }}

{{- end }}
{{- end }}
{{- if .Values.service.enabled }}
{{- end }}
{{- if .Values.startupProbeEnabled }}
startupProbe:
Expand Down
2 changes: 1 addition & 1 deletion charts/common/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ if .Values.variables.secret }}
{{- $dot := . }}
{{- range $index, $value := .Values.variables.secret }}
{{- range $index, $value := .Values.variables.secret.data }}
apiVersion: v1
kind: Secret
metadata:
Expand Down
16 changes: 13 additions & 3 deletions charts/common/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ deployment:
memoryLimit: null
cpuLimit: null
port: *containerPort
minReplicas: 1
strategy:
type: Replace
rollingUpdate:
Expand Down Expand Up @@ -42,9 +43,18 @@ ingress:

# env variables
variables:
secret: {}
# user: "username"
# password: "hugepassword"
secret:
data: {}
# user: "username"
# password: "hugepassword"
existingSecret:
- name: "existing-secret"
key: "key"
envName: "ENV_NAME"
- name: another-existing-secret
key: key2
envName: ENV2_NAME

nonSecret: {}
# author: name
# app: 1
Expand Down

0 comments on commit 5f0636d

Please sign in to comment.