add init containers, fix backup hook

This commit is contained in:
Stavros kois
2022-11-03 04:03:54 +02:00
parent 2355fc80e5
commit a26fe70988
7 changed files with 91 additions and 38 deletions
@@ -20,7 +20,15 @@
{{- $postgresSecretName := (include "postgres.secretName" .) -}}
{{- $envList = mustAppend $envList (dict "name" "MINIO_LOG_QUERY_AUTH_TOKEN" "valueFromSecret" true "secretName" $secretName "secretKey" "queryToken") -}}
{{- $envList = mustAppend $envList (dict "name" "LOGSEARCH_AUDIT_AUTH_TOKEN" "valueFromSecret" true "secretName" $secretName "secretKey" "auditToken") -}}
{{- $envList = mustAppend $envList (dict "name" "LOGSEARCH_PG_CONN_STR" "valueFromSecret" true "secretName" $secretName "secretKey" "postgresURL") -}}
{{- $envList = mustAppend $envList (dict "name" "LOGSEARCH_PG_CONN_STR" "valueFromSecret" true "secretName" $postgresSecretName "secretKey" "postgresURL") -}}
{{- $envList = mustAppend $envList (dict "name" "LOGSEARCH_DISK_CAPACITY_GB" "value" .Values.logsearchapi.diskCapacityGB) -}}
{{- include "common.containers.environmentVariables" (dict "environmentVariables" $envList) -}}
{{- end -}}
{{/* Used in the minio init container (checks that logsearchapi is available) */}}
{{- define "logsearchapiInit.envVariableConfiguration" -}}
{{- $envList := list -}}
{{- $secretName := (include "logsearchapi.secretName" .) -}}
{{- $envList = mustAppend $envList (dict "name" "apiURL" "valueFromSecret" true "secretName" $secretName "secretKey" "logQueryURL") -}}
{{- include "common.containers.environmentVariables" (dict "environmentVariables" $envList) -}}
{{- end -}}
+21 -1
View File
@@ -36,6 +36,26 @@ This will return a unique name based on revision and chart numbers specified.
{{- include "common.containers.environmentVariables" (dict "environmentVariables" $envList) -}}
{{- end -}}
{{- define "postgresBackup.envVariableConfiguration" -}}
{{- $envList := list -}}
{{- $secretName := (include "postgres.secretName" .) -}}
{{- $envList = mustAppend $envList (dict "name" "POSTGRES_USER" "valueFromSecret" true "secretName" $secretName "secretKey" "db_user") -}}
{{- $envList = mustAppend $envList (dict "name" "POSTGRES_DB" "valueFromSecret" true "secretName" $secretName "secretKey" "db_name") -}}
{{/* PGPASSWORD is used by pg_dump */}}
{{- $envList = mustAppend $envList (dict "name" "PGPASSWORD" "valueFromSecret" true "secretName" $secretName "secretKey" "db_password") -}}
{{- $envList = mustAppend $envList (dict "name" "pgHost" "valueFromSecret" true "secretName" $secretName "secretKey" "postgresHost") -}}
{{- include "common.containers.environmentVariables" (dict "environmentVariables" $envList) -}}
{{- end -}}
{{/* Used in the logsearchapi init container (checks that postgres is available) */}}
{{- define "postgresInit.envVariableConfiguration" -}}
{{- $envList := list -}}
{{- $secretName := (include "postgres.secretName" .) -}}
{{- $envList = mustAppend $envList (dict "name" "pgHost" "valueFromSecret" true "secretName" $secretName "secretKey" "postgresHost") -}}
{{- $envList = mustAppend $envList (dict "name" "pguser" "valueFromSecret" true "secretName" $secretName "secretKey" "db_user") -}}
{{- include "common.containers.environmentVariables" (dict "environmentVariables" $envList) -}}
{{- end -}}
{{/*
Retrieve postgres volume configuration
*/}}
@@ -47,5 +67,5 @@ Retrieve postgres volume configuration
Retrieve postgres volume mounts configuration
*/}}
{{- define "postgres.volumeMountsConfiguration" -}}
{{ include "common.storage.configureAppVolumeMountsInContainer" (dict "appVolumeMounts" .Values.postgresql ) | nindent 0 }}
{{ include "common.storage.configureAppVolumeMountsInContainer" (dict "appVolumeMounts" .Values.postgresAppVolumeMounts ) | nindent 0 }}
{{- end -}}
@@ -9,7 +9,7 @@ data:
#!/bin/sh
cmd="/docker-entrypoint.sh postgres"
eval "${cmd}" & disown;
until pg_isready; do
until pg_isready -U "$POSTGRES_USER" -h "$pgHost"; do
sleep 5;
done;
pg_dump -U $POSTGRES_USER -d {{ include "postgres.dbName" . }} > /postgres_backups/$BACKUP_NAME;
pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -h "$pgHost" -Fc -f /postgres_backups/$BACKUP_NAME.dump;
@@ -21,7 +21,7 @@ spec:
- name: {{ .Chart.Name }}-postgres-backup
image: {{ include "postgres.imageName" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }}
env: {{ include "postgresBackup.envVariableConfiguration" $values | nindent 10 }}
- name: BACKUP_NAME
value: {{ include "postgres.backupName" . }}
volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }}
@@ -1,4 +1,6 @@
{{ include "common.storage.hostPathValidate" .Values }}
{{ $logsearchValues := (. | mustDeepCopy) }}
{{ $_ := set $logsearchValues "common" (dict "nameSuffix" (include "logsearchapi.nameSuffix" .)) }}
apiVersion: {{ template "common.capabilities.deployment.apiVersion" . }}
kind: Deployment
metadata:
@@ -32,6 +34,17 @@ spec:
runAsGroup: {{ .Values.runAsGroup }}
serviceAccountName: {{ include "common.names.serviceAccountName" . | quote }}
hostNetwork: {{ include "minio.hostNetworking" . }}
{{ if .Values.logsearchapi.enabled }}
initContainers:
- name: {{ .Chart.Name }}-waitapi
image: alpine/curl
imagePullPolicy: {{ .Values.image.pullPolicy }}
env: {{ include "logsearchapiInit.envVariableConfiguration" $logsearchValues | nindent 10 }}
command:
- sh
- -c
- "until curl $apiURL/status; do sleep 2; done"
{{ end }}
containers:
- name: {{ .Chart.Name }}
{{ include "common.resources.limitation" . | nindent 10 }}
@@ -1,40 +1,51 @@
{{ if .Values.logsearchapi.enabled }}
{{ $values := (. | mustDeepCopy) }}
{{ $_ := set $values "common" (dict "nameSuffix" (include "logsearchapi.nameSuffix" .)) }}
{{ $pg_values := (. | mustDeepCopy) }}
{{ $_ := set $pg_values "common" (dict "nameSuffix" (include "postgres.nameSuffix" .)) }}
{{ include "common.deployment.common_config" $values | nindent 0 }}
spec: {{ include "common.deployment.common_spec" $values | nindent 2 }}
template: {{ include "common.deployment.pod.metadata" $values | nindent 4 }}
spec:
initContainers:
- name: {{ .Chart.Name }}-{{ include "logsearchapi.nameSuffix" . }}-waitdb
image: {{ include "postgres.imageName" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
env: {{ include "postgresInit.envVariableConfiguration" $pg_values | nindent 10 }}
command:
- sh
- -c
- 'until pg_isready -U "$pgUser" -h "$pgHost"; do sleep 2; done'
containers:
- name: {{ .Chart.Name }}-{{ include "logsearchapi.nameSuffix" . }}
image: {{ include "logsearchapi.imageName" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
env: {{ include "logsearchapi.envVariableConfiguration" $values | nindent 10 }}
command:
- {{ include "logsearchapi.command" . }}
ports:
- name: logsearchapi
containerPort: 8080
protocol: TCP
readinessProbe:
httpGet:
path: /status
port: 8080
failureThreshold: 5
periodSeconds: 15
initialDelaySeconds: 15
livenessProbe:
httpGet:
path: /status
port: 8080
failureThreshold: 5
periodSeconds: 15
initialDelaySeconds: 15
startupProbe:
httpGet:
path: /status
port: 8080
failureThreshold: 5
periodSeconds: 15
initialDelaySeconds: 15
- name: {{ .Chart.Name }}-{{ include "logsearchapi.nameSuffix" . }}
image: {{ include "logsearchapi.imageName" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
env: {{ include "logsearchapi.envVariableConfiguration" $values | nindent 10 }}
command:
- {{ include "logsearchapi.command" . }}
ports:
- name: logsearchapi
containerPort: 8080
protocol: TCP
readinessProbe:
httpGet:
path: /status
port: 8080
failureThreshold: 5
periodSeconds: 15
initialDelaySeconds: 15
livenessProbe:
httpGet:
path: /status
port: 8080
failureThreshold: 5
periodSeconds: 15
initialDelaySeconds: 15
startupProbe:
httpGet:
path: /status
port: 8080
failureThreshold: 5
periodSeconds: 15
initialDelaySeconds: 15
{{ end }}
@@ -7,8 +7,8 @@ kind: Secret
metadata:
name: {{ include "postgres.secretName" . }}
data:
db_user: {{ include "postgres.dbUser" . }}
db_name: {{ include "postgres.dbName" . }}
db_user: {{ include "postgres.dbUser" . | b64enc }}
db_name: {{ include "postgres.dbName" . | b64enc }}
{{ with (lookup "v1" "Secret" .Release.Namespace (include "postgres.secretName" .)) }}
{{ $dbPass = (index .data "db_password") }}
db_password: {{ $dbPass }}
@@ -16,4 +16,5 @@ data:
db_password: {{ $dbPass }}
{{ end }}
postgresURL: {{ printf "postgres://%v:%v@%v:5432/%v?sslmode=disable" (include "postgres.dbUser" .) ($dbPass | b64dec) (include "common.names.fullname" $pgValues) (include "postgres.dbName" .) | b64enc }}
postgresHost: {{ printf "%v" (include "common.names.fullname" $pgValues) | b64enc }}
{{ end }}