Skip to content

Commit cd7ef68

Browse files
authored
Merge pull request #322 from lucas-benedito/fix_awx_restore
Fix EDA Restore multiple bugs
2 parents f7b727c + 3cf8490 commit cd7ef68

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

roles/restore/defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ restore_resource_requirements:
3030
set_self_labels: true
3131

3232
spec_overrides: {}
33+
34+
force_drop_db: false
3335
...

roles/restore/tasks/postgres.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,24 @@
7272
- name: Set pg_restore command
7373
set_fact:
7474
pg_restore: >-
75-
pg_restore --clean --if-exists --no-owner --no-acl
75+
pg_restore {{ force_drop_db | bool | ternary('', '--clean --if-exists') }} --no-owner --no-acl
7676
-U {{ eda_postgres_user }}
7777
-h {{ resolvable_db_host }}
7878
-d {{ eda_postgres_database }}
7979
-p {{ eda_postgres_port }}
8080
no_log: "{{ no_log }}"
8181

82+
- name: Grant CREATEDB privilege to database user for force_drop_db
83+
kubernetes.core.k8s_exec:
84+
namespace: "{{ ansible_operator_meta.namespace }}"
85+
pod: "{{ postgres_pod_name }}"
86+
container: postgres
87+
command: >-
88+
psql -c "ALTER USER {{ eda_postgres_user }} CREATEDB;"
89+
when:
90+
- force_drop_db | bool
91+
- eda_postgres_type == 'managed'
92+
8293
- name: Force drop and create database if force_drop_db is true
8394
block:
8495
- name: Set drop db command
@@ -138,3 +149,14 @@
138149
"
139150
register: data_migration
140151
no_log: "{{ no_log }}"
152+
153+
- name: Revoke CREATEDB privilege from database user
154+
kubernetes.core.k8s_exec:
155+
namespace: "{{ ansible_operator_meta.namespace }}"
156+
pod: "{{ postgres_pod_name }}"
157+
container: postgres
158+
command: >-
159+
psql -c "ALTER USER {{ eda_postgres_user }} NOCREATEDB;"
160+
when:
161+
- force_drop_db | bool
162+
- eda_postgres_type == 'managed'

roles/restore/vars/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ _postgres_image_version: latest
88
backup_api_version: '{{ deployment_type }}.ansible.com/v1alpha1'
99
backup_kind: 'EDABackup'
1010

11-
force_drop_db: false
1211
pg_drop_create: ''

0 commit comments

Comments
 (0)