From 252dd7de97ed8f28b079353793696afc40391e4b Mon Sep 17 00:00:00 2001 From: jwcesign Date: Tue, 15 Nov 2022 14:56:34 +0800 Subject: [PATCH] Fix PP/CPP e2e probabilistic failure Signed-off-by: jwcesign --- test/e2e/clusterpropagationpolicy_test.go | 22 +++++++++++++++++----- test/e2e/propagationpolicy_test.go | 23 ++++++++++++++++++----- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/test/e2e/clusterpropagationpolicy_test.go b/test/e2e/clusterpropagationpolicy_test.go index 4e14b01ee..b2c922e13 100644 --- a/test/e2e/clusterpropagationpolicy_test.go +++ b/test/e2e/clusterpropagationpolicy_test.go @@ -2,6 +2,7 @@ package e2e import ( "fmt" + "time" "github.com/onsi/ginkgo/v2" appsv1 "k8s.io/api/apps/v1" @@ -10,6 +11,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/rand" + "k8s.io/klog/v2" policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" "github.com/karmada-io/karmada/test/e2e/framework" @@ -333,9 +335,9 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { var priorityLabelValue = "priority" ginkgo.BeforeEach(func() { - higherPriorityLabelSelector = deploymentNamePrefix + rand.String(RandomStrLength) - lowerPriorityMatchName = deploymentNamePrefix + rand.String(RandomStrLength) - implicitPriorityMatchName = deploymentNamePrefix + rand.String(RandomStrLength) + higherPriorityLabelSelector = deploymentNamePrefix + "higherprioritylabelselector" + rand.String(RandomStrLength) + lowerPriorityMatchName = deploymentNamePrefix + "lowerprioritymatchname" + rand.String(RandomStrLength) + implicitPriorityMatchName = deploymentNamePrefix + "implicitprioritymatchname" + rand.String(RandomStrLength) deploymentNamespace = testNamespace deploymentName = deploymentNamePrefix + rand.String(RandomStrLength) @@ -380,6 +382,10 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { framework.CreateClusterPropagationPolicy(karmadaClient, policyHigherPriorityLabelSelector) framework.CreateClusterPropagationPolicy(karmadaClient, policyLowerPriorityMatchName) framework.CreateClusterPropagationPolicy(karmadaClient, policyImplicitPriorityMatchName) + + // Wait policy present in cache + time.Sleep(time.Second) + framework.CreateDeployment(kubeClient, deployment) ginkgo.DeferCleanup(func() { framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name) @@ -395,6 +401,7 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { ginkgo.By("check whether the deployment uses the highest explicit priority ClusterPropagationPolicy", func() { framework.WaitDeploymentPresentOnClustersFitWith(framework.ClusterNames(), deployment.Namespace, deployment.Name, func(deployment *appsv1.Deployment) bool { + klog.Infof("Matched ClusterPropagationPolicy:%s", deployment.GetLabels()[policyv1alpha1.ClusterPropagationPolicyLabel]) return deployment.GetLabels()[policyv1alpha1.ClusterPropagationPolicyLabel] == higherPriorityLabelSelector }) }) @@ -410,8 +417,8 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { var priorityLabelValue = "priority" ginkgo.BeforeEach(func() { - explicitPriorityLabelSelector = deploymentNamePrefix + rand.String(RandomStrLength) - explicitPriorityMatchName = deploymentNamePrefix + rand.String(RandomStrLength) + explicitPriorityLabelSelector = deploymentNamePrefix + "explicitprioritylabelselector" + rand.String(RandomStrLength) + explicitPriorityMatchName = deploymentNamePrefix + "explicitprioritymatchname" + rand.String(RandomStrLength) deploymentNamespace = testNamespace deploymentName = deploymentNamePrefix + rand.String(RandomStrLength) @@ -444,6 +451,10 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { ginkgo.BeforeEach(func() { framework.CreateClusterPropagationPolicy(karmadaClient, policyExplicitPriorityLabelSelector) framework.CreateClusterPropagationPolicy(karmadaClient, policyExplicitPriorityMatchName) + + // Wait policy present in cache + time.Sleep(time.Second) + framework.CreateDeployment(kubeClient, deployment) ginkgo.DeferCleanup(func() { framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name) @@ -459,6 +470,7 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { ginkgo.By("check whether the deployment uses the ClusterPropagationPolicy with name matched", func() { framework.WaitDeploymentPresentOnClustersFitWith(framework.ClusterNames(), deployment.Namespace, deployment.Name, func(deployment *appsv1.Deployment) bool { + klog.Infof("Matched ClusterPropagationPolicy:%s", deployment.GetLabels()[policyv1alpha1.ClusterPropagationPolicyLabel]) return deployment.GetLabels()[policyv1alpha1.ClusterPropagationPolicyLabel] == explicitPriorityMatchName }) }) diff --git a/test/e2e/propagationpolicy_test.go b/test/e2e/propagationpolicy_test.go index 92fd99903..c7630fc46 100644 --- a/test/e2e/propagationpolicy_test.go +++ b/test/e2e/propagationpolicy_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "time" "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" @@ -704,9 +705,9 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { ginkgo.BeforeEach(func() { policyNamespace = testNamespace - higherPriorityLabelSelector = deploymentNamePrefix + rand.String(RandomStrLength) - lowerPriorityMatchName = deploymentNamePrefix + rand.String(RandomStrLength) - implicitPriorityMatchName = deploymentNamePrefix + rand.String(RandomStrLength) + higherPriorityLabelSelector = deploymentNamePrefix + "higherprioritylabelselector" + rand.String(RandomStrLength) + lowerPriorityMatchName = deploymentNamePrefix + "lowerprioritymatchame" + rand.String(RandomStrLength) + implicitPriorityMatchName = deploymentNamePrefix + "implicitprioritymatchname" + rand.String(RandomStrLength) deploymentNamespace = testNamespace deploymentName = deploymentNamePrefix + rand.String(RandomStrLength) @@ -751,6 +752,10 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { framework.CreatePropagationPolicy(karmadaClient, policyHigherPriorityLabelSelector) framework.CreatePropagationPolicy(karmadaClient, policyLowerPriorityMatchMatchName) framework.CreatePropagationPolicy(karmadaClient, policyImplicitPriorityMatchMatchName) + + // Wait policy present in cache + time.Sleep(time.Second) + framework.CreateDeployment(kubeClient, deployment) ginkgo.DeferCleanup(func() { framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name) @@ -766,6 +771,8 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { ginkgo.By("check whether the deployment uses the highest explicit priority PropagationPolicy", func() { framework.WaitDeploymentPresentOnClustersFitWith(framework.ClusterNames(), deployment.Namespace, deployment.Name, func(deployment *appsv1.Deployment) bool { + klog.Infof("Match PropagationPolicy:%s/%s", deployment.GetLabels()[policyv1alpha1.PropagationPolicyNamespaceLabel], + deployment.GetLabels()[policyv1alpha1.PropagationPolicyNameLabel]) return deployment.GetLabels()[policyv1alpha1.PropagationPolicyNameLabel] == higherPriorityLabelSelector }) }) @@ -782,8 +789,8 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { ginkgo.BeforeEach(func() { policyNamespace = testNamespace - explicitPriorityLabelSelector = deploymentNamePrefix + rand.String(RandomStrLength) - explicitPriorityMatchName = deploymentNamePrefix + rand.String(RandomStrLength) + explicitPriorityLabelSelector = deploymentNamePrefix + "explicitprioritylabelselector" + rand.String(RandomStrLength) + explicitPriorityMatchName = deploymentNamePrefix + "explicitprioritymatchname" + rand.String(RandomStrLength) deploymentNamespace = testNamespace deploymentName = deploymentNamePrefix + rand.String(RandomStrLength) @@ -816,6 +823,10 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { ginkgo.BeforeEach(func() { framework.CreatePropagationPolicy(karmadaClient, policyExplicitPriorityLabelSelector) framework.CreatePropagationPolicy(karmadaClient, policyExplicitPriorityMatchName) + + // Wait policy present in cache + time.Sleep(time.Second) + framework.CreateDeployment(kubeClient, deployment) ginkgo.DeferCleanup(func() { framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name) @@ -831,6 +842,8 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() { ginkgo.By("check whether the deployment uses the PropagationPolicy with name matched", func() { framework.WaitDeploymentPresentOnClustersFitWith(framework.ClusterNames(), deployment.Namespace, deployment.Name, func(deployment *appsv1.Deployment) bool { + klog.Infof("Match PropagationPolicy:%s/%s", deployment.GetLabels()[policyv1alpha1.PropagationPolicyNamespaceLabel], + deployment.GetLabels()[policyv1alpha1.PropagationPolicyNameLabel]) return deployment.GetLabels()[policyv1alpha1.PropagationPolicyNameLabel] == explicitPriorityMatchName }) })