Skip to content

Commit

Permalink
Merge pull request rook#2127 from travisn/cleanup-integration-test
Browse files Browse the repository at this point in the history
Make integration tests more resilient to crd deletion failure
  • Loading branch information
travisn authored Sep 17, 2018
2 parents bcb7137 + 1266c63 commit b6acc6d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/framework/installer/ceph_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func (h *CephInstaller) CreateCephCRDs() error {
return err
}

// ensure all the cluster CRDs are removed
if err = h.k8shelper.PurgeClusters(); err != nil {
logger.Warningf("could not purge cluster crds. %+v", err)
}

// remove the finalizer from the cluster CRD
if _, err := h.k8shelper.Kubectl("patch", "crd", "clusters.ceph.rook.io", "-p", `{"metadata":{"finalizers": []}}`, "--type=merge"); err != nil {
logger.Warningf("could not remove finalizer from cluster crd. %+v", err)
Expand Down
29 changes: 29 additions & 0 deletions tests/framework/utils/k8s_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,35 @@ func (k8sh *K8sHelper) Kubectl(args ...string) (string, error) {
return result, nil
}

func (k8sh *K8sHelper) PurgeClusters() error {
// get all namespaces
namespaces, err := k8sh.Clientset.CoreV1().Namespaces().List(metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to get namespaces to remove finalizers. %+v", err)
}

// look for the clusters in all namespaces
for _, n := range namespaces.Items {
namespace := n.Name
logger.Infof("looking in namespace %s for clusters to purge", namespace)
clusters, err := k8sh.RookClientset.CephV1beta1().Clusters(namespace).List(metav1.ListOptions{})
if err != nil {
logger.Warningf("failed to get clusters in namespace %s. %+v", namespace, err)
continue
}
for _, cluster := range clusters.Items {
logger.Infof("Ensuring rook cluster crd %s in namespace %s is deleted", cluster.Name, namespace)
if _, err := k8sh.Kubectl("patch", "clusters.ceph.rook.io", cluster.Name, "-n", namespace, "-p", `{"metadata":{"finalizers": []}}`, "--type=merge"); err != nil {
logger.Warningf("failed to remove finalizer from cluster %s. %+v", cluster.Name, err)
}
if err := k8sh.RookClientset.CephV1beta1().Clusters(namespace).Delete(cluster.Name, &metav1.DeleteOptions{}); err != nil {
logger.Warningf("failed to delete cluster %s", cluster.Name)
}
}
}
return nil
}

//KubectlWithStdin is wrapper for executing kubectl commands in stdin
func (k8sh *K8sHelper) KubectlWithStdin(stdin string, args ...string) (string, error) {

Expand Down

0 comments on commit b6acc6d

Please sign in to comment.