Skip to content

Commit

Permalink
Add postgres init container
Browse files Browse the repository at this point in the history
Add postgres init container if
postgres_init_container_extra_commands is defined

This allows users to run arbitrary commands

This is aimed to solve the issue where users may
need to chmod or chown the postgres
data volume for user 26, which is the user
that is running postgres in the sclorg image.

For example, one can now set the follow on the AWX spec:
spec:
  postgres_init_container_extra_commands: |
    chown 26:0 /var/lib/pgsql/data
    chmod 700 /var/lib/pgsql/data

Signed-off-by: Seth Foster <[email protected]>
  • Loading branch information
fosterseth authored and rooftopcellist committed Apr 2, 2024
1 parent 7bf49c2 commit 79497c7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/crd/bases/awx.ansible.com_awxs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,9 @@ spec:
type: array
items:
type: string
postgres_init_container_extra_commands:
description: Extra commands for the init postgres container
type: string
postgres_extra_volumes:
description: Specify extra volumes to add to the application pod
type: string
Expand Down
12 changes: 12 additions & 0 deletions docs/user-guide/database-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,15 @@ We recommend you use the default image sclorg image. If you are coming from a de
You can no longer configure a custom `postgres_data_path` because it is hardcoded in the quay.io/sclorg/postgresql-15-c9s image.

If you override the postgres image to use a custom postgres image like postgres:15 for example, the default data directory path may be different. These images cannot be used interchangeably.

#### Postgres init extra commands

Users can define arbitrary commands to run from a postgres init container.

For example this may be useful for setting permissions and ownership of the postgres data directory.

```yaml
postgres_init_container_extra_commands: |
chown 26:0 /var/lib/pgsql/data
chmod 700 /var/lib/pgsql/data
```
22 changes: 21 additions & 1 deletion roles/installer/templates/statefulsets/postgres.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ spec:
{% endif %}
{% if postgres_priority_class is defined %}
priorityClassName: '{{ postgres_priority_class }}'
{% endif %}
{% if postgres_init_container_extra_commands is defined %}
initContainers:
- name: init
image: '{{ _postgres_image }}'
imagePullPolicy: '{{ image_pull_policy }}'
securityContext:
runAsUser: 0
command:
- /bin/sh
- -c
- |
{{ postgres_init_container_extra_commands | indent(width=14) }}
volumeMounts:
- name: postgres-{{ supported_pg_version }}
mountPath: '{{ _postgres_data_path | dirname }}'
subPath: '{{ _postgres_data_path | dirname | basename }}'
{% if postgres_extra_volume_mounts %}
{{ postgres_extra_volume_mounts | indent(width=12, first=True) }}
{% endif %}
{% endif %}
containers:
- image: '{{ _postgres_image }}'
Expand Down Expand Up @@ -113,7 +133,7 @@ spec:
- name: postgres-{{ supported_pg_version }}
mountPath: '{{ _postgres_data_path | dirname }}'
subPath: '{{ _postgres_data_path | dirname | basename }}'
{% if postgres_extra_volume_mounts -%}
{% if postgres_extra_volume_mounts %}
{{ postgres_extra_volume_mounts | indent(width=12, first=True) }}
{% endif %}
resources: {{ postgres_resource_requirements }}
Expand Down

0 comments on commit 79497c7

Please sign in to comment.