From 3d89a5f80bfe7f36f9489c5b1f517584933032ab Mon Sep 17 00:00:00 2001 From: kpavic Date: Fri, 22 Jun 2018 14:47:27 +0200 Subject: [PATCH] Cleanup all failed builds before setting up templates --- .../os_temps/tasks/handle_os_templates.yml | 2 +- .../roles/os_temps/tasks/setup_containers.yml | 23 +++++++++++++++++++ .../os_temps/tasks/setup_os_templates.yml | 20 ---------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/playbooks/roles/os_temps/tasks/handle_os_templates.yml b/playbooks/roles/os_temps/tasks/handle_os_templates.yml index 00c9f00b..570c8323 100644 --- a/playbooks/roles/os_temps/tasks/handle_os_templates.yml +++ b/playbooks/roles/os_temps/tasks/handle_os_templates.yml @@ -20,7 +20,7 @@ stdout: "" # Check for failed apps and cleanup -- name: "Check for all failed app on the cluster" +- name: "Check for all failed apps on the cluster" shell: "{{ oc_bin }} get all | egrep 'Failed|Error' | egrep 'builds' | awk '{print $1}' | awk -F'/' '{print $2}' | sed 's/-[0-9+]//g' " register: oc_check_app_status ignore_errors: yes diff --git a/playbooks/roles/os_temps/tasks/setup_containers.yml b/playbooks/roles/os_temps/tasks/setup_containers.yml index bc52d040..405ffedf 100644 --- a/playbooks/roles/os_temps/tasks/setup_containers.yml +++ b/playbooks/roles/os_temps/tasks/setup_containers.yml @@ -33,6 +33,29 @@ - set_fact: total_build_success: false +# Check for failed apps and cleanup +- name: "Check for all failed apps on the cluster" + shell: "{{ oc_bin }} get all | egrep 'Failed|Error' | egrep 'builds' | awk '{print $1}' | awk -F'/' '{print $2}' | sed 's/-[0-9+]//g' " + register: oc_check_app_status + ignore_errors: yes + +- name: "Cleanup all failed dc, bc, routes, svc, and imagestreams on the cluster" + shell: "{{ oc_bin }} get all | grep '{{ failed_container_name }}' | awk '{print $1}' | egrep -v 'builds|po' | xargs -i {{ oc_bin }} delete {}" + with_items: "{{ oc_check_app_status.stdout_lines }}" + loop_control: + loop_var: failed_container_name + ignore_errors: yes + when: oc_check_app_status.stdout != "" + +- name: "Cleanup any serviceaccounts, pvc, and rolebindings for an app if it exists on the cluster" + shell: "{{ oc_bin }} get {{ item }} | egrep '{{ oc_check_app_status.stdout_lines|join('|') }}' | awk '{print $1}' | xargs -i {{ oc_bin }} delete {{ item }}/{}" + ignore_errors: yes + with_items: + - serviceaccounts + - pvc + - rolebindings + when: oc_check_app_status.stdout != "" + # Setup project_repo templates and store variables for each template - name: "Setup project_repo templates and store variables for each template" include_tasks: "setup_os_templates.yml template_name={{ item.path }}.processed" diff --git a/playbooks/roles/os_temps/tasks/setup_os_templates.yml b/playbooks/roles/os_temps/tasks/setup_os_templates.yml index 24478027..46a2b7e6 100644 --- a/playbooks/roles/os_temps/tasks/setup_os_templates.yml +++ b/playbooks/roles/os_temps/tasks/setup_os_templates.yml @@ -2,26 +2,6 @@ - set_fact: params: [] -# Check for failed apps and cleanup -- name: Check for any failed apps on the cluster - shell: "{{ oc_bin }} get all | egrep 'Failed|Error' | egrep 'builds' | awk '{print $1}' | awk -F'/' '{print $2}' | sed 's/-[0-9+]//g' | head -1" - register: oc_check_app_status - ignore_errors: yes - -- name: Cleanup any failed dc, bc, routes, svc, and is for {{ oc_check_app_status.stdout }} on the cluster - shell: "{{ oc_bin }} get all | grep '{{ oc_check_app_status.stdout }}' | awk '{print $1}' | egrep -v 'builds|po' | xargs -i {{ oc_bin }} delete {}" - ignore_errors: yes - when: oc_check_app_status.stdout != "" - -- name: Cleanup any serviceaccounts, pvc, and rolebindings for an app if it exists on the cluster - shell: "{{ oc_bin }} get {{ item }} | grep '{{ oc_check_app_status.stdout }}' | awk '{print $1}' | xargs -i {{ oc_bin }} delete {{ item }}/{}" - ignore_errors: yes - with_items: - - serviceaccounts - - pvc - - rolebindings - when: oc_check_app_status.stdout != "" - - name: "{{ container_config_name }} :: Get template name from the yaml file" shell: "{{ oc_bin }} process -f {{ template_name }} | jq '.items[1].metadata.labels.template' | sed 's/\"//g'" register: "template_name_file"