tests: ensure cluster finalizer removed during cleanup

The tests must ensure that the cluster is cleaned up so that
other test suites will not be affected by cleanup of a previous
test suite. Removing the cluster finalizer is critical to this
cleanup.

Signed-off-by: travisn <tnielsen@redhat.com>
This commit is contained in:
travisn committed 2019-10-14 09:29:46 -06:00
1 parent 2b3d1f45ef
commit d1680b2cca
1 file changed
+23
@@ -383,6 +383,8 @@ func (h *CephInstaller) UninstallRookFromMultipleNS(gatherLogs bool, systemNames
crdCheckerFunc := func() error {
_, err := h.k8shelper.RookClientset.CephV1().CephClusters(namespace).Get(namespace, metav1.GetOptions{})
// ensure the finalizer(s) are removed
h.removeClusterFinalizers(namespace, namespace)
return err
}
err = h.k8shelper.WaitForCustomResourceDeletion(namespace, crdCheckerFunc)
@@ -473,6 +475,27 @@ func (h *CephInstaller) UninstallRookFromMultipleNS(gatherLogs bool, systemNames
}
}
func (h *CephInstaller) removeClusterFinalizers(namespace, name string) {
// Get the latest cluster instead of using the same instance in case it has been changed
cluster, err := h.k8shelper.RookClientset.CephV1().CephClusters(namespace).Get(name, metav1.GetOptions{})
if err != nil {
logger.Errorf("failed to remove finalizer. failed to get cluster. %+v", err)
return
}
objectMeta := &cluster.ObjectMeta
if len(objectMeta.Finalizers) == 0 {
logger.Infof("no finalizers to remove from cluster %s", name)
return
}
objectMeta.Finalizers = nil
_, err = h.k8shelper.RookClientset.CephV1().CephClusters(cluster.Namespace).Update(cluster)
if err != nil {
logger.Errorf("failed to remove finalizers from cluster %s. %+v", objectMeta.Name, err)
return
}
logger.Infof("removed finalizers from cluster %s", objectMeta.Name)
}
func (h *CephInstaller) purgeClusters() error {
// get all namespaces
namespaces, err := h.k8shelper.Clientset.CoreV1().Namespaces().List(metav1.ListOptions{})