mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 05:46:37 +00:00
Fix e2e 2500 namespaces scale test timeout problem
Signed-off-by: Ming <mqiu@vmware.com>
This commit is contained in:
1
changelogs/unreleased/4480-mqiu
Normal file
1
changelogs/unreleased/4480-mqiu
Normal file
@@ -0,0 +1 @@
|
||||
Fix e2e 2500 namespaces scale test timeout problem
|
||||
@@ -92,9 +92,12 @@ func (m *MultiNSBackup) Init() error {
|
||||
func (m *MultiNSBackup) CreateResources() error {
|
||||
m.Ctx, _ = context.WithTimeout(context.Background(), m.TimeoutDuration)
|
||||
fmt.Printf("Creating namespaces ...\n")
|
||||
labels := map[string]string{
|
||||
"ns-test": "true",
|
||||
}
|
||||
for nsNum := 0; nsNum < m.NamespacesTotal; nsNum++ {
|
||||
createNSName := fmt.Sprintf("%s-%00000d", m.NSBaseName, nsNum)
|
||||
if err := CreateNamespace(m.Ctx, m.Client, createNSName); err != nil {
|
||||
if err := CreateNamespaceWithLabel(m.Ctx, m.Client, createNSName, labels); err != nil {
|
||||
return errors.Wrapf(err, "Failed to create namespace %s", createNSName)
|
||||
}
|
||||
}
|
||||
@@ -108,10 +111,17 @@ func (m *MultiNSBackup) Verify() error {
|
||||
checkNS, err := GetNamespace(m.Ctx, m.Client, checkNSName)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not retrieve test namespace %s", checkNSName)
|
||||
}
|
||||
if checkNS.Name != checkNSName {
|
||||
} else if checkNS.Name != checkNSName {
|
||||
return errors.Errorf("Retrieved namespace for %s has name %s instead", checkNSName, checkNS.Name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MultiNSBackup) Destroy() error {
|
||||
err := CleanupNamespaces(m.Ctx, m.Client, m.NSBaseName)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Could cleanup retrieve namespaces")
|
||||
}
|
||||
return WaitAllSelectedNSDeleted(m.Ctx, m.Client, "ns-test=true")
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
waitutil "k8s.io/apimachinery/pkg/util/wait"
|
||||
|
||||
"github.com/vmware-tanzu/velero/pkg/builder"
|
||||
@@ -89,7 +88,7 @@ func DeleteNamespace(ctx context.Context, client TestClient, namespace string, w
|
||||
}
|
||||
|
||||
func CleanupNamespacesWithPoll(ctx context.Context, client TestClient, nsBaseName string) error {
|
||||
namespaces, err := client.ClientGo.CoreV1().Namespaces().List(ctx, v1.ListOptions{})
|
||||
namespaces, err := client.ClientGo.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Could not retrieve namespaces")
|
||||
}
|
||||
@@ -105,13 +104,13 @@ func CleanupNamespacesWithPoll(ctx context.Context, client TestClient, nsBaseNam
|
||||
}
|
||||
|
||||
func CleanupNamespaces(ctx context.Context, client TestClient, nsBaseName string) error {
|
||||
namespaces, err := client.ClientGo.CoreV1().Namespaces().List(ctx, v1.ListOptions{})
|
||||
namespaces, err := client.ClientGo.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Could not retrieve namespaces")
|
||||
}
|
||||
for _, checkNamespace := range namespaces.Items {
|
||||
if strings.HasPrefix(checkNamespace.Name, nsBaseName) {
|
||||
err = client.ClientGo.CoreV1().Namespaces().Delete(ctx, checkNamespace.Name, v1.DeleteOptions{})
|
||||
err = client.ClientGo.CoreV1().Namespaces().Delete(ctx, checkNamespace.Name, metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not delete namespace %s", checkNamespace.Name)
|
||||
}
|
||||
@@ -119,3 +118,19 @@ func CleanupNamespaces(ctx context.Context, client TestClient, nsBaseName string
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func WaitAllSelectedNSDeleted(ctx context.Context, client TestClient, label string) error {
|
||||
return waitutil.PollImmediateInfinite(5*time.Second,
|
||||
func() (bool, error) {
|
||||
if ns, err := client.ClientGo.CoreV1().Namespaces().List(ctx, metav1.ListOptions{LabelSelector: label}); err != nil {
|
||||
return false, err
|
||||
} else if ns == nil {
|
||||
return true, nil
|
||||
} else if len(ns.Items) == 0 {
|
||||
return true, nil
|
||||
} else {
|
||||
logrus.Debugf("%d namespaces is still being deleted...\n", len(ns.Items))
|
||||
return false, nil
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user