Skip to content

Commit

Permalink
Update orders helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
niallthomson committed Jan 3, 2024
1 parent 9c6a185 commit 9e3f6db
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 144 deletions.
40 changes: 12 additions & 28 deletions deploy/kubernetes/charts/orders/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ Create the name of the config map to use
{{- end }}
{{- end -}}

{{- define "orders.mysql.fullname" -}}
{{- define "orders.postgresql.fullname" -}}
{{- include "orders.fullname" . }}-mysql
{{- end -}}

{{/*
Common labels for mysql
*/}}
{{- define "orders.mysql.labels" -}}
{{- define "orders.postgresql.labels" -}}
helm.sh/chart: {{ include "orders.chart" . }}
{{ include "orders.mysql.selectorLabels" . }}
{{ include "orders.postgresql.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand All @@ -105,7 +105,7 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{/*
Selector labels for mysql
*/}}
{{- define "orders.mysql.selectorLabels" -}}
{{- define "orders.postgresql.selectorLabels" -}}
app.kubernetes.io/name: {{ include "orders.fullname" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: mysql
Expand All @@ -123,35 +123,19 @@ app.kubernetes.io/component: mysql
{{- end -}}
{{- end }}

{{- define "orders.mysql.password" -}}
{{- if not (empty .Values.mysql.secret.password) -}}
{{- .Values.mysql.secret.password | b64enc -}}
{{- define "orders.postgresql.password" -}}
{{- if not (empty .Values.postgresql.secret.password) -}}
{{- .Values.postgresql.secret.password | b64enc -}}
{{- else -}}
{{- include "getOrGeneratePass" (dict "Namespace" .Release.Namespace "Kind" "Secret" "Name" .Values.mysql.secret.name "Key" "password") -}}
{{- include "getOrGeneratePass" (dict "Namespace" .Release.Namespace "Kind" "Secret" "Name" .Values.postgresql.secret.name "Key" "password") -}}
{{- end -}}
{{- end -}}

{{- define "orders.mysql.reader.password" -}}
{{- if not (empty .Values.mysql.reader.secret.password) -}}
{{- .Values.mysql.reader.secret.password | b64enc -}}
{{- define "orders.postgresql.endpoint" -}}
{{- if not (empty .Values.postgresql.endpoint) -}}
{{- .Values.postgresql.endpoint -}}
{{- else -}}
{{- include "getOrGeneratePass" (dict "Namespace" .Release.Namespace "Kind" "Secret" "Name" .Values.mysql.reader.secret.name "Key" "password") -}}
{{- end -}}
{{- end -}}

{{- define "orders.mysql.endpoint" -}}
{{- if not (empty .Values.mysql.endpoint) -}}
{{- .Values.mysql.endpoint -}}
{{- else -}}
jdbc:mariadb://{{ include "orders.mysql.fullname" . }}:{{ .Values.mysql.service.port }}/{{ .Values.mysql.database }}
{{- end -}}
{{- end -}}

{{- define "orders.mysql.reader.endpoint" -}}
{{- if not (empty .Values.mysql.reader.endpoint) -}}
{{- .Values.mysql.reader.endpoint -}}
{{- else -}}
{{- include "orders.mysql.endpoint" . -}}
jdbc:mariadb://{{ include "orders.postgresql.fullname" . }}:{{ .Values.postgresql.service.port }}/{{ .Values.postgresql.database }}
{{- end -}}
{{- end -}}

Expand Down
4 changes: 2 additions & 2 deletions deploy/kubernetes/charts/orders/templates/configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: ConfigMap
metadata:
name: {{ include "orders.configMapName" . }}
data:
SPRING_PROFILES_ACTIVE: mysql,rabbitmq
SPRING_DATASOURCE_URL: {{ include "orders.mysql.endpoint" . }}
SPRING_PROFILES_ACTIVE: rabbitmq
SPRING_DATASOURCE_URL: jdbc:postgresql://{{ .Values.postgresql.endpoint.host }}:{{ .Values.postgresql.endpoint.port }}/{{ .Values.postgresql.database }}
SPRING_RABBITMQ_ADDRESSES: {{ include "orders.rabbitmq.addresses" . }}
{{- end }}
4 changes: 2 additions & 2 deletions deploy/kubernetes/charts/orders/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ spec:
- name: SPRING_DATASOURCE_USERNAME
valueFrom:
secretKeyRef:
name: {{ .Values.mysql.secret.name }}
name: {{ .Values.postgresql.secret.name }}
key: username
- name: SPRING_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.mysql.secret.name }}
name: {{ .Values.postgresql.secret.name }}
key: password
envFrom:
- secretRef:
Expand Down

This file was deleted.

