diff --git a/ansible/templates/awxbackup_crd.yml.j2 b/ansible/templates/awxbackup_crd.yml.j2 index 02e18a27..21e388f3 100644 --- a/ansible/templates/awxbackup_crd.yml.j2 +++ b/ansible/templates/awxbackup_crd.yml.j2 @@ -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"] diff --git a/ansible/templates/awxrestore_crd.yml.j2 b/ansible/templates/awxrestore_crd.yml.j2 index eb11e1a4..af08e551 100644 --- a/ansible/templates/awxrestore_crd.yml.j2 +++ b/ansible/templates/awxrestore_crd.yml.j2 @@ -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"] diff --git a/ansible/templates/crd.yml.j2 b/ansible/templates/crd.yml.j2 index c5956c1f..0bca0a1c 100644 --- a/ansible/templates/crd.yml.j2 +++ b/ansible/templates/crd.yml.j2 @@ -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 diff --git a/deploy/awx-operator.yaml b/deploy/awx-operator.yaml index e303c137..00c30c95 100644 --- a/deploy/awx-operator.yaml +++ b/deploy/awx-operator.yaml @@ -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"] diff --git a/deploy/crds/awx_v1beta1_crd.yaml b/deploy/crds/awx_v1beta1_crd.yaml index c5956c1f..0bca0a1c 100644 --- a/deploy/crds/awx_v1beta1_crd.yaml +++ b/deploy/crds/awx_v1beta1_crd.yaml @@ -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 diff --git a/deploy/crds/awxbackup_v1beta1_crd.yaml b/deploy/crds/awxbackup_v1beta1_crd.yaml index 02e18a27..21e388f3 100644 --- a/deploy/crds/awxbackup_v1beta1_crd.yaml +++ b/deploy/crds/awxbackup_v1beta1_crd.yaml @@ -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"] diff --git a/deploy/crds/awxrestore_v1beta1_crd.yaml b/deploy/crds/awxrestore_v1beta1_crd.yaml index eb11e1a4..af08e551 100644 --- a/deploy/crds/awxrestore_v1beta1_crd.yaml +++ b/deploy/crds/awxrestore_v1beta1_crd.yaml @@ -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"] diff --git a/docs/migration.md b/docs/migration.md index f2b258d8..e83397e1 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -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: -secret-key - namespace: + namespace: stringData: 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: diff --git a/roles/backup/README.md b/roles/backup/README.md index 509ffebe..5db6e418 100644 --- a/roles/backup/README.md +++ b/roles/backup/README.md @@ -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 ---------------- diff --git a/roles/backup/tasks/postgres.yml b/roles/backup/tasks/postgres.yml index ddf9d0f4..4b891717 100644 --- a/roles/backup/tasks/postgres.yml +++ b/roles/backup/tasks/postgres.yml @@ -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: diff --git a/roles/installer/tasks/migrate_data.yml b/roles/installer/tasks/migrate_data.yml index e6bbab80..1f83d8f3 100644 --- a/roles/installer/tasks/migrate_data.yml +++ b/roles/installer/tasks/migrate_data.yml @@ -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 diff --git a/roles/restore/tasks/postgres.yml b/roles/restore/tasks/postgres.yml index 13e38816..e64ee137 100644 --- a/roles/restore/tasks/postgres.yml +++ b/roles/restore/tasks/postgres.yml @@ -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: