From b3a74362aff871f4eb9b9ba73ea2b4ddf1ba46ff Mon Sep 17 00:00:00 2001 From: Stanislav Zaprudskiy Date: Tue, 24 Jan 2023 18:45:24 +0100 Subject: [PATCH] Make AWX Pod variable to be calculated respecting `creationTimestamp` and `deletionTimestamp` Do not consider Pods marked for deletion when calculating tower_pod to address replicas scale down case - where normally Pods spawned recently are being taken for removal. As well as the case when operator kicked off but some old replicas are still terminating. Respect `creationTimestamp` so to make sure that the newest Pod is taken after Deployment application, in which case multiple RS Pods (from old RS and new RS) could be running simultaneously while the rollout is happening. --- .../tasks/resources_configuration.yml | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/roles/installer/tasks/resources_configuration.yml b/roles/installer/tasks/resources_configuration.yml index fd2db1cf..438af396 100644 --- a/roles/installer/tasks/resources_configuration.yml +++ b/roles/installer/tasks/resources_configuration.yml @@ -13,9 +13,17 @@ - status.phase=Running register: tower_pod +- name: Set the resource pod as a variable. + set_fact: + tower_pod: >- + {{ tower_pod['resources'] + | rejectattr('metadata.deletionTimestamp', 'defined') + | sort(attribute='metadata.creationTimestamp') + | first | default({}) }} + - name: Set the resource pod name as a variable. set_fact: - tower_pod_name: "{{ tower_pod['resources'][0]['metadata']['name'] | default('') }}" + tower_pod_name: "{{ tower_pod['metadata']['name'] | default('') }}" - name: Set user provided control plane ee image set_fact: @@ -238,9 +246,17 @@ - status.phase=Running register: _new_pod + - name: Update new resource pod as a variable. + set_fact: + tower_pod: >- + {{ _new_pod['resources'] + | rejectattr('metadata.deletionTimestamp', 'defined') + | sort(attribute='metadata.creationTimestamp') + | last | default({}) }} + - name: Update new resource pod name as a variable. set_fact: - tower_pod_name: '{{ _new_pod["resources"][0]["metadata"]["name"] }}' + tower_pod_name: '{{ tower_pod["metadata"]["name"] | default("")}}' when: - tower_resources_result.changed or this_deployment_result.changed