Allow custom postgres pod label to support user managed pg pods

- Only set resolvable pg host path for pg container when managed
This commit is contained in:
Christian M. Adams
2021-04-22 13:49:28 -04:00
parent ff9248e971
commit 867bc258b9
12 changed files with 59 additions and 4 deletions

View File

@@ -53,5 +53,9 @@ spec:
tower_postgres_configuration_secret:
description: Custom postgres_configuration secret name
type: string
postgres_label_selector:
description: Label selector used to identify postgres pod for backing up data
type: string
oneOf:
- required: ["tower_name"]

View File

@@ -50,5 +50,8 @@ spec:
tower_postgres_configuration_secret:
description: Custom postgres_configuration secret name
type: string
postgres_label_selector:
description: Label selector used to identify postgres pod for backing up data
type: string
oneOf:
- required: ["tower_name", "tower_backup_pvc", "tower_backup_pvc_namespace", "tower_backup_dir"]

View File

@@ -58,6 +58,9 @@ spec:
tower_old_postgres_configuration_secret:
description: Secret where the old database configuration can be found for data migration
type: string
postgres_label_selector:
description: Label selector used to identify postgres pod for data migration
type: string
tower_secret_key_secret:
description: Secret where the secret key can be found
type: string

View File

@@ -60,6 +60,9 @@ spec:
tower_old_postgres_configuration_secret:
description: Secret where the old database configuration can be found for data migration
type: string
postgres_label_selector:
description: Label selector used to identify postgres pod for data migration
type: string
tower_secret_key_secret:
description: Secret where the secret key can be found
type: string
@@ -440,6 +443,10 @@ spec:
tower_postgres_configuration_secret:
description: Custom postgres_configuration secret name
type: string
postgres_label_selector:
description: Label selector used to identify postgres pod for backing up data
type: string
oneOf:
- required: ["tower_name"]
@@ -495,6 +502,9 @@ spec:
tower_postgres_configuration_secret:
description: Custom postgres_configuration secret name
type: string
postgres_label_selector:
description: Label selector used to identify postgres pod for backing up data
type: string
oneOf:
- required: ["tower_name", "tower_backup_pvc", "tower_backup_pvc_namespace", "tower_backup_dir"]

View File

@@ -58,6 +58,9 @@ spec:
tower_old_postgres_configuration_secret:
description: Secret where the old database configuration can be found for data migration
type: string
postgres_label_selector:
description: Label selector used to identify postgres pod for data migration
type: string
tower_secret_key_secret:
description: Secret where the secret key can be found
type: string

View File

@@ -53,5 +53,9 @@ spec:
tower_postgres_configuration_secret:
description: Custom postgres_configuration secret name
type: string
postgres_label_selector:
description: Label selector used to identify postgres pod for backing up data
type: string
oneOf:
- required: ["tower_name"]

View File

@@ -50,5 +50,8 @@ spec:
tower_postgres_configuration_secret:
description: Custom postgres_configuration secret name
type: string
postgres_label_selector:
description: Label selector used to identify postgres pod for backing up data
type: string
oneOf:
- required: ["tower_name", "tower_backup_pvc", "tower_backup_pvc_namespace", "tower_backup_dir"]

View File

@@ -6,14 +6,14 @@ To migrate data from an older AWX installation, you must provide some informatio
### Secret Key
You can find your old secret key in the inventory file you used to deploy AWX in releases prior to version 18.
You can find your old secret key in the inventory file you used to deploy AWX in releases prior to version 18.
```yaml
apiVersion: v1
kind: Secret
metadata:
name: <resourcename>-secret-key
namespace: <target namespace>
namespace: <target-namespace>
stringData:
secret_key: <old-secret-key>
type: Opaque
@@ -49,6 +49,9 @@ In the next section pass it in through `tower_postgres_configuration_secret` ins
from the key and ensuring the value matches the name of the secret. This will make AWX pick up on the existing
database and apply any pending migrations. It is strongly recommended to backup your database beforehand.
The postgresql pod for the old deployment is used when streaming data to the new postgresql pod. If your postgresql pod has a custom label,
you can pass that via the `postgres_label_selector` variable to make sure the postgresql pod can be found.
## Deploy AWX
When you apply your AWX object, you must specify the name to the database secret you created above:

View File

@@ -71,6 +71,10 @@ tower_backup_pvc_namespace: 'custom-namespace'
If a custom postgres configuration secret was used when deploying AWX, it will automatically be used by the backup role.
To check the name of this secret, look at the towerPostgresConfigurationSecret status on your AWX object.
The postgresql pod for the old deployment is used when backing up data to the new postgresql pod. If your postgresql pod has a custom label,
you can pass that via the `postgres_label_selector` variable to make sure the postgresql pod can be found.
Testing
----------------

View File

@@ -19,13 +19,19 @@
awx_postgres_database: "{{ pg_config['resources'][0]['data']['database'] | b64decode }}"
awx_postgres_port: "{{ pg_config['resources'][0]['data']['port'] | b64decode }}"
awx_postgres_host: "{{ pg_config['resources'][0]['data']['host'] | b64decode }}"
awx_postgres_type: "{{ _postgres_configuration['resources'][0]['data']['type'] | b64decode | default('unmanaged') }}"
- name: Default label selector to custom resource generated postgres
set_fact:
postgres_label_selector: "app.kubernetes.io/name={{ meta.name }}-postgres"
when: postgres_label_selector is not defined
- name: Get the postgres pod information
k8s_info:
kind: Pod
namespace: '{{ meta.namespace }}'
label_selectors:
- "app.kubernetes.io/name={{ tower_name }}-postgres"
- "{{ postgres_label_selector }}"
register: postgres_pod
until:
- "postgres_pod['resources'] | length"
@@ -69,6 +75,7 @@
- name: Set full resolvable host name for postgres pod
set_fact:
resolvable_db_host: "{{ awx_postgres_host }}.{{ meta.namespace }}.svc.cluster.local"
when: awx_postgres_type == 'managed'
- name: Set pg_dump command
set_fact:

View File

@@ -12,6 +12,11 @@
awx_old_postgres_port: "{{ old_pg_config['resources'][0]['data']['port'] | b64decode }}"
awx_old_postgres_host: "{{ old_pg_config['resources'][0]['data']['host'] | b64decode }}"
- name: Default label selector to custom resource generated postgres
set_fact:
postgres_label_selector: "app.kubernetes.io/name={{ meta.name }}-postgres"
when: postgres_label_selector is not defined
- name: Get the postgres pod information
k8s_info:
kind: Pod

View File

@@ -27,12 +27,17 @@
awx_postgres_port: "{{ pg_config['resources'][0]['data']['port'] | b64decode }}"
awx_postgres_host: "{{ pg_config['resources'][0]['data']['host'] | b64decode }}"
- name: Default label selector to custom resource generated postgres
set_fact:
postgres_label_selector: "app.kubernetes.io/name={{ meta.name }}-postgres"
when: postgres_label_selector is not defined
- name: Get the postgres pod information
k8s_info:
kind: Pod
namespace: '{{ meta.namespace }}'
label_selectors:
- "app.kubernetes.io/name={{ tower_name }}-postgres"
- "{{ postgres_label_selector }}"
register: postgres_pod
until:
- "postgres_pod['resources'] | length"
@@ -64,6 +69,7 @@
- name: Set full resolvable host name for postgres pod
set_fact:
resolvable_db_host: "{{ awx_postgres_host }}.{{ meta.namespace }}.svc.cluster.local"
when: awx_postgres_type == 'managed'
- name: Set pg_restore command
set_fact: