mirror of
https://github.com/ansible/awx-operator.git
synced 2026-03-26 21:33:14 +00:00
Fix AWXRestore multiple bugs
- Move force_drop_db from vars/main.yml to defaults/main.yml so CR spec values are not overridden by Ansible variable precedence - Grant CREATEDB priv to database user before DROP/CREATE and revoke it after restore, following the containerized-installer pattern - Omit --clean --if-exists from pg_restore when force_drop_db is true since the database is freshly created and empty, avoiding partition index dependency errors Signed-off-by: Lucas Benedito <lbenedit@redhat.com>
This commit is contained in:
committed by
Dimitri Savineau
parent
d4b295e8b4
commit
0b4b5dd7fd
@@ -40,5 +40,8 @@ additional_labels: []
|
|||||||
# Maintain some of the recommended `app.kubernetes.io/*` labels on the resource (self)
|
# Maintain some of the recommended `app.kubernetes.io/*` labels on the resource (self)
|
||||||
set_self_labels: true
|
set_self_labels: true
|
||||||
|
|
||||||
|
# If set to true, the restore process will drop and recreate the database schema before restoring
|
||||||
|
force_drop_db: false
|
||||||
|
|
||||||
spec_overrides: {}
|
spec_overrides: {}
|
||||||
...
|
...
|
||||||
|
|||||||
@@ -83,13 +83,24 @@
|
|||||||
- name: Set pg_restore command
|
- name: Set pg_restore command
|
||||||
set_fact:
|
set_fact:
|
||||||
pg_restore: >-
|
pg_restore: >-
|
||||||
pg_restore --clean --if-exists --no-owner --no-acl
|
pg_restore {{ force_drop_db | bool | ternary('', '--clean --if-exists') }} --no-owner --no-acl
|
||||||
-U {{ awx_postgres_user }}
|
-U {{ awx_postgres_user }}
|
||||||
-h {{ resolvable_db_host }}
|
-h {{ resolvable_db_host }}
|
||||||
-d {{ awx_postgres_database }}
|
-d {{ awx_postgres_database }}
|
||||||
-p {{ awx_postgres_port }}
|
-p {{ awx_postgres_port }}
|
||||||
no_log: "{{ no_log }}"
|
no_log: "{{ no_log }}"
|
||||||
|
|
||||||
|
- name: Grant CREATEDB privilege to database user for force_drop_db
|
||||||
|
kubernetes.core.k8s_exec:
|
||||||
|
namespace: "{{ ansible_operator_meta.namespace }}"
|
||||||
|
pod: "{{ postgres_pod_name }}"
|
||||||
|
container: postgres
|
||||||
|
command: >-
|
||||||
|
psql -c "ALTER USER {{ awx_postgres_user }} CREATEDB;"
|
||||||
|
when:
|
||||||
|
- force_drop_db | bool
|
||||||
|
- awx_postgres_type == 'managed'
|
||||||
|
|
||||||
- name: Force drop and create database if force_drop_db is true
|
- name: Force drop and create database if force_drop_db is true
|
||||||
block:
|
block:
|
||||||
- name: Set drop db command
|
- name: Set drop db command
|
||||||
@@ -155,3 +166,14 @@
|
|||||||
"
|
"
|
||||||
register: data_migration
|
register: data_migration
|
||||||
no_log: "{{ no_log }}"
|
no_log: "{{ no_log }}"
|
||||||
|
|
||||||
|
- name: Revoke CREATEDB privilege from database user
|
||||||
|
kubernetes.core.k8s_exec:
|
||||||
|
namespace: "{{ ansible_operator_meta.namespace }}"
|
||||||
|
pod: "{{ postgres_pod_name }}"
|
||||||
|
container: postgres
|
||||||
|
command: >-
|
||||||
|
psql -c "ALTER USER {{ awx_postgres_user }} NOCREATEDB;"
|
||||||
|
when:
|
||||||
|
- force_drop_db | bool
|
||||||
|
- awx_postgres_type == 'managed'
|
||||||
|
|||||||
@@ -14,7 +14,4 @@ broadcast_websocket_secret: '{{ deployment_name }}-broadcast-websocket'
|
|||||||
postgres_configuration_secret: '{{ deployment_name }}-postgres-configuration'
|
postgres_configuration_secret: '{{ deployment_name }}-postgres-configuration'
|
||||||
supported_pg_version: 15
|
supported_pg_version: 15
|
||||||
image_pull_policy: IfNotPresent
|
image_pull_policy: IfNotPresent
|
||||||
|
|
||||||
# If set to true, the restore process will delete the existing database and create a new one
|
|
||||||
force_drop_db: false
|
|
||||||
pg_drop_create: ''
|
pg_drop_create: ''
|
||||||
|
|||||||
Reference in New Issue
Block a user