diff --git a/test/e2e/failover_test.go b/test/e2e/failover_test.go index 0ca201d71..d569511b0 100644 --- a/test/e2e/failover_test.go +++ b/test/e2e/failover_test.go @@ -6,7 +6,6 @@ import ( "github.com/onsi/ginkgo" "github.com/onsi/gomega" - appsv1 "k8s.io/api/apps/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -17,7 +16,6 @@ import ( clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1" policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" - workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" "github.com/karmada-io/karmada/pkg/util" "github.com/karmada-io/karmada/test/e2e/framework" testhelper "github.com/karmada-io/karmada/test/helper" @@ -85,28 +83,19 @@ var _ = ginkgo.Describe("failover testing", func() { }) ginkgo.By("check whether deployment of failed cluster is rescheduled to other available cluster", func() { - totalNum := 0 - - targetClusterNames = framework.ExtractTargetClustersFrom(controlPlaneClient, deployment) - for _, targetClusterName := range targetClusterNames { - // the target cluster should be overwritten to another available cluster - gomega.Expect(isDisabled(targetClusterName, disabledClusters)).Should(gomega.BeFalse()) - - framework.WaitDeploymentPresentOnClusterFitWith(targetClusterName, deployment.Namespace, deployment.Name, - func(deployment *appsv1.Deployment) bool { - return true - }) - totalNum++ - } - gomega.Expect(totalNum == minGroups).Should(gomega.BeTrue()) - }) - - ginkgo.By("check if the scheduled condition is true", func() { err := wait.PollImmediate(pollInterval, pollTimeout, func() (bool, error) { - rb, err := getResourceBinding(deployment) - gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - return meta.IsStatusConditionTrue(rb.Status.Conditions, workv1alpha2.Scheduled), nil + targetClusterNames = framework.ExtractTargetClustersFrom(controlPlaneClient, deployment) + for _, targetClusterName := range targetClusterNames { + // the target cluster should be overwritten to another available cluster + if !testhelper.IsExclude(targetClusterName, disabledClusters) { + return false, nil + } + } + + gomega.Expect(len(targetClusterNames) == minGroups).Should(gomega.BeTrue()) + return true, nil }) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) }) @@ -183,16 +172,6 @@ func recoverCluster(c client.Client, clusterName string, originalAPIEndpoint str return err } -// indicate if the cluster is disabled -func isDisabled(clusterName string, disabledClusters []string) bool { - for _, cluster := range disabledClusters { - if cluster == clusterName { - return true - } - } - return false -} - // get the API endpoint of a specific cluster func getClusterAPIEndpoint(clusterName string) (apiEndpoint string) { for _, cluster := range framework.Clusters() { diff --git a/test/e2e/rescheduling_test.go b/test/e2e/rescheduling_test.go index 737429976..dbd07fb20 100644 --- a/test/e2e/rescheduling_test.go +++ b/test/e2e/rescheduling_test.go @@ -113,7 +113,7 @@ var _ = ginkgo.Describe("reschedule testing", func() { ginkgo.By("check whether the deployment is rescheduled to other available clusters", func() { gomega.Eventually(func(g gomega.Gomega) bool { targetClusterNames = framework.ExtractTargetClustersFrom(controlPlaneClient, deployment) - return isExclude(newClusterName, targetClusterNames) + return testhelper.IsExclude(newClusterName, targetClusterNames) }, pollTimeout, pollInterval).Should(gomega.BeTrue()) }) @@ -131,13 +131,3 @@ var _ = ginkgo.Describe("reschedule testing", func() { }) }) }) - -// indicate if the target clusters exclude the deleteCluster -func isExclude(deleteCluster string, targetClusters []string) bool { - for _, cluster := range targetClusters { - if cluster == deleteCluster { - return false - } - } - return true -} diff --git a/test/helper/scheduler.go b/test/helper/scheduler.go index 8ce79ffa3..154b3441e 100644 --- a/test/helper/scheduler.go +++ b/test/helper/scheduler.go @@ -23,3 +23,13 @@ func IsScheduleResultEqual(tc1, tc2 []workv1alpha2.TargetCluster) bool { } return true } + +// IsExclude indicate if the target clusters exclude the srcCluster +func IsExclude(srcCluster string, targetClusters []string) bool { + for _, cluster := range targetClusters { + if cluster == srcCluster { + return false + } + } + return true +}