Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
put the setting db access env vars into template
Browse files Browse the repository at this point in the history
  • Loading branch information
sa-ChristianAnton committed Jun 12, 2022
1 parent 7cde286 commit b386878
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 311 deletions.
84 changes: 84 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,87 @@ Return if ingress supports pathType.
{{- define "zabbix.ingress.supportsPathType" -}}
{{- or (eq (include "zabbix.ingress.isStable" .) "true") (and (eq (include "zabbix.ingress.apiVersion" .) "networking.k8s.io/v1beta1")) -}}
{{- end -}}

{{/*
Define env var names
*/}}


{{/*
Return the entire logic of setting DB access related env vars for the containers which need them
*/}}
{{- define "zabbix.db_access.env_vars" -}}
{{- $ := index . 0 }}
{{- $cntxt := index . 2 }}
{{- $hostvar := "DB_SERVER_HOST" }}
{{- $portvar := "DB_SERVER_PORT" }}
{{- $uservar := "POSTGRES_USER" }}
{{- $passwordvar := "POSTGRES_PASSWORD" }}
{{- $dbvar := "POSTGRES_DB" }}
{{- if eq $cntxt "database" }}
{{- $hostvar = "PGHOST" }}
{{- $portvar = "PGPORT" }}
{{- $uservar = "PGUSER" }}
{{- $passwordvar = "PGPASSWORD" }}
{{- $dbvar = "PGDATABASE" }}
{{- end }}
{{- with index . 1 }}
{{- if .Values.postgresql.enabled }}
- name: {{ $hostvar }}
value: {{ template "zabbix.fullname" . }}-postgresql
- name: {{ $portvar }}
value: {{ .Values.postgresql.service.port | quote }}
{{- else if .Values.db_access.use_unified_secret }}
- name: {{ $hostvar }}
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: host
- name: {{ $portvar }}
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: port
optional: true
{{- else }}
- name: {{ $hostvar }}
value: {{ .Values.db_access.db_server_host | quote }}
- name: {{ $portvar }}
value: {{ .Values.db_access.db_server_port | quote }}
{{- end }}
{{- if .Values.db_access.use_unified_secret }}
- name: {{ $uservar }}
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: user
optional: true
- name: {{ $passwordvar }}
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: password
- name: {{ $dbvar }}
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: dbname
optional: true
{{- else }}
- name: {{ $uservar }}
value: {{ .Values.db_access.postgres_user | quote }}
- name: {{ $passwordvar }}
{{- if .Values.db_access.postgres_password_secret }}
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.postgres_password_secret }}
key: {{ default "password" .Values.db_access.postgres_password_secret_key }}
{{- else }}
value: {{ .Values.db_access.postgres_password | quote }}
{{- end }}
- name: {{ $dbvar }}
value: {{ .Values.db_access.postgres_db | quote }}
{{- end }}
{{- end }}
{{- end -}}
57 changes: 1 addition & 56 deletions templates/cronjob-hanodes-autoclean.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,7 @@ spec:
- -c
- echo "deleting all stopped and unavailable HANodes older than {{ .Values.zabbixserver.ha_nodes_autoclean.delete_older_than_seconds }} seconds..." && psql -c "delete from ha_node where status in (1,2) and extract(epoch from now())-lastaccess>{{ .Values.zabbixserver.ha_nodes_autoclean.delete_older_than_seconds }}"
env:
{{- if .Values.postgresql.enabled }}
- name: PGHOST
value: {{ template "zabbix.fullname" . }}-postgresql
- name: PGPORT
value: {{ .Values.postgresql.service.port | quote }}
{{- else if .Values.db_access.use_unified_secret }}
- name: PGHOST
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: host
- name: PGPORT
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: port
optional: true
{{- else }}
- name: PGHOST
value: {{ .Values.db_access.db_server_host | quote }}
- name: PGPORT
value: {{ .Values.db_access.db_server_port | quote }}
{{- end }}
{{- if .Values.db_access.use_unified_secret }}
- name: PGUSER
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: user
optional: true
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: password
- name: PGDATABASE
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: dbname
optional: true
{{- else }}
- name: PGUSER
value: {{ .Values.db_access.postgres_user | quote }}
- name: PGPASSWORD
{{- if .Values.db_access.postgres_password_secret }}
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.postgres_password_secret }}
key: {{ default "password" .Values.db_access.postgres_password_secret_key }}
{{- else }}
value: {{ .Values.db_access.postgres_password | quote }}
{{- end }}
- name: PGDATABASE
value: {{ .Values.db_access.postgres_db | quote }}
{{- end }}
{{- include "zabbix.db_access.env_vars" (list $ . "database") | nindent 12 }}
imagePullSecrets:
{{- range .Values.zabbixserver.image.pullSecrets }}
- name: {{ . | quote }}
Expand Down
114 changes: 2 additions & 112 deletions templates/deployment-zabbix-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,62 +51,7 @@ spec:
- name: init-wait-for-database-schema
image: "{{ .Values.zabbixserver.image.repository }}:{{ .Values.zabbix_image_tag }}"
env:
{{- if .Values.postgresql.enabled }}
- name: DB_SERVER_HOST
value: {{ template "zabbix.fullname" . }}-postgresql
- name: DB_SERVER_PORT
value: {{ .Values.postgresql.service.port | quote }}
{{- else if .Values.db_access.use_unified_secret }}
- name: DB_SERVER_HOST
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: host
- name: DB_SERVER_PORT
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: port
optional: true
{{- else }}
- name: DB_SERVER_HOST
value: {{ .Values.db_access.db_server_host | quote }}
- name: DB_SERVER_PORT
value: {{ .Values.db_access.db_server_port | quote }}
{{- end }}
{{- if .Values.db_access.use_unified_secret }}
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: user
optional: true
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: password
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: dbname
optional: true
{{- else }}
- name: POSTGRES_USER
value: {{ .Values.db_access.postgres_user | quote }}
- name: POSTGRES_PASSWORD
{{- if .Values.db_access.postgres_password_secret }}
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.postgres_password_secret }}
key: {{ default "password" .Values.db_access.postgres_password_secret_key }}
{{- else }}
value: {{ .Values.db_access.postgres_password | quote }}
{{- end }}
- name: POSTGRES_DB
value: {{ .Values.db_access.postgres_db | quote }}
{{- end }}
{{- include "zabbix.db_access.env_vars" (list $ . "zabbix") | nindent 12 }}
command:
- "/bin/bash"
- "/script/wait_db_schema.sh"
Expand Down Expand Up @@ -137,62 +82,7 @@ spec:
hostIP: {{ .Values.zabbixserver.hostIP }}
{{- end}}
env:
{{- if .Values.postgresql.enabled }}
- name: DB_SERVER_HOST
value: {{ template "zabbix.fullname" . }}-postgresql
- name: DB_SERVER_PORT
value: {{ .Values.postgresql.service.port | quote }}
{{- else if .Values.db_access.use_unified_secret }}
- name: DB_SERVER_HOST
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: host
- name: DB_SERVER_PORT
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: port
optional: true
{{- else }}
- name: DB_SERVER_HOST
value: {{ .Values.db_access.db_server_host | quote }}
- name: DB_SERVER_PORT
value: {{ .Values.db_access.db_server_port | quote }}
{{- end }}
{{- if .Values.db_access.use_unified_secret }}
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: user
optional: true
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: password
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: dbname
optional: true
{{- else }}
- name: POSTGRES_USER
value: {{ .Values.db_access.postgres_user | quote }}
- name: POSTGRES_PASSWORD
{{- if .Values.db_access.postgres_password_secret }}
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.postgres_password_secret }}
key: {{ default "password" .Values.db_access.postgres_password_secret_key }}
{{- else }}
value: {{ .Values.db_access.postgres_password | quote }}
{{- end }}
- name: POSTGRES_DB
value: {{ .Values.db_access.postgres_db | quote }}
{{- end }}
{{- include "zabbix.db_access.env_vars" (list $ . "zabbix") | nindent 12 }}
{{- range $item := .Values.zabbixserver.extraEnv }}
- name: {{ $item.name }}
value: {{ $item.value | quote }}
Expand Down
57 changes: 1 addition & 56 deletions templates/deployment-zabbix-web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,62 +54,7 @@ spec:
image: "{{ .Values.zabbixweb.image.repository }}:{{ .Values.zabbix_image_tag }}"
imagePullPolicy: {{ .Values.zabbixweb.image.pullPolicy }}
env:
{{- if .Values.postgresql.enabled }}
- name: DB_SERVER_HOST
value: {{ template "zabbix.fullname" . }}-postgresql
- name: DB_SERVER_PORT
value: {{ .Values.postgresql.service.port | quote }}
{{- else if .Values.db_access.use_unified_secret }}
- name: DB_SERVER_HOST
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: host
- name: DB_SERVER_PORT
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: port
optional: true
{{- else }}
- name: DB_SERVER_HOST
value: {{ .Values.db_access.db_server_host | quote }}
- name: DB_SERVER_PORT
value: {{ .Values.db_access.db_server_port | quote }}
{{- end }}
{{- if .Values.db_access.use_unified_secret }}
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: user
optional: true
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: password
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.unified_secret_name }}
key: dbname
optional: true
{{- else }}
- name: POSTGRES_USER
value: {{ .Values.db_access.postgres_user | quote }}
- name: POSTGRES_PASSWORD
{{- if .Values.db_access.postgres_password_secret }}
valueFrom:
secretKeyRef:
name: {{ .Values.db_access.postgres_password_secret }}
key: {{ default "password" .Values.db_access.postgres_password_secret_key }}
{{- else }}
value: {{ .Values.db_access.postgres_password | quote }}
{{- end }}
- name: POSTGRES_DB
value: {{ .Values.db_access.postgres_db | quote }}
{{- end }}
{{- include "zabbix.db_access.env_vars" (list $ . "zabbix") | nindent 10 }}
{{- range $item := .Values.zabbixweb.extraEnv }}
- name: {{ $item.name }}
value: {{ $item.value | quote }}
Expand Down
Loading

0 comments on commit b386878

Please sign in to comment.