From 99d77dff990244e648d2c617101cc48807d1a1ef Mon Sep 17 00:00:00 2001 From: Marcelo Moreira de Mello Date: Sat, 31 Jul 2021 00:42:01 -0400 Subject: [PATCH 1/2] pgsql uses initContainer to address FS permissions --- roles/installer/tasks/database_configuration.yml | 3 ++- roles/installer/templates/postgres.yaml.j2 | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/roles/installer/tasks/database_configuration.yml b/roles/installer/tasks/database_configuration.yml index 2e99be55..470530ae 100644 --- a/roles/installer/tasks/database_configuration.yml +++ b/roles/installer/tasks/database_configuration.yml @@ -80,8 +80,9 @@ - block: - name: Create Database if no database is specified k8s: - apply: true + apply: yes definition: "{{ lookup('template', 'postgres.yaml.j2') }}" + wait: yes register: create_statefulset_result rescue: diff --git a/roles/installer/templates/postgres.yaml.j2 b/roles/installer/templates/postgres.yaml.j2 index d17ee12a..bf2e018a 100644 --- a/roles/installer/templates/postgres.yaml.j2 +++ b/roles/installer/templates/postgres.yaml.j2 @@ -37,6 +37,21 @@ spec: imagePullSecrets: - name: {{ image_pull_secret }} {% endif %} + initContainers: + - name: init-chmod-data + image: '{{ postgres_image }}:{{ postgres_image_version }}' + imagePullPolicy: '{{ image_pull_policy }}' + command: + - /bin/sh + - -c + - | + if [ ! -f {{ postgres_data_path }}/PG_VERSION ]; then + chown postgres:root {{ postgres_data_path | dirname }} + fi + volumeMounts: + - name: postgres + mountPath: '{{ postgres_data_path | dirname }}' + subPath: '{{ postgres_data_path | dirname | basename }}' containers: - image: '{{ postgres_image }}:{{ postgres_image_version }}' imagePullPolicy: '{{ image_pull_policy }}' From 649f0cc3fb69d27e29553735295b749e866bc541 Mon Sep 17 00:00:00 2001 From: Marcelo Moreira de Mello Date: Sat, 31 Jul 2021 00:56:20 -0400 Subject: [PATCH 2/2] Added fsGroup --- roles/installer/templates/postgres.yaml.j2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/installer/templates/postgres.yaml.j2 b/roles/installer/templates/postgres.yaml.j2 index bf2e018a..f87c8420 100644 --- a/roles/installer/templates/postgres.yaml.j2 +++ b/roles/installer/templates/postgres.yaml.j2 @@ -56,6 +56,8 @@ spec: - image: '{{ postgres_image }}:{{ postgres_image_version }}' imagePullPolicy: '{{ image_pull_policy }}' name: postgres + securityContext: + fsGroup: 999 env: # For postgres_image based on rhel8/postgresql-12 - name: POSTGRESQL_DATABASE