def delete_pvc_pod(self): """ Function to delete pvc and pod based on the delete pod count. """ log.info(f"Delete {self.delete_pod_count} pods and respective pvcs") temp_pod_list = random.choices(self.all_pod_obj, k=self.delete_pod_count) temp_pvc_list = [] for pod_obj in temp_pod_list: list_counter_for_pvc = 0 for pvc_obj in self.all_pvc_obj: if pvc_obj is not None: if type(pvc_obj) is list: for pvc_ in pvc_obj: if pod.get_pvc_name(pod_obj) == pvc_.name: temp_pvc_list.append(pvc_) log.info(f"Deleting pvc {pvc_.name}") self.all_pvc_obj[list_counter_for_pvc].remove( pvc_) else: if pod.get_pvc_name(pod_obj) == pvc_obj.name: temp_pvc_list.append(pvc_obj) log.info(f"Deleting pvc {pvc_obj.name}") self.all_pvc_obj.remove(pvc_obj) list_counter_for_pvc += 1 log.info(f"Deleting pod {pod_obj.name}") if pod_obj in self.all_pod_obj: self.all_pod_obj.remove(pod_obj) helpers.delete_objs_parallel(temp_pod_list) helpers.delete_objs_parallel(temp_pvc_list)
def get_registry_pvc(): """ Function to get registry pvc Returns: pvc_name (str): Returns name of the OCS pvc backed for registry """ pod_obj = get_registry_pod_obj() return pod.get_pvc_name(pod_obj)
def get_attached_pods(self): """ Get the pods attached to the PVC represented by this object instance Returns: list: A list of pod objects attached to the PVC """ # Importing from pod inside, because of unsolvable import loop from ocs_ci.ocs.resources.pod import get_all_pods, get_pvc_name attached_pods = [] all_pods = get_all_pods() for pod_obj in all_pods: try: pvc = get_pvc_name(pod_obj) except UnavailableResourceException: continue if pvc == self.name: attached_pods.append(pod_obj) return attached_pods
def uninstall_ocs(): """ The function uninstalls the OCS operator from a openshift cluster and removes all its settings and dependencies """ ocp_obj = ocp.OCP() provisioners = constants.OCS_PROVISIONERS # List the storage classes sc_list = get_all_storageclass() sc_name_list = [] for storage_class in sc_list: if storage_class.get('provisioner') not in provisioners: sc_list.remove(storage_class) else: sc_name_list.append(storage_class.get('metadata').get('name')) # Query for PVCs and OBCs that are using the storage class provisioners listed in the previous step. pvc_to_delete = [] pvc_name_list = [] for sc in sc_name_list: pvc_to_delete.extend(get_all_pvcs_in_storageclass(sc)) # ignoring all noobaa pvcs & make name list for pvc in pvc_to_delete: if "noobaa" in pvc.name: pvc_to_delete.remove(pvc) else: pvc_name_list.append(pvc.name) pods_to_delete = [] all_pods = get_all_pods() # default openshift-storage namespace all_pods.extend(get_all_pods(namespace=constants.OPENSHIFT_IMAGE_REGISTRY_NAMESPACE)) all_pods.extend(get_all_pods(namespace=constants.OPENSHIFT_MONITORING_NAMESPACE)) for pod_obj in all_pods: try: pvc_name = get_pvc_name(pod_obj) except UnavailableResourceException: continue if pvc_name in pvc_name_list: pods_to_delete.append(pod_obj) log.info("Removing monitoring stack from OpenShift Container Storage") remove_monitoring_stack_from_ocs() log.info("Removing OpenShift Container Platform registry from OpenShift Container Storage") remove_ocp_registry_from_ocs(config.ENV_DATA['platform']) log.info("Removing the cluster logging operator from OpenShift Container Storage") csv = ocp.OCP( kind=constants.CLUSTER_SERVICE_VERSION, namespace=constants.OPENSHIFT_LOGGING_NAMESPACE ) logging_csv = csv.get().get('items') if logging_csv: clusterlogging_obj = ocp.OCP( kind=constants.CLUSTER_LOGGING, namespace=constants.OPENSHIFT_LOGGING_NAMESPACE ) clusterlogging_obj.delete(resource_name='instance') log.info("deleting pvcs") for pvc in pvc_to_delete: log.info(f"deleting pvc: {pvc.name}") pvc.delete() log.info("deleting pods") for pod in pods_to_delete: log.info(f"deleting pod {pod.name}") pod.delete() log.info("removing rook directory from nodes") nodes_list = get_labeled_nodes(constants.OPERATOR_NODE_LABEL) for node in nodes_list: log.info(f"removing rook from {node}") ocp_obj.exec_oc_debug_cmd(node=node, cmd_list=["rm -rf /var/lib/rook"]) log.info("Delete the storage classes with an openshift-storage provisioner list") for storage_class in sc_list: log.info(f"deleting storage class {storage_class.get('metadata').get('name')}") sc_obj = ocp.OCP(kind=constants.STORAGECLASS) sc_obj.delete(resource_name=storage_class.get('metadata').get('name')) log.info("unlabaling storage nodes") nodes_list = get_all_nodes() for node in nodes_list: node_obj = ocp.OCP(kind=constants.NODE, resource_name=node) node_obj.add_label(resource_name=node, label=constants.OPERATOR_NODE_LABEL[:-3] + '-') node_obj.add_label(resource_name=node, label=constants.TOPOLOGY_ROOK_LABEL + '-') log.info("deleting storageCluster object") storage_cluster = ocp.OCP(kind=constants.STORAGECLUSTER, resource_name=constants.DEFAULT_CLUSTERNAME) storage_cluster.delete(resource_name=constants.DEFAULT_CLUSTERNAME) log.info("removing CRDs") crd_list = ['backingstores.noobaa.io', 'bucketclasses.noobaa.io', 'cephblockpools.ceph.rook.io', 'cephfilesystems.ceph.rook.io', 'cephnfses.ceph.rook.io', 'cephobjectstores.ceph.rook.io', 'cephobjectstoreusers.ceph.rook.io', 'noobaas.noobaa.io', 'ocsinitializations.ocs.openshift.io', 'storageclusterinitializations.ocs.openshift.io', 'storageclusters.ocs.openshift.io', 'cephclusters.ceph.rook.io'] for crd in crd_list: ocp_obj.exec_oc_cmd(f"delete crd {crd} --timeout=300m") log.info("deleting openshift-storage namespace") ocp_obj.delete_project('openshift-storage') ocp_obj.wait_for_delete('openshift-storage')