From 6809e1632d8df019c794b3b17b85d52692265c81 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Thu, 3 Nov 2022 01:15:50 +0200 Subject: [PATCH] add postgres job and update questions --- charts/minio/1.7.0/questions.yaml | 101 ++++++++++++++++++ charts/minio/1.7.0/templates/_postgres.tpl | 9 ++ .../templates/backup-postgres-config.yaml | 15 +++ .../1.7.0/templates/backup-postgres-hook.yaml | 38 +++++++ charts/minio/1.7.0/test_values.yaml | 1 + 5 files changed, 164 insertions(+) create mode 100644 charts/minio/1.7.0/templates/backup-postgres-config.yaml create mode 100644 charts/minio/1.7.0/templates/backup-postgres-hook.yaml diff --git a/charts/minio/1.7.0/questions.yaml b/charts/minio/1.7.0/questions.yaml index 54b54b30b4..259fde747f 100644 --- a/charts/minio/1.7.0/questions.yaml +++ b/charts/minio/1.7.0/questions.yaml @@ -184,6 +184,28 @@ questions: $ref: - "definitions/certificate" + - variable: logsearchapi + label: Log Search API Configuration + description: Log Search API Configuration + group: Minio Configuration + schema: + type: dict + additional_attrs: true + attrs: + - variable: enabled + label: Enable Log Search API + description: Enables Log Search API and configures MinIO to use it. It also deploys a postgres DB for it. + schema: + type: boolean + default: false + - variable: diskCapacityGB + label: Disk Capacity in GB + description: Capacity in GB that logs are allowed to occupy. + schema: + type: int + show_if: [["enabled", "=", true]] + default: 5 + - variable: appVolumeMounts label: "Minio Storage" group: "Storage" @@ -252,6 +274,85 @@ questions: type: hostpath required: true + - variable: postgresAppVolumeMounts + label: Postgres Storage + group: Storage + schema: + type: dict + attrs: + - variable: postgres-data + label: Postgres Data Volume + schema: + type: dict + attrs: + - variable: datasetName + label: Postgres Data Volume Name + schema: + type: string + hidden: true + $ref: + - normalize/ixVolume + default: ix-postgres_data + show_if: [["hostPathEnabled", "=", false]] + editable: false + + - variable: mountPath + label: Postgresql Data Mount Path + description: Path where the volume will be mounted inside the pod + schema: + type: path + hidden: true + editable: false + default: /var/lib/postgresql/data + - variable: hostPathEnabled + label: Enable Host Path for Postgres Data Volume + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: Host Path for Postgres Data Volume + schema: + type: hostpath + required: true + + - variable: postgres-backup + label: Postgres Backup Volume + schema: + type: dict + attrs: + - variable: datasetName + label: Postgres Backup Volume Name + schema: + type: string + hidden: true + $ref: + - normalize/ixVolume + default: ix-postgres_backups + show_if: [["hostPathEnabled", "=", false]] + editable: false + - variable: mountPath + label: Postgresql Backup Mount Path + description: Path where the volume will be mounted inside the pod + schema: + type: path + hidden: true + editable: false + default: /postgres_backups + - variable: hostPathEnabled + label: Enable Host Path for Postgres Backup Volume + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: Host Path for Postgres Backup Volume + schema: + type: hostpath + required: true + - variable: enableResourceLimits label: "Enable Pod resource limits" group: "Resource Limits" diff --git a/charts/minio/1.7.0/templates/_postgres.tpl b/charts/minio/1.7.0/templates/_postgres.tpl index 01be54d6ae..e90c3a83a3 100644 --- a/charts/minio/1.7.0/templates/_postgres.tpl +++ b/charts/minio/1.7.0/templates/_postgres.tpl @@ -18,6 +18,15 @@ {{- print "logsearchapi" -}} {{- end -}} +{{/* +Retrieve postgres backup name +This will return a unique name based on revision and chart numbers specified. +*/}} +{{- define "postgres.backupName" -}} +{{- $upgradeDict := .Values.ixChartContext.upgradeMetadata -}} +{{- printf "postgres-backup-from-%s-to-%s-revision-%d" $upgradeDict.oldChartVersion $upgradeDict.newChartVersion (int64 $upgradeDict.preUpgradeRevision) -}} +{{- end -}} + {{- define "postgres.envVariableConfiguration" -}} {{- $envList := list -}} {{- $secretName := (include "postgres.secretName" .) -}} diff --git a/charts/minio/1.7.0/templates/backup-postgres-config.yaml b/charts/minio/1.7.0/templates/backup-postgres-config.yaml new file mode 100644 index 0000000000..d3ddec6294 --- /dev/null +++ b/charts/minio/1.7.0/templates/backup-postgres-config.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgres-backup-hook-config-map + annotations: + rollme: {{ randAlphaNum 5 | quote }} +data: + entrypoint.sh: |- + #!/bin/sh + cmd="/docker-entrypoint.sh postgres" + eval "${cmd}" & disown; + until pg_isready; do + sleep 5; + done; + pg_dump -U $POSTGRES_USER -d {{ include "postgres.dbName" . }} > /postgres_backups/$BACKUP_NAME; diff --git a/charts/minio/1.7.0/templates/backup-postgres-hook.yaml b/charts/minio/1.7.0/templates/backup-postgres-hook.yaml new file mode 100644 index 0000000000..d9e515761a --- /dev/null +++ b/charts/minio/1.7.0/templates/backup-postgres-hook.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ixChartContext.isUpgrade -}} +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" (include "postgres.nameSuffix" .)) }} +apiVersion: batch/v1 +kind: Job +metadata: + name: pre-upgrade-hook + annotations: + "helm.sh/hook": pre-upgrade + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": hook-succeeded + rollme: {{ randAlphaNum 5 | quote }} +spec: + template: + metadata: + name: pre-upgrade-hook + spec: + restartPolicy: Never + containers: + - name: {{ .Chart.Name }}-postgres-backup + image: {{ include "postgres.imageName" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }} + - name: BACKUP_NAME + value: {{ include "postgres.backupName" . }} + volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }} + - name: backup-script-configmap + mountPath: /bin/backup_entrypoint.sh + readOnly: true + subPath: entrypoint.sh + command: + - /bin/backup_entrypoint.sh + volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }} + - name: backup-script-configmap + configMap: + defaultMode: 0700 + name: postgres-backup-hook-config-map +{{- end -}} diff --git a/charts/minio/1.7.0/test_values.yaml b/charts/minio/1.7.0/test_values.yaml index 47c5943db1..62a60e1d2c 100644 --- a/charts/minio/1.7.0/test_values.yaml +++ b/charts/minio/1.7.0/test_values.yaml @@ -16,6 +16,7 @@ postgresql: dataVolume: datasetName: ix-postgres_data mountPath: /var/lib/postgresql/data +ixChartContext: {} distributedIps: [] distributedMode: false dnsConfig: