Skip to content

Commit

Permalink
CI: delete resources in order to avoid a long time waiting for subnet…
Browse files Browse the repository at this point in the history
… deletions. (#1643)
  • Loading branch information
zhangzujian committed Jun 27, 2022
1 parent 35e29e1 commit 20222e4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
59 changes: 54 additions & 5 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"testing"
"time"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -63,33 +64,81 @@ func TestE2e(t *testing.T) {

var _ = SynchronizedAfterSuite(func() {}, func() {
f := framework.NewFramework("init", fmt.Sprintf("%s/.kube/config", os.Getenv("HOME")))
nss, err := f.KubeClientSet.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{LabelSelector: "e2e=true"})
if err != nil {
Fail(err.Error())
for {
pods, err := f.KubeClientSet.CoreV1().Pods(corev1.NamespaceAll).List(context.Background(), metav1.ListOptions{LabelSelector: "e2e=true"})
if err != nil {
Fail(err.Error())
}
if len(pods.Items) == 0 {
break
}
time.Sleep(time.Second)
}
if nss != nil {

for {
nss, err := f.KubeClientSet.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{LabelSelector: "e2e=true"})
if err != nil {
Fail(err.Error())
}
if len(nss.Items) == 0 {
break
}
for _, ns := range nss.Items {
if ns.DeletionTimestamp != nil {
continue
}
err := f.KubeClientSet.CoreV1().Namespaces().Delete(context.Background(), ns.Name, metav1.DeleteOptions{})
if err != nil {
Fail(err.Error())
}
}
time.Sleep(time.Second)
}

err = f.OvnClientSet.KubeovnV1().Subnets().DeleteCollection(context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "e2e=true"})
err := f.OvnClientSet.KubeovnV1().Subnets().DeleteCollection(context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "e2e=true"})
if err != nil {
Fail(err.Error())
}
for {
subnets, err := f.OvnClientSet.KubeovnV1().Subnets().List(context.Background(), metav1.ListOptions{LabelSelector: "e2e=true"})
if err != nil {
Fail(err.Error())
}
if len(subnets.Items) == 0 {
break
}
time.Sleep(time.Second)
}

err = f.OvnClientSet.KubeovnV1().Vlans().DeleteCollection(context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "e2e=true"})
if err != nil {
Fail(err.Error())
}
for {
vlans, err := f.OvnClientSet.KubeovnV1().Vlans().List(context.Background(), metav1.ListOptions{LabelSelector: "e2e=true"})
if err != nil {
Fail(err.Error())
}
if len(vlans.Items) == 0 {
break
}
time.Sleep(time.Second)
}

err = f.OvnClientSet.KubeovnV1().ProviderNetworks().DeleteCollection(context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "e2e=true"})
if err != nil {
Fail(err.Error())
}
for {
pns, err := f.OvnClientSet.KubeovnV1().ProviderNetworks().List(context.Background(), metav1.ListOptions{LabelSelector: "e2e=true"})
if err != nil {
Fail(err.Error())
}
if len(pns.Items) == 0 {
break
}
time.Sleep(time.Second)
}
})

func setExternalRoute(af int, dst, gw string) {
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/ip/static_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ var _ = Describe("[IP Allocation]", func() {
}
err = f.WaitStatefulsetReady(name, namespace)
Expect(err).NotTo(HaveOccurred())

By("Delete statefulset")
err = f.KubeClientSet.AppsV1().StatefulSets(namespace).Delete(context.Background(), sts.Name, metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())
})
})
})

0 comments on commit 20222e4

Please sign in to comment.