diff --git a/roles/installer/tasks/initialize.yml b/roles/installer/tasks/initialize_django.yml similarity index 100% rename from roles/installer/tasks/initialize.yml rename to roles/installer/tasks/initialize_django.yml diff --git a/roles/installer/tasks/main.yml b/roles/installer/tasks/main.yml index 27fb7690..1b5a13db 100644 --- a/roles/installer/tasks/main.yml +++ b/roles/installer/tasks/main.yml @@ -39,47 +39,8 @@ - tower_ingress_type | lower == 'route' - tower_route_tls_secret != '' -- name: Ensure configured instance resources exist in the cluster. - k8s: - apply: yes - definition: "{{ lookup('template', item) | from_yaml_all | list }}" - with_items: - - tower_config.yaml.j2 - -- name: Apply Resources - k8s: - apply: yes - definition: "{{ lookup('template', item + '.yaml.j2') }}" - register: tower_deployment_result - loop: - - 'tower_app_credentials' - - 'tower_service_account' - - 'tower_persistent' - - 'tower_deployment' - - 'tower_service' - - 'tower_ingress' - -- name: Get the resource pod information. - k8s_info: - kind: Pod - namespace: '{{ meta.namespace }}' - label_selectors: - - "app.kubernetes.io/name={{ meta.name }}" - - "app.kubernetes.io/managed-by=awx-operator" - - "app.kubernetes.io/component=awx" - register: tower_pods - until: "tower_pods['resources'][0]['status']['phase'] == 'Running'" - delay: 5 - retries: 60 - -- name: Set the resource pod name as a variable. - set_fact: - tower_pod_name: "{{ tower_pods['resources'][0]['metadata']['name'] }}" - -- name: Verify the resource pod name is populated. - assert: - that: tower_pod_name != '' - fail_msg: "Could not find the tower pod's name." +- name: Include resources configuration tasks + include_tasks: resources_configuration.yml - name: Check for pending migrations k8s_exec: @@ -103,7 +64,8 @@ - database_check is defined - (database_check.stdout|trim) != '0' -- include_tasks: initialize.yml +- name: Initialize Django + include_tasks: initialize_django.yml - name: Update status variables include_tasks: update_status.yml diff --git a/roles/installer/tasks/migrate_data.yml b/roles/installer/tasks/migrate_data.yml index cd619af0..63ec4c75 100644 --- a/roles/installer/tasks/migrate_data.yml +++ b/roles/installer/tasks/migrate_data.yml @@ -12,10 +12,11 @@ k8s_info: kind: Pod namespace: '{{ meta.namespace }}' - label_selectors: - - "app.kubernetes.io/name={{ meta.name }}-postgres" + name: '{{ meta.name }}-postgres-0' # using name to keep compatibility + field_selectors: + - status.phase=Running register: postgres_pod - until: "postgres_pod['resources'][0]['status']['phase'] == 'Running'" + until: postgres_pod['resources'] | length delay: 5 retries: 60 @@ -38,6 +39,7 @@ name: "{{ meta.name }}" namespace: "{{ meta.namespace }}" replicas: 0 + wait: yes when: tower_deployment['resources'] | length - name: Set pg_dump command diff --git a/roles/installer/tasks/resources_configuration.yml b/roles/installer/tasks/resources_configuration.yml new file mode 100644 index 00000000..703191bc --- /dev/null +++ b/roles/installer/tasks/resources_configuration.yml @@ -0,0 +1,80 @@ +--- + +- name: Get the current resource pod information. + k8s_info: + api_version: v1 + kind: Pod + namespace: '{{ meta.namespace }}' + label_selectors: + - "app.kubernetes.io/name={{ meta.name }}" + - "app.kubernetes.io/managed-by=awx-operator" + - "app.kubernetes.io/component=awx" + field_selectors: + - status.phase=Running + register: tower_pods + +- name: Set the resource pod name as a variable. + set_fact: + tower_pod_name: "{{ tower_pods['resources'][0]['metadata']['name'] | default('') }}" + +- name: Apply Resources + k8s: + apply: yes + definition: "{{ lookup('template', item + '.yaml.j2') }}" + wait: yes + register: tower_resources_result + loop: + - 'tower_config' + - 'tower_app_credentials' + - 'tower_service_account' + - 'tower_persistent' + - 'tower_service' + - 'tower_ingress' + +- name: Apply deployment resources + k8s: + apply: yes + definition: "{{ lookup('template', 'tower_deployment.yaml.j2') | from_yaml }}" + wait: yes + register: tower_deployment_result + +- block: + - name: Delete pod to reload a resource configuration + k8s: + api_version: v1 + state: absent + kind: Pod + namespace: '{{ meta.namespace }}' + name: '{{ tower_pod_name }}' + wait: yes + when: + - tower_resources_result.changed + - tower_pod_name | length + + - name: Get the new resource pod information after updating resource. + k8s_info: + kind: Pod + namespace: '{{ meta.namespace }}' + label_selectors: + - "app.kubernetes.io/name={{ meta.name }}" + - "app.kubernetes.io/managed-by=awx-operator" + - "app.kubernetes.io/component=awx" + field_selectors: + - status.phase=Running + register: _new_pod + until: + - _new_pod['resources'] | length + - _new_pod['resources'][0]['metadata']['name'] != tower_pod_name + delay: 5 + retries: 60 + + - name: Update new resource pod name as a variable. + set_fact: + tower_pod_name: '{{ _new_pod["resources"][0]["metadata"]["name"] }}' + when: + - tower_resources_result.changed or tower_deployment_result.changed + +- name: Verify the resource pod name is populated. + assert: + that: tower_pod_name != '' + fail_msg: "Could not find the tower pod's name." diff --git a/roles/installer/templates/tower_postgres.yaml.j2 b/roles/installer/templates/tower_postgres.yaml.j2 index dc2583e7..a4255992 100644 --- a/roles/installer/templates/tower_postgres.yaml.j2 +++ b/roles/installer/templates/tower_postgres.yaml.j2 @@ -1,6 +1,6 @@ # Postgres StatefulSet. --- -apiVersion: v1 +apiVersion: apps/v1 kind: StatefulSet metadata: name: '{{ meta.name }}-postgres'