diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-11-02 07:24:28 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2022-12-05 10:52:49 +0000 |
commit | 7ebad0a8164345ebf6b93b028ae7ef3b56ecabf4 (patch) | |
tree | f285829dabb0fd9bfdece3472373bb9d7de9d3f4 /roles/oom_clean | |
parent | a43be446c10a58f5a7aea91851b4c74b9ee3d3af (diff) |
Release oom-automatic-installation
Issue-ID: INT-2150
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I8992f93e2b79f17c90d8f3c350891e8428ef3dcb
Diffstat (limited to 'roles/oom_clean')
-rw-r--r-- | roles/oom_clean/defaults/main.yaml | 8 | ||||
-rw-r--r-- | roles/oom_clean/tasks/helm3.yaml | 66 | ||||
-rw-r--r-- | roles/oom_clean/tasks/main.yaml | 151 |
3 files changed, 225 insertions, 0 deletions
diff --git a/roles/oom_clean/defaults/main.yaml b/roles/oom_clean/defaults/main.yaml new file mode 100644 index 0000000..adf0ae3 --- /dev/null +++ b/roles/oom_clean/defaults/main.yaml @@ -0,0 +1,8 @@ +faulty_pods: + - ejbca + +helm_env: {} + +helm_env_postgres: + HELM_DRIVER: sql + HELM_DRIVER_SQL_CONNECTION_STRING: "{{ postgres_url }}"
\ No newline at end of file diff --git a/roles/oom_clean/tasks/helm3.yaml b/roles/oom_clean/tasks/helm3.yaml new file mode 100644 index 0000000..f6eb3a9 --- /dev/null +++ b/roles/oom_clean/tasks/helm3.yaml @@ -0,0 +1,66 @@ +--- +- name: "[HELM3] retrieve helm postgres secret" + community.kubernetes.k8s_info: + api_version: v1 + kind: Secret + name: "{{ postgres_secret_name }}" + namespace: "{{ postgres_namespace }}" + register: postgres_secrets + when: helmv3_use_sql|bool + +- name: "[HELM3] retrieve helm postrgres password" + set_fact: + postgres_password: "{{ + postgres_secrets.resources[0].data['postgresql-password'] | b64decode }}" + when: helmv3_use_sql|bool + +- name: set helm environment with postgres + set_fact: + helm_env: "{{ helm_env_postgres }}" + when: helmv3_use_sql|bool + +- name: "[HELM3] list previously installed components" + shell: | + set -o pipefail && helm list -a -n {{ onap_namespace }} | + awk '{print $1}' | grep {{ chart_name }}- || true + args: + executable: /bin/bash + environment: "{{ helm_env }}" + register: components + changed_when: "false" + +- name: "[HELM3] remove previously installed components" + command: + "helm uninstall {{ item }} -n {{ onap_namespace }}" + loop: "{{ components.stdout_lines }}" + environment: "{{ helm_env }}" + register: helm_undeploy + async: 900 + poll: 0 + +- name: "[HELM3] Wait for component deletion" + ansible.builtin.async_status: + jid: "{{ item.ansible_job_id }}" + register: _jobs + until: _jobs.finished + delay: 5 + retries: 300 + loop: "{{ helm_undeploy.results }}" + loop_control: + label: "{{ item.item }}" + +- name: "[HELM3] check if an onap installation has been launched before" + shell: | + set -o pipefail && helm list -a -n {{ onap_namespace }} | + awk '{print $1}' | grep -c {{ chart_name }} || true + args: + executable: /bin/bash + environment: "{{ helm_env }}" + register: launched + changed_when: "false" + +- name: "[HELM3] remove previous installation" + command: + "helm uninstall {{ chart_name }} -n {{ onap_namespace }}" + environment: "{{ helm_env }}" + when: launched.stdout != '0'
\ No newline at end of file diff --git a/roles/oom_clean/tasks/main.yaml b/roles/oom_clean/tasks/main.yaml new file mode 100644 index 0000000..4f14200 --- /dev/null +++ b/roles/oom_clean/tasks/main.yaml @@ -0,0 +1,151 @@ +--- +- name: check helm version + command: "helm version --template {% raw %}'{{.Version}}'{% endraw %}" + register: helm_version + +# Return of previous command will be "v3.3.4" for v3 and up and "<no value>" +# for version 2. +- name: store helm version + ansible.builtin.set_fact: + helmv3: "{{ ('<' in helm_version.stdout) | ternary(false, true) }}" + +- name: "HELM 3 not installed - stop playbook" + ansible.builtin.fail: + msg: HELM 3 not installed + when: not helmv3 + +- name: "[HELM3] Remove previous installation" + include_tasks: helm3.yaml + when: helmv3 + +- name: get number of remaining pods + command: > + kubectl get pods --namespace {{ onap_namespace }} --no-headers + -o custom-columns=NAME:.metadata.name + changed_when: False + register: pods + +- name: delete remaining faulty pods + command: > + kubectl delete pods --namespace {{ onap_namespace }} --force + --grace-period 0 {{ item }} + loop: "{{ pods.stdout_lines }}" + when: (pods.stdout_lines | length) <= (faulty_pods | length) and + ((item | regex_replace('^[a-zA-Z0-9]+-') | + regex_replace('-[0-9a-z]+-[0-9a-z]+$')) in faulty_pods) + changed_when: True + +- name: get number of remaining jobs + command: > + kubectl get jobs --namespace {{ onap_namespace }} --no-headers + -o custom-columns=NAME:.metadata.name + changed_when: false + register: jobs + +- name: delete remaining faulty jobs + command: > + kubectl delete job --namespace {{ onap_namespace }} --force + --grace-period 0 {{ item }} + loop: "{{ jobs.stdout_lines }}" + +- name: get number of remaining pvcs + command: > + kubectl get pvc --namespace {{ onap_namespace }} --no-headers + -o custom-columns=NAME:.metadata.name + changed_when: false + register: pvcs + +- name: delete remaining faulty pvcs + command: > + kubectl delete pvc --namespace {{ onap_namespace }} --force + --grace-period 0 {{ item }} + loop: "{{ pvcs.stdout_lines }}" + +- name: check if namespace is for namespace full deletion + shell: | + set -o pipefail && kubectl get namespace {{ onap_namespace }} + -o jsonpath="{.status.phase}" || true + args: + executable: /bin/bash + register: ns_status + ignore_errors: yes + changed_when: False + +- name: delete onap namespace + community.kubernetes.k8s: + state: absent + definition: + apiVersion: v1 + kind: Namespace + metadata: + name: "{{ onap_namespace }}" + when: (not ns_status.failed) and ('Terminating' not in ns_status.stdout) + +- name: delete onap tests namespace + community.kubernetes.k8s: + state: absent + definition: + apiVersion: v1 + kind: Namespace + metadata: + name: "{{ onap_namespace }}-tests" + when: (not ns_status.failed) and ('Terminating' not in ns_status.stdout) + +- name: wait for namespace full deletion + shell: | + set -o pipefail && kubectl get namespace | + grep -c {{ onap_namespace }} || true + args: + executable: /bin/bash + register: kube + changed_when: + kube.stdout == '0' + until: + kube.stdout == '0' + retries: 600 + delay: 1 + +- name: list all remaining persistent volumes + shell: | + set -o pipefail && + kubectl get pv -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | + grep {{ chart_name }} || true + args: + executable: /bin/bash + register: persistent_volumes + changed_when: "false" + +- name: remove remaining persistent volumes + shell: | + set -o pipefail && kubectl delete pv {{ item }} || true + args: + executable: /bin/bash + changed_when: "true" + loop: "{{ persistent_volumes.stdout_lines }}" + +- name: "list all onap directories in {{ nfs_folder }}" + ansible.builtin.find: + paths: "{{ nfs_folder }}" + recurse: no + file_type: directory + register: onap_directories + +- name: "delete onap directory in {{ nfs_folder }}" + become: "yes" + ansible.builtin.file: + path: "{{ item.path }}" + state: absent + loop: "{{ onap_directories.files }}" + loop_control: + label: "{{ item.path }}" + +- name: delete component-gating-overrides.yaml if present + ansible.builtin.file: + path: "{{ override_gating_component }}" + state: absent + +- name: remove oom directory + become: "yes" + ansible.builtin.file: + path: "{{ oom_path }}" + state: absent |