From f95e14769a61559d3581d34bbddf1cb5a07f42f5 Mon Sep 17 00:00:00 2001 From: changzhen Date: Fri, 20 May 2022 12:20:33 +0800 Subject: [PATCH] log more err info when wait resource exist on member clusters Signed-off-by: changzhen --- test/e2e/framework/deployment.go | 12 ++++++++++-- test/e2e/framework/job.go | 12 ++++++++++-- test/e2e/framework/namespace.go | 12 ++++++++++-- test/e2e/framework/pod.go | 12 ++++++++++-- test/e2e/framework/resourcequota.go | 10 +++++++++- test/e2e/framework/secret.go | 12 ++++++++++-- test/e2e/framework/service.go | 12 ++++++++++-- test/e2e/framework/workload.go | 12 ++++++++++-- test/e2e/resource_test.go | 2 +- 9 files changed, 80 insertions(+), 16 deletions(-) diff --git a/test/e2e/framework/deployment.go b/test/e2e/framework/deployment.go index b21c0e6622b4..1ee3c1228e17 100644 --- a/test/e2e/framework/deployment.go +++ b/test/e2e/framework/deployment.go @@ -65,10 +65,18 @@ func WaitDeploymentDisappearOnCluster(cluster, namespace, name string) { clusterClient := GetClusterClient(cluster) gomega.Expect(clusterClient).ShouldNot(gomega.BeNil()) - klog.Infof("Waiting for deployment disappear on cluster(%s)", cluster) + klog.Infof("Waiting for deployment(%s/%s) disappear on cluster(%s)", namespace, name, cluster) gomega.Eventually(func() bool { _, err := clusterClient.AppsV1().Deployments(namespace).Get(context.TODO(), name, metav1.GetOptions{}) - return apierrors.IsNotFound(err) + if err == nil { + return false + } + if apierrors.IsNotFound(err) { + return true + } + + klog.Errorf("Failed to get deployment(%s/%s) on cluster(%s), err: %v", namespace, name, cluster, err) + return false }, pollTimeout, pollInterval).Should(gomega.Equal(true)) } diff --git a/test/e2e/framework/job.go b/test/e2e/framework/job.go index ecf6a22eb187..3b43af3affcb 100644 --- a/test/e2e/framework/job.go +++ b/test/e2e/framework/job.go @@ -68,10 +68,18 @@ func WaitJobDisappearOnCluster(cluster, namespace, name string) { clusterClient := GetClusterClient(cluster) gomega.Expect(clusterClient).ShouldNot(gomega.BeNil()) - klog.Infof("Waiting for job disappear on cluster(%s)", cluster) + klog.Infof("Waiting for job(%s/%s) disappear on cluster(%s)", namespace, name, cluster) gomega.Eventually(func() bool { _, err := clusterClient.BatchV1().Jobs(namespace).Get(context.TODO(), name, metav1.GetOptions{}) - return apierrors.IsNotFound(err) + if err == nil { + return false + } + if apierrors.IsNotFound(err) { + return true + } + + klog.Errorf("Failed to get job(%s/%s) on cluster(%s), err: %v", namespace, name, cluster, err) + return false }, pollTimeout, pollInterval).Should(gomega.Equal(true)) } diff --git a/test/e2e/framework/namespace.go b/test/e2e/framework/namespace.go index 62e37b44b0ee..638eb01338e4 100644 --- a/test/e2e/framework/namespace.go +++ b/test/e2e/framework/namespace.go @@ -66,10 +66,18 @@ func WaitNamespaceDisappearOnCluster(cluster, name string) { clusterClient := GetClusterClient(cluster) gomega.Expect(clusterClient).ShouldNot(gomega.BeNil()) - klog.Infof("Waiting for namespace disappear on cluster(%s)", cluster) + klog.Infof("Waiting for namespace(%s) disappear on cluster(%s)", name, cluster) gomega.Eventually(func() bool { _, err := clusterClient.CoreV1().Namespaces().Get(context.TODO(), name, metav1.GetOptions{}) - return apierrors.IsNotFound(err) + if err == nil { + return false + } + if apierrors.IsNotFound(err) { + return true + } + + klog.Errorf("Failed to get namespace(%s) on cluster(%s), err: %v", name, cluster, err) + return false }, pollTimeout, pollInterval).Should(gomega.Equal(true)) } diff --git a/test/e2e/framework/pod.go b/test/e2e/framework/pod.go index b163130d8e87..89c1a0edd1c2 100644 --- a/test/e2e/framework/pod.go +++ b/test/e2e/framework/pod.go @@ -60,10 +60,18 @@ func WaitPodDisappearOnCluster(cluster, namespace, name string) { clusterClient := GetClusterClient(cluster) gomega.Expect(clusterClient).ShouldNot(gomega.BeNil()) - klog.Infof("Waiting for pod disappear on cluster(%s)", cluster) + klog.Infof("Waiting for pod(%s/%s) disappear on cluster(%s)", namespace, name, cluster) gomega.Eventually(func() bool { _, err := clusterClient.CoreV1().Pods(namespace).Get(context.TODO(), name, metav1.GetOptions{}) - return apierrors.IsNotFound(err) + if err == nil { + return false + } + if apierrors.IsNotFound(err) { + return true + } + + klog.Errorf("Failed to get pod(%s/%s) on cluster(%s), err: %v", namespace, name, cluster, err) + return false }, pollTimeout, pollInterval).Should(gomega.Equal(true)) } diff --git a/test/e2e/framework/resourcequota.go b/test/e2e/framework/resourcequota.go index 566f918b690e..f27c74f92085 100644 --- a/test/e2e/framework/resourcequota.go +++ b/test/e2e/framework/resourcequota.go @@ -50,6 +50,14 @@ func WaitResourceQuotaDisappearOnCluster(cluster, namespace, name string) { klog.Infof("Waiting for resourceQuota(%s/%s) disappear on cluster(%s)", namespace, name, cluster) gomega.Eventually(func() bool { _, err := clusterClient.CoreV1().ResourceQuotas(namespace).Get(context.TODO(), name, metav1.GetOptions{}) - return apierrors.IsNotFound(err) + if err == nil { + return false + } + if apierrors.IsNotFound(err) { + return true + } + + klog.Errorf("Failed to get resourceQuota(%s/%s) on cluster(%s), err: %v", namespace, name, cluster, err) + return false }, pollTimeout, pollInterval).Should(gomega.Equal(true)) } diff --git a/test/e2e/framework/secret.go b/test/e2e/framework/secret.go index a452444519dc..861a1ae8f58e 100644 --- a/test/e2e/framework/secret.go +++ b/test/e2e/framework/secret.go @@ -58,10 +58,18 @@ func WaitSecretDisappearOnCluster(cluster, namespace, name string) { clusterClient := GetClusterClient(cluster) gomega.Expect(clusterClient).ShouldNot(gomega.BeNil()) - klog.Infof("Waiting for secret disappear on cluster(%s)", cluster) + klog.Infof("Waiting for secret(%s/%s) disappear on cluster(%s)", namespace, name, cluster) gomega.Eventually(func() bool { _, err := clusterClient.CoreV1().Secrets(namespace).Get(context.TODO(), name, metav1.GetOptions{}) - return apierrors.IsNotFound(err) + if err == nil { + return false + } + if apierrors.IsNotFound(err) { + return true + } + + klog.Errorf("Failed to get secret(%s/%s) on cluster(%s), err: %v", namespace, name, cluster, err) + return false }, pollTimeout, pollInterval).Should(gomega.Equal(true)) } diff --git a/test/e2e/framework/service.go b/test/e2e/framework/service.go index f881e639a48a..8af4d28a23be 100644 --- a/test/e2e/framework/service.go +++ b/test/e2e/framework/service.go @@ -60,10 +60,18 @@ func WaitServiceDisappearOnCluster(cluster, namespace, name string) { clusterClient := GetClusterClient(cluster) gomega.Expect(clusterClient).ShouldNot(gomega.BeNil()) - klog.Infof("Waiting for service disappear on cluster(%s)", cluster) + klog.Infof("Waiting for service(%s/%s) disappear on cluster(%s)", namespace, name, cluster) gomega.Eventually(func() bool { _, err := clusterClient.CoreV1().Services(namespace).Get(context.TODO(), name, metav1.GetOptions{}) - return apierrors.IsNotFound(err) + if err == nil { + return false + } + if apierrors.IsNotFound(err) { + return true + } + + klog.Errorf("Failed to get service(%s/%s) on cluster(%s), err: %v", namespace, name, cluster, err) + return false }, pollTimeout, pollInterval).Should(gomega.Equal(true)) } diff --git a/test/e2e/framework/workload.go b/test/e2e/framework/workload.go index 8e1a0f168371..649134b79ed1 100644 --- a/test/e2e/framework/workload.go +++ b/test/e2e/framework/workload.go @@ -98,10 +98,18 @@ func WaitWorkloadDisappearOnCluster(cluster, namespace, name string) { clusterClient := GetClusterDynamicClient(cluster) gomega.Expect(clusterClient).ShouldNot(gomega.BeNil()) - klog.Infof("Waiting for workload disappear on cluster(%s)", cluster) + klog.Infof("Waiting for workload(%s/%s) disappear on cluster(%s)", namespace, name, cluster) gomega.Eventually(func() bool { _, err := clusterClient.Resource(workloadGVR).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{}) - return apierrors.IsNotFound(err) + if err == nil { + return false + } + if apierrors.IsNotFound(err) { + return true + } + + klog.Errorf("Failed to get workload(%s/%s) on cluster(%s), err: %v", namespace, name, cluster, err) + return false }, pollTimeout, pollInterval).Should(gomega.Equal(true)) } diff --git a/test/e2e/resource_test.go b/test/e2e/resource_test.go index 9b24266db301..783a7f3649c4 100644 --- a/test/e2e/resource_test.go +++ b/test/e2e/resource_test.go @@ -119,7 +119,7 @@ var _ = ginkgo.Describe("[resource-status collection] resource status collection ginkgo.BeforeEach(func() { policyNamespace = testNamespace - policyName = deploymentNamePrefix + rand.String(RandomStrLength) + policyName = serviceNamePrefix + rand.String(RandomStrLength) serviceNamespace = testNamespace serviceName = policyName