From aca03f146cbc2af7f1cbba55754e255dd761503c Mon Sep 17 00:00:00 2001 From: changzhen Date: Thu, 9 Sep 2021 17:00:09 +0800 Subject: [PATCH] fix bug: update binding object with replicas and replicaRequirements Signed-off-by: changzhen --- pkg/util/detector/detector.go | 6 +++++ test/e2e/scheduling_test.go | 45 ++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/pkg/util/detector/detector.go b/pkg/util/detector/detector.go index 53d5dd151..d08850890 100644 --- a/pkg/util/detector/detector.go +++ b/pkg/util/detector/detector.go @@ -440,6 +440,8 @@ func (d *ResourceDetector) ApplyPolicy(object *unstructured.Unstructured, object bindingCopy.Labels = binding.Labels bindingCopy.OwnerReferences = binding.OwnerReferences bindingCopy.Spec.Resource = binding.Spec.Resource + bindingCopy.Spec.ReplicaRequirements = binding.Spec.ReplicaRequirements + bindingCopy.Spec.Replicas = binding.Spec.Replicas return nil }) if err != nil { @@ -486,6 +488,8 @@ func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured, bindingCopy.Labels = binding.Labels bindingCopy.OwnerReferences = binding.OwnerReferences bindingCopy.Spec.Resource = binding.Spec.Resource + bindingCopy.Spec.ReplicaRequirements = binding.Spec.ReplicaRequirements + bindingCopy.Spec.Replicas = binding.Spec.Replicas return nil }) @@ -513,6 +517,8 @@ func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured, bindingCopy.Labels = binding.Labels bindingCopy.OwnerReferences = binding.OwnerReferences bindingCopy.Spec.Resource = binding.Spec.Resource + bindingCopy.Spec.ReplicaRequirements = binding.Spec.ReplicaRequirements + bindingCopy.Spec.Replicas = binding.Spec.Replicas return nil }) diff --git a/test/e2e/scheduling_test.go b/test/e2e/scheduling_test.go index e160b638c..a68d8d3de 100644 --- a/test/e2e/scheduling_test.go +++ b/test/e2e/scheduling_test.go @@ -451,11 +451,26 @@ var _ = ginkgo.Describe("[ReplicaScheduling] ReplicaSchedulingStrategy testing", }) ginkgo.It("replicas duplicated testing when rescheduling", func() { - ginkgo.By(fmt.Sprintf("Update deployment(%s/%s)'s replicas to 2", policyNamespace, policyName), func() { + ginkgo.By("make sure deployment has been propagated to member clusters", func() { + for _, cluster := range clusters { + clusterClient := getClusterClient(cluster.Name) + gomega.Expect(clusterClient).ShouldNot(gomega.BeNil()) + + gomega.Eventually(func() bool { + _, err := clusterClient.AppsV1().Deployments(deploymentNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{}) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + + return true + }, pollTimeout, pollInterval).Should(gomega.Equal(true)) + } + }) + + ginkgo.By(fmt.Sprintf("Update deployment(%s/%s)'s replicas", deploymentNamespace, deploymentName), func() { updateReplicas := int32(2) deployment.Spec.Replicas = &updateReplicas _, err := kubeClient.AppsV1().Deployments(deploymentNamespace).Update(context.TODO(), deployment, metav1.UpdateOptions{}) gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + klog.Infof("Update deployment(%s/%s)'s replicas to %d", deploymentNamespace, deploymentName, *deployment.Spec.Replicas) }) ginkgo.By("check if deployment's replicas have been updated on member clusters", func() { @@ -598,6 +613,20 @@ var _ = ginkgo.Describe("[ReplicaScheduling] ReplicaSchedulingStrategy testing", }) ginkgo.It("replicas divided and weighted testing when rescheduling", func() { + ginkgo.By("make sure deployment has been propagated to member clusters", func() { + for _, cluster := range clusters { + clusterClient := getClusterClient(cluster.Name) + gomega.Expect(clusterClient).ShouldNot(gomega.BeNil()) + + gomega.Eventually(func() bool { + _, err := clusterClient.AppsV1().Deployments(deploymentNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{}) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + + return true + }, pollTimeout, pollInterval).Should(gomega.Equal(true)) + } + }) + expectedReplicas := int32(3) ginkgo.By(fmt.Sprintf("Update deployment(%s/%s)'s replicas to 3*len(clusters)", policyNamespace, policyName), func() { updateReplicas := expectedReplicas * int32(len(clusters)) @@ -780,6 +809,20 @@ var _ = ginkgo.Describe("[ReplicaScheduling] ReplicaSchedulingStrategy testing", }) ginkgo.It("replicas divided and weighted testing when rescheduling", func() { + ginkgo.By("make sure deployment has been propagated to member clusters", func() { + for _, cluster := range clusters { + clusterClient := getClusterClient(cluster.Name) + gomega.Expect(clusterClient).ShouldNot(gomega.BeNil()) + + gomega.Eventually(func() bool { + _, err := clusterClient.AppsV1().Deployments(deploymentNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{}) + gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + + return true + }, pollTimeout, pollInterval).Should(gomega.Equal(true)) + } + }) + ginkgo.By(fmt.Sprintf("Update deployment(%s/%s)'s replicas to 2*sumWeight", policyNamespace, policyName), func() { sumWeight := 0 for index := range clusterNames {