diff --git a/test/e2e/clusterpropagationpolicy_test.go b/test/e2e/clusterpropagationpolicy_test.go index ad78ae1d84bf..c019c9480d4d 100644 --- a/test/e2e/clusterpropagationpolicy_test.go +++ b/test/e2e/clusterpropagationpolicy_test.go @@ -1052,23 +1052,22 @@ var _ = ginkgo.Describe("[Suspend] clusterPropagation testing", func() { }) ginkgo.BeforeEach(func() { + framework.CreateClusterPropagationPolicy(karmadaClient, policy) framework.CreateClusterRole(kubeClient, clusterRole) ginkgo.DeferCleanup(func() { + framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name) framework.RemoveClusterRole(kubeClient, clusterRole.Name) }) }) - ginkgo.Context("suspend the ClusterPropagationPolicy dispatching", func() { - ginkgo.BeforeEach(func() { - policy.Spec.Suspension = &policyv1alpha1.Suspension{ - Dispatching: ptr.To(true), - } - framework.CreateClusterPropagationPolicy(karmadaClient, policy) - ginkgo.DeferCleanup(func() { - framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name) - }) - }) + ginkgo.BeforeEach(func() { + policy.Spec.Suspension = &policyv1alpha1.Suspension{ + Dispatching: ptr.To(true), + } + framework.UpdateClusterPropagationPolicyWithSpec(karmadaClient, policy.Name, policy.Spec) + }) + ginkgo.Context("suspend the ClusterPropagationPolicy dispatching", func() { ginkgo.It("suspends ClusterResourceBinding", func() { framework.WaitClusterResourceBindingFitWith(karmadaClient, resourceBindingName, func(binding *workv1alpha2.ClusterResourceBinding) bool { return binding.Spec.Suspension != nil && ptr.Deref(binding.Spec.Suspension.Dispatching, false) diff --git a/test/e2e/propagationpolicy_test.go b/test/e2e/propagationpolicy_test.go index 6bef5de30fd7..2b13be2889f1 100644 --- a/test/e2e/propagationpolicy_test.go +++ b/test/e2e/propagationpolicy_test.go @@ -1148,25 +1148,34 @@ var _ = ginkgo.Describe("[Suspend] PropagationPolicy testing", func() { }) ginkgo.BeforeEach(func() { - framework.CreateDeployment(kubeClient, deployment) + framework.CreatePropagationPolicy(karmadaClient, policy) ginkgo.DeferCleanup(func() { - framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name) + framework.RemovePropagationPolicy(karmadaClient, policy.Namespace, policy.Name) }) + framework.CreateDeployment(kubeClient, deployment) + framework.WaitDeploymentPresentOnClusterFitWith(targetMember, deployment.Namespace, deployment.Name, + func(deployment *appsv1.Deployment) bool { + return true + }) }) - ginkgo.Context("suspend the PropagationPolicy dispatching", func() { - ginkgo.BeforeEach(func() { - policy.Spec.Suspension = &policyv1alpha1.Suspension{ - Dispatching: ptr.To(true), - } + ginkgo.BeforeEach(func() { + policy.Spec.Suspension = &policyv1alpha1.Suspension{ + Dispatching: ptr.To(true), + } + framework.UpdatePropagationPolicyWithSpec(karmadaClient, policy.Namespace, policy.Name, policy.Spec) + }) - framework.CreatePropagationPolicy(karmadaClient, policy) + ginkgo.Context("suspend the PropagationPolicy dispatching", func() { + ginkgo.AfterEach(func() { + framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name) }) ginkgo.It("suspends ResourceBinding", func() { - framework.WaitResourceBindingFitWith(karmadaClient, deployment.Namespace, names.GenerateBindingName(deployment.Kind, deployment.Name), func(binding *workv1alpha2.ResourceBinding) bool { - return binding.Spec.Suspension != nil && ptr.Deref(binding.Spec.Suspension.Dispatching, false) - }) + framework.WaitResourceBindingFitWith(karmadaClient, deployment.Namespace, names.GenerateBindingName(deployment.Kind, deployment.Name), + func(binding *workv1alpha2.ResourceBinding) bool { + return binding.Spec.Suspension != nil && ptr.Deref(binding.Spec.Suspension.Dispatching, false) + }) }) ginkgo.It("suspends Work", func() { @@ -1196,9 +1205,76 @@ var _ = ginkgo.Describe("[Suspend] PropagationPolicy testing", func() { ginkgo.It("adds dispatching event with suspend message", func() { workName := names.GenerateWorkName(deployment.Kind, deployment.Name, deployment.Namespace) esName := names.GenerateExecutionSpaceName(targetMember) - framework.WaitEventFitWith(kubeClient, esName, workName, func(event corev1.Event) bool { - return event.Reason == events.EventReasonWorkDispatching && - event.Message == execution.WorkSuspendDispatchingConditionMessage + framework.WaitEventFitWith(kubeClient, esName, workName, + func(event corev1.Event) bool { + return event.Reason == events.EventReasonWorkDispatching && + event.Message == execution.WorkSuspendDispatchingConditionMessage + }) + }) + }) + + ginkgo.Context("delete resource in the control plane", func() { + var hasPropagationLabelsAndAnnotations = func(dep *appsv1.Deployment) bool { + if dep.Labels == nil || dep.Labels[policyv1alpha1.PropagationPolicyPermanentIDLabel] == "" { + return false + } + if dep.Annotations == nil || dep.Annotations[policyv1alpha1.PropagationPolicyNamespaceAnnotation] == "" || dep.Annotations[policyv1alpha1.PropagationPolicyNameAnnotation] == "" { + return true + } + return false + } + + ginkgo.JustBeforeEach(func() { + framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name) + }) + + ginkgo.It("suspends deleting deployment annotations and labels in member cluster", func() { + framework.WaitDeploymentFitWith(kubeClient, deployment.Namespace, deployment.Name, func(dep *appsv1.Deployment) bool { + return hasPropagationLabelsAndAnnotations(dep) + }) + }) + + ginkgo.When("propagation is resumed", func() { + ginkgo.JustBeforeEach(func() { + policy.Spec.Suspension = &policyv1alpha1.Suspension{} + framework.UpdatePropagationPolicyWithSpec(karmadaClient, policy.Namespace, policy.Name, policy.Spec) + }) + + ginkgo.It("deletes deployment annotations and labels in member cluster", func() { + framework.WaitDeploymentFitWith(kubeClient, deployment.Namespace, deployment.Name, func(dep *appsv1.Deployment) bool { + return !hasPropagationLabelsAndAnnotations(dep) + }) + }) + }) + }) + + ginkgo.Context("update resource in the control plane", func() { + ginkgo.JustBeforeEach(func() { + framework.UpdateDeploymentReplicas(kubeClient, deployment, updateDeploymentReplicas) + }) + + ginkgo.AfterEach(func() { + framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name) + }) + + ginkgo.It("suspends updating deployment replicas in member cluster", func() { + framework.WaitDeploymentPresentOnClusterFitWith(targetMember, deployment.Namespace, deployment.Name, + func(d *appsv1.Deployment) bool { + return *d.Spec.Replicas != updateDeploymentReplicas + }) + }) + + ginkgo.When("propagation is resumed", func() { + ginkgo.JustBeforeEach(func() { + policy.Spec.Suspension = &policyv1alpha1.Suspension{} + framework.UpdatePropagationPolicyWithSpec(karmadaClient, policy.Namespace, policy.Name, policy.Spec) + }) + + ginkgo.It("updates deployment replicas in member cluster", func() { + framework.WaitDeploymentPresentOnClusterFitWith(targetMember, deployment.Namespace, deployment.Name, + func(d *appsv1.Deployment) bool { + return *d.Spec.Replicas == updateDeploymentReplicas + }) }) }) })