9 changes: 0 additions & 9 deletions deploy/kubernetes/charts/orders/templates/mysql-secret.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions deploy/kubernetes/charts/orders/templates/mysql-service.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- if .Values.postgresql.secret.create }}
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.postgresql.secret.name }}
data:
username: {{ .Values.postgresql.secret.username | b64enc | quote }}
password: "{{ include "orders.postgresql.password" . }}"
{{- end }}
17 changes: 17 additions & 0 deletions deploy/kubernetes/charts/orders/templates/postgresql-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.postgresql.create }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "orders.postgresql.fullname" . }}
labels:
{{- include "orders.postgresql.labels" . | nindent 4 }}
spec:
type: {{ .Values.postgresql.service.type }}
ports:
- port: {{ .Values.postgresql.service.port }}
targetPort: mysql
protocol: TCP
name: mysql
selector:
{{- include "orders.postgresql.selectorLabels" . | nindent 4 }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
{{- if .Values.mysql.create }}
{{- if .Values.postgresql.create }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "orders.mysql.fullname" . }}
name: {{ include "orders.postgresql.fullname" . }}
labels:
{{- include "orders.mysql.labels" . | nindent 4 }}
{{- include "orders.postgresql.labels" . | nindent 4 }}
spec:
replicas: 1
serviceName: {{ include "orders.mysql.fullname" . }}
serviceName: {{ include "orders.postgresql.fullname" . }}
selector:
matchLabels:
{{- include "orders.mysql.selectorLabels" . | nindent 6 }}
{{- include "orders.postgresql.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.mysql.podAnnotations }}
{{- with .Values.postgresql.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "orders.mysql.selectorLabels" . | nindent 8 }}
{{- include "orders.postgresql.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: mysql
image: "{{ .Values.mysql.image.repository }}:{{ .Values.mysql.image.tag }}"
imagePullPolicy: {{ .Values.mysql.image.pullPolicy }}
image: "{{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }}"
imagePullPolicy: {{ .Values.postgresql.image.pullPolicy }}
env:
- name: MYSQL_ROOT_PASSWORD
value: my-secret-pw
- name: MYSQL_DATABASE
value: {{ .Values.mysql.database }}
value: {{ .Values.postgresql.database }}
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: {{ .Values.mysql.secret.name }}
name: {{ .Values.postgresql.secret.name }}
key: username
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.mysql.secret.name }}
name: {{ .Values.postgresql.secret.name }}
key: password
args:
- "--ignore-db-dir=lost+found"
Expand All @@ -52,41 +52,41 @@ spec:
- name: mysql
containerPort: 3306
protocol: TCP
{{- with .Values.mysql.nodeSelector }}
{{- with .Values.postgresql.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.mysql.affinity }}
{{- with .Values.postgresql.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.mysql.tolerations }}
{{- with .Values.postgresql.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.mysql.persistentVolume.enabled }}
{{- if .Values.postgresql.persistentVolume.enabled }}
volumeClaimTemplates:
- metadata:
name: data
{{- if .Values.mysql.persistentVolume.annotations }}
{{- if .Values.postgresql.persistentVolume.annotations }}
annotations:
{{ toYaml .Values.mysql.persistentVolume.annotations | indent 10 }}
{{ toYaml .Values.postgresql.persistentVolume.annotations | indent 10 }}
{{- end }}
{{- if .Values.mysql.persistentVolume.labels }}
{{- if .Values.postgresql.persistentVolume.labels }}
labels:
{{ toYaml .Values.mysql.persistentVolume.labels | indent 10 }}
{{ toYaml .Values.postgresql.persistentVolume.labels | indent 10 }}
{{- end }}
spec:
accessModes:
{{ toYaml .Values.mysql.persistentVolume.accessModes | indent 8 }}
{{ toYaml .Values.postgresql.persistentVolume.accessModes | indent 8 }}
resources:
requests:
storage: "{{ .Values.mysql.persistentVolume.size }}"
{{- if .Values.mysql.persistentVolume.storageClass }}
{{- if (eq "-" .Values.mysql.persistentVolume.storageClass) }}
storage: "{{ .Values.postgresql.persistentVolume.size }}"
{{- if .Values.postgresql.persistentVolume.storageClass }}
{{- if (eq "-" .Values.postgresql.persistentVolume.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.mysql.persistentVolume.storageClass }}"
storageClassName: "{{ .Values.postgresql.persistentVolume.storageClass }}"
{{- end }}
{{- end }}
{{- else }}
Expand Down
12 changes: 7 additions & 5 deletions deploy/kubernetes/charts/orders/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ configMap:
create: true
name:

mysql:
postgresql:
create: true

database: orders

endpoint: ""
endpoint:
host: ""
port: ""

secret:
create: true
Expand All @@ -92,13 +94,13 @@ mysql:
password: ""

image:
repository: mysql
repository: postgres
pullPolicy: IfNotPresent
tag: "5.7"
tag: "16.1"

service:
type: ClusterIP
port: 3306
port: 5432

podAnnotations: {}

Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/charts/templates/orders.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ image:
{{end}}

{{if env "RANDOM_PASSWORD" }}
mysql:
postgresql:
secret:
password: {{ env "RANDOM_PASSWORD" | default "" }}
{{end}}
Loading

0 comments on commit 9e3f6db

Please sign in to comment.