mayadata-io / d-operators

Declarative patterns to write kubernetes controllers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

use case: delete openebs control plane components from a k8s cluster

amitbhatt818 opened this issue · comments

What is the issue ??

  • In our e2e pipeline we are deleting openebs components from the cluster using ansible script which is responsible for deleting opnebs from the cluster. We need to do the same using declarative approach.

Script used to remove openebs from cluster

## Check if SPC is present in the cluster
- name: Checking if SPC is present in the cluster
  shell: kubectl get spc --no-headers | wc -l
  args:
    executable: /bin/bash
  register: spc

## Clean up SPC (if any present) from the cluster
- name: Cleaning up SPC from the cluster
  shell: kubectl delete spc --all                                                            
  args:                                            
    executable: /bin/bash                          
  when: "spc.stdout > '0'"

## Check if PV is present in the cluster
- name: Checking if PV is present in the cluster
  shell: kubectl get pv -n openebs --no-headers | wc -l
  args:
    executable: /bin/bash
  register: pv

## Clean up PV (if any present) from the cluster
- name: Removing PV from the cluster
  shell: kubectl delete pv -n {{ namespace }} --all
  args:
    executable: /bin/bash
  when: "pv.stdout > '0'"

## Check if BD is present in the cluster
- name: Checking if BD is present in the cluster
  shell: kubectl get bd -n openebs --no-headers | wc -l
  args:
    executable: /bin/bash
  register: bd

## Clean up BD (if any present) from the cluster
- name: Removing Blockdevices from the cluster
  shell: kubectl delete bd -n {{ namespace }} --all
  args:
    executable: /bin/bash
  when: "bd.stdout > '0'"
      
## Cleaning up deployment
- name: Removing deployment from openebs namespace
  shell: kubectl delete deploy -n {{ namespace }} --all
  args:
    executable: /bin/bash

## Cleaning up NDM Daemonset
- name: Removing NDM DaemonSet
  shell: kubectl delete ds -n {{ namespace }} --all
  args:
    executable: /bin/bash

## Cleaning up OpenEBS Namespace
- name: Removing openebs namespace
  shell: kubectl delete ns {{ namespace }}
  args:
    executable: /bin/bash
             
## Checking openebs ns is deleted or not
- name: Waiting for graceful termination of openebs namespace
  shell: kubectl get ns --no-headers | grep {{ namespace }} | awk '{print $1}' | wc -l
  args:
    executable: /bin/bash
  register: openebs_ns
  until: "openebs_ns.stdout=='0'"
  retries: 30
  delay: 2

- name: Waiting for graceful termination of openebs pods
  shell: kubectl get pods -n {{ namespace }} --no-headers | awk '{print $1}' | wc -l
  args:
    executable: /bin/bash
  register: pod_list
  until: "pod_list.stdout=='0'"
  retries: 30
  delay: 5

- name: Check openebses should not have openebs active entry
  uri:
    url: "{{ director_url }}/v3/groups/{{ group_id }}/openebses?state=active&clusterId={{ cluster_id }}"
    url_username: "{{ username.stdout }}"
    url_password: "{{ password.stdout }}"
    method: GET
    status_code: 200
  register: openebses_active
  until: "openebses_active.json.data == []"
  delay: 10
  retries: 30