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 }}'