From 142c8354f8792b681cde4c9e08926f92102ff03a Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Sat, 12 Dec 2020 19:01:32 +0500 Subject: [PATCH] Use a configmap for a script to take backup of postgres --- .../1.0.0/templates/backup-postgres-hook.yaml | 36 +++++++++++++++++-- .../templates/nuke-deployments-hook.yaml | 4 +-- .../1.0.0/templates/serviceaccount.yaml | 10 +++--- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/test/nextcloud/1.0.0/templates/backup-postgres-hook.yaml b/test/nextcloud/1.0.0/templates/backup-postgres-hook.yaml index 6a566520337..5c02335f47e 100644 --- a/test/nextcloud/1.0.0/templates/backup-postgres-hook.yaml +++ b/test/nextcloud/1.0.0/templates/backup-postgres-hook.yaml @@ -1,3 +1,19 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "postgres-backup-hook-config-map" +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 {{ template "postgres.DatabaseName"}} > /postgres_backups/update_dump; + +--- + apiVersion: batch/v1 kind: Job metadata: @@ -12,7 +28,7 @@ spec: name: "pre-upgrade-hook2" spec: restartPolicy: Never - serviceAccountName: {{ template "nextcloud.serviceAccountName" }} + serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}" containers: - name: {{ .Chart.Name }}-postgres-backup image: "postgres:13.1" @@ -33,4 +49,20 @@ spec: mountPath: /var/lib/postgresql/data - name: postgres-backup mountPath: /postgres_backups - command: ['sh', '-c', "/docker-entrypoint.sh; pg_dump -U $POSTGRES_USER -d {{ template "postgres.DatabaseName"}} > /postgres_backups/update_dump;"] + - name: backup-script-configmap + mountPath: /bin/backup_entrypoint.sh + readOnly: true + subPath: entrypoint.sh + command: + - "/bin/backup_entrypoint.sh" + volumes: + - name: postgres-data + hostPath: + path: {{ template "configuredPostgresHostPath" . }} + - name: postgres-backup + hostPath: + path: {{ template "configuredBackupPostgresHostPath" . }} + - name: backup-script-configmap + configMap: + defaultMode: 0700 + name: "postgres-backup-hook-config-map" diff --git a/test/nextcloud/1.0.0/templates/nuke-deployments-hook.yaml b/test/nextcloud/1.0.0/templates/nuke-deployments-hook.yaml index 34b2ea77bb2..dbab1f52e5c 100644 --- a/test/nextcloud/1.0.0/templates/nuke-deployments-hook.yaml +++ b/test/nextcloud/1.0.0/templates/nuke-deployments-hook.yaml @@ -12,8 +12,8 @@ spec: name: "pre-upgrade-hook1" spec: restartPolicy: Never - serviceAccountName: {{ template "nextcloud.serviceAccountName" }} + serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}" containers: - name: kubectl image: "bitnami/kubectl:1.19" - command: ["delete" , "deployment", "{{ template "nextcloud.fullname" . }}", "{{ template "nextcloud.fullname" . }}-postgres"] + command: ["kubectl", "delete" , "deployment", "{{ template "nextcloud.fullname" . }}", "{{ template "nextcloud.fullname" . }}-postgres"] diff --git a/test/nextcloud/1.0.0/templates/serviceaccount.yaml b/test/nextcloud/1.0.0/templates/serviceaccount.yaml index 46a4f18f385..c25bd439fd5 100644 --- a/test/nextcloud/1.0.0/templates/serviceaccount.yaml +++ b/test/nextcloud/1.0.0/templates/serviceaccount.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ template "nextcloud.serviceAccountName" }} + name: "{{ template "nextcloud.serviceAccountName" . }}" namespace: {{ .Release.Namespace }} --- @@ -9,14 +9,14 @@ metadata: apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: - name: {{ .Release.Name }}-service-account-role-binding + name: "{{ .Release.Name }}-service-account-role-binding" subjects: - kind: ServiceAccount - name: {{ template "nextcloud.serviceAccountName" }} + name: "{{ template "nextcloud.serviceAccountName" . }}" namespace: {{ .Release.Namespace }} roleRef: kind: Role - name: spinupcontainers + name: "{{ .Release.Name }}-service-account-role" apiGroup: rbac.authorization.k8s.io --- @@ -24,7 +24,7 @@ roleRef: apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: - name: {{ .Release.Name }}-service-account-role + name: "{{ .Release.Name }}-service-account-role" namespace: {{ .Release.Namespace }} rules: - apiGroups: