func DeleteAllVolumeResources() (bool, bool) {
	logf.Log.Info("DeleteAllVolumeResources")
	foundResources := false
	success := true

	// Delete all PVCs found
	// Phase 1 to delete dangling resources
	pvcs, err := gTestEnv.KubeInt.CoreV1().PersistentVolumeClaims("default").List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		logf.Log.Error(err, "DeleteAllVolumeResources: list PVCs failed.")
		success = false
	}
	if err == nil && pvcs != nil && len(pvcs.Items) != 0 {
		foundResources = true
		logf.Log.Info("DeleteAllVolumeResources: deleting PersistentVolumeClaims")
		for _, pvc := range pvcs.Items {
			if err := DeletePVC(pvc.Name); err != nil {
				success = false
			}
		}
	}

	// Delete all PVs found
	pvs, err := gTestEnv.KubeInt.CoreV1().PersistentVolumes().List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		logf.Log.Error(err, "DeleteAllVolumeResources: list PVs failed.")
	}
	if err == nil && pvs != nil && len(pvs.Items) != 0 {
		logf.Log.Info("DeleteAllVolumeResources: deleting PersistentVolumes")
		for _, pv := range pvs.Items {
			if err := gTestEnv.KubeInt.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, metav1.DeleteOptions{}); err != nil {
				success = false
			}
		}
	}

	// Wait 2 minutes for resources to be deleted
	for attempts := 0; attempts < 120; attempts++ {
		numPvcs := 0
		pvcs, err := gTestEnv.KubeInt.CoreV1().PersistentVolumeClaims("default").List(context.TODO(), metav1.ListOptions{})
		if err == nil && pvcs != nil {
			numPvcs = len(pvcs.Items)
		}

		numPvs := 0
		pvs, err := gTestEnv.KubeInt.CoreV1().PersistentVolumes().List(context.TODO(), metav1.ListOptions{})
		if err == nil && pvs != nil {
			numPvs = len(pvs.Items)
		}

		if numPvcs == 0 && numPvs == 0 {
			break
		}
		time.Sleep(1 * time.Second)
	}

	// If after deleting PVCs and PVs Mayastor volumes are leftover
	// try cleaning them up explicitly
	msvGVR := schema.GroupVersionResource{
		Group:    "openebs.io",
		Version:  "v1alpha1",
		Resource: "mayastorvolumes",
	}

	msvs, err := gTestEnv.DynamicClient.Resource(msvGVR).Namespace("mayastor").List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		// This function may be called by AfterSuite by uninstall test so listing MSVs may fail correctly
		logf.Log.Info("DeleteAllVolumeResources: list MSVs failed.", "Error", err)
	}
	if err == nil && msvs != nil && len(msvs.Items) != 0 {
		logf.Log.Info("DeleteAllVolumeResources: deleting MayastorVolumes")
		for _, msv := range msvs.Items {
			if err := DeleteMSV(msv.GetName()); err != nil {
				success = false
			}
		}
	}

	// Wait 2 minutes for resources to be deleted
	for attempts := 0; attempts < 120; attempts++ {
		numMsvs := 0
		msvs, err := gTestEnv.DynamicClient.Resource(msvGVR).Namespace("mayastor").List(context.TODO(), metav1.ListOptions{})
		if err == nil && msvs != nil {
			numMsvs = len(msvs.Items)
		}
		if numMsvs == 0 {
			break
		}
		time.Sleep(1 * time.Second)
	}

	return success, foundResources
}
// Make best attempt to delete PVCs, PVs and MSVs
Make best attempt to delete PVCs, PVs and MSVs
// Make best attempt to delete PVCs PVs and MSVs
func DeleteAllVolumeResources() (bool, bool) {
	logf.Log.Info("DeleteAllVolumeResources")
	foundResources := false
	success := true
	pvcs, err := gTestEnv.KubeInt.CoreV1().PersistentVolumeClaims("default").List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		logf.Log.Error(err, "DeleteAllVolumeResources: list PVCs failed.")
		success = false
	}
	if err == nil && pvcs != nil && len(pvcs.Items) != 0 {
		foundResources = true
		logf.Log.Info("DeleteAllVolumeResources: deleting PersistentVolumeClaims")
		for _, pvc := range pvcs.Items {
			if err := DeletePVC(pvc.Name); err != nil {
				success = false
			}
		}
	}
	pvs, err := gTestEnv.KubeInt.CoreV1().PersistentVolumes().List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		logf.Log.Error(err, "DeleteAllVolumeResources: list PVs failed.")
	}
	if err == nil && pvs != nil && len(pvs.Items) != 0 {
		logf.Log.Info("DeleteAllVolumeResources: deleting PersistentVolumes")
		for _, pv := range pvs.Items {
			if err := gTestEnv.KubeInt.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, metav1.DeleteOptions{}); err != nil {
				success = false
			}
		}
	}
	for attempts := 0; attempts < 120; attempts++ {
		numPvcs := 0
		pvcs, err := gTestEnv.KubeInt.CoreV1().PersistentVolumeClaims("default").List(context.TODO(), metav1.ListOptions{})
		if err == nil && pvcs != nil {
			numPvcs = len(pvcs.Items)
		}
		numPvs := 0
		pvs, err := gTestEnv.KubeInt.CoreV1().PersistentVolumes().List(context.TODO(), metav1.ListOptions{})
		if err == nil && pvs != nil {
			numPvs = len(pvs.Items)
		}
		if numPvcs == 0 && numPvs == 0 {
			break
		}
		time.Sleep(1 * time.Second)
	}
	msvGVR := schema.GroupVersionResource{
		Group:    "openebs.io",
		Version:  "v1alpha1",
		Resource: "mayastorvolumes",
	}
	msvs, err := gTestEnv.DynamicClient.Resource(msvGVR).Namespace("mayastor").List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		logf.Log.Info("DeleteAllVolumeResources: list MSVs failed.", "Error", err)
	}
	if err == nil && msvs != nil && len(msvs.Items) != 0 {
		logf.Log.Info("DeleteAllVolumeResources: deleting MayastorVolumes")
		for _, msv := range msvs.Items {
			if err := DeleteMSV(msv.GetName()); err != nil {
				success = false
			}
		}
	}
	for attempts := 0; attempts < 120; attempts++ {
		numMsvs := 0
		msvs, err := gTestEnv.DynamicClient.Resource(msvGVR).Namespace("mayastor").List(context.TODO(), metav1.ListOptions{})
		if err == nil && msvs != nil {
			numMsvs = len(msvs.Items)
		}
		if numMsvs == 0 {
			break
		}
		time.Sleep(1 * time.Second)
	}
	return success, foundResources
}
func DeleteAllVolumeResources ( ) ( bool , bool ) { logf . Log . Info ( " " ) foundResources := false success := true pvcs , err := gTestEnv . KubeInt . CoreV1 ( ) . PersistentVolumeClaims ( " " ) . List ( context . TODO ( ) , metav1 . ListOptions { } ) if err != nil { logf . Log . Error ( err , " " ) success = false } if err == nil && pvcs != nil && len ( pvcs . Items ) != 0 { foundResources = true logf . Log . Info ( " " ) for _ , pvc := range pvcs . Items { if err := DeletePVC ( pvc . Name ) ; err != nil { success = false } } } pvs , err := gTestEnv . KubeInt . CoreV1 ( ) . PersistentVolumes ( ) . List ( context . TODO ( ) , metav1 . ListOptions { } ) if err != nil { logf . Log . Error ( err , " " ) } if err == nil && pvs != nil && len ( pvs . Items ) != 0 { logf . Log . Info ( " " ) for _ , pv := range pvs . Items { if err := gTestEnv . KubeInt . CoreV1 ( ) . PersistentVolumes ( ) . Delete ( context . TODO ( ) , pv . Name , metav1 . DeleteOptions { } ) ; err != nil { success = false } } } for attempts := 0 ; attempts < 120 ; attempts ++ { numPvcs := 0 pvcs , err := gTestEnv . KubeInt . CoreV1 ( ) . PersistentVolumeClaims ( " " ) . List ( context . TODO ( ) , metav1 . ListOptions { } ) if err == nil && pvcs != nil { numPvcs = len ( pvcs . Items ) } numPvs := 0 pvs , err := gTestEnv . KubeInt . CoreV1 ( ) . PersistentVolumes ( ) . List ( context . TODO ( ) , metav1 . ListOptions { } ) if err == nil && pvs != nil { numPvs = len ( pvs . Items ) } if numPvcs == 0 && numPvs == 0 { break } time . Sleep ( 1 * time . Second ) } msvGVR := schema . GroupVersionResource { Group : " " , Version : " " , Resource : " " , } msvs , err := gTestEnv . DynamicClient . Resource ( msvGVR ) . Namespace ( " " ) . List ( context . TODO ( ) , metav1 . ListOptions { } ) if err != nil { logf . Log . Info ( " " , " " , err ) } if err == nil && msvs != nil && len ( msvs . Items ) != 0 { logf . Log . Info ( " " ) for _ , msv := range msvs . Items { if err := DeleteMSV ( msv . GetName ( ) ) ; err != nil { success = false } } } for attempts := 0 ; attempts < 120 ; attempts ++ { numMsvs := 0 msvs , err := gTestEnv . DynamicClient . Resource ( msvGVR ) . Namespace ( " " ) . List ( context . TODO ( ) , metav1 . ListOptions { } ) if err == nil && msvs != nil { numMsvs = len ( msvs . Items ) } if numMsvs == 0 { break } time . Sleep ( 1 * time . Second ) } return success , foundResources }
Make best attempt to delete PVCs, PVs and MSVs
Make best attempt to delete PVCs PVs and MSVs
// Delete all PVCs found // Phase 1 to delete dangling resources // Delete all PVs found // Wait 2 minutes for resources to be deleted // If after deleting PVCs and PVs Mayastor volumes are leftover // try cleaning them up explicitly // This function may be called by AfterSuite by uninstall test so listing MSVs may fail correctly // Wait 2 minutes for resources to be deleted