From d0827ba42680f42ed7d0ddbe1c751e376dd3e4c4 Mon Sep 17 00:00:00 2001 From: aknochow Date: Fri, 1 Mar 2024 17:09:15 -0500 Subject: [PATCH] Fixing postgres upgrade conditional (#1741) --- molecule/default/tasks/awx_replicas_test.yml | 2 +- .../tasks/database_configuration.yml | 38 +++++++++---------- roles/installer/tasks/update_status.yml | 2 +- roles/installer/tasks/upgrade_postgres.yml | 1 + 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/molecule/default/tasks/awx_replicas_test.yml b/molecule/default/tasks/awx_replicas_test.yml index 14536d869..93afe7eca 100644 --- a/molecule/default/tasks/awx_replicas_test.yml +++ b/molecule/default/tasks/awx_replicas_test.yml @@ -61,4 +61,4 @@ expected_web_replicas: 3 expected_task_replicas: 3 tags: - - replicas + - replicas diff --git a/roles/installer/tasks/database_configuration.yml b/roles/installer/tasks/database_configuration.yml index 48bad24ab..ee2d952e1 100644 --- a/roles/installer/tasks/database_configuration.yml +++ b/roles/installer/tasks/database_configuration.yml @@ -117,26 +117,26 @@ register: _running_pods - block: - - name: Filter pods by name - set_fact: - filtered_old_postgres_pods: "{{ _running_pods.resources | - selectattr('metadata.name', 'match', ansible_operator_meta.name + '-postgres.*-0') | - rejectattr('metadata.name', 'search', '-' + supported_pg_version | string + '-0') | - list }}" + - name: Filter pods by name + set_fact: + filtered_old_postgres_pods: "{{ _running_pods.resources | + selectattr('metadata.name', 'match', ansible_operator_meta.name + '-postgres.*-0') | + rejectattr('metadata.name', 'search', '-' + supported_pg_version | string + '-0') | + list }}" # Sort pods by name in reverse order (most recent PG version first) and set - - name: Set info for previous postgres pod - set_fact: - sorted_old_postgres_pods: "{{ filtered_old_postgres_pods | - sort(attribute='metadata.name') | - reverse }}" - when: filtered_old_postgres_pods | length - - - - name: Set info for previous postgres pod - set_fact: - old_postgres_pod: "{{ sorted_old_postgres_pods | first }}" - when: filtered_old_postgres_pods | length + - name: Set info for previous postgres pod + set_fact: + sorted_old_postgres_pods: "{{ filtered_old_postgres_pods | + sort(attribute='metadata.name') | + reverse }}" + when: filtered_old_postgres_pods | length + + + - name: Set info for previous postgres pod + set_fact: + old_postgres_pod: "{{ sorted_old_postgres_pods | first }}" + when: filtered_old_postgres_pods | length when: _running_pods.resources | length - name: Look up details for this deployment @@ -179,7 +179,7 @@ - (_old_pg_version.stdout | default(0) | int ) < supported_pg_version when: - managed_database - - (_previous_upgraded_pg_version | default(false)) | ternary(_previous_upgraded_pg_version < supported_pg_version, true) + - (_previous_upgraded_pg_version | default(false)) | ternary(_previous_upgraded_pg_version | int < supported_pg_version, true) - old_postgres_pod | length # If empty, then old pg pod has been removed and we can assume the upgrade is complete - block: diff --git a/roles/installer/tasks/update_status.yml b/roles/installer/tasks/update_status.yml index a693ae528..9f59b3644 100644 --- a/roles/installer/tasks/update_status.yml +++ b/roles/installer/tasks/update_status.yml @@ -111,5 +111,5 @@ name: "{{ ansible_operator_meta.name }}" namespace: "{{ ansible_operator_meta.namespace }}" status: - upgradedPostgresVersion: "{{ upgraded_postgres_version | string }}" + upgradedPostgresVersion: "{{ upgraded_postgres_version }}" when: upgraded_postgres_version is defined diff --git a/roles/installer/tasks/upgrade_postgres.yml b/roles/installer/tasks/upgrade_postgres.yml index ff3618a84..392744e80 100644 --- a/roles/installer/tasks/upgrade_postgres.yml +++ b/roles/installer/tasks/upgrade_postgres.yml @@ -164,4 +164,5 @@ loop: - "postgres-{{ ansible_operator_meta.name }}-postgres-0" - "postgres-{{ ansible_operator_meta.name }}-postgres-13-0" + - "postgres-13-{{ ansible_operator_meta.name }}-postgres-13-0" when: postgres_keep_pvc_after_upgrade