Skip to content

Commit

Permalink
e2e for work suspension resume
Browse files Browse the repository at this point in the history
Signed-off-by: Amir Alavi <[email protected]>
  • Loading branch information
a7i committed Aug 13, 2024
1 parent 235ec91 commit ad2e9a7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 24 deletions.
19 changes: 9 additions & 10 deletions test/e2e/clusterpropagationpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
104 changes: 90 additions & 14 deletions test/e2e/propagationpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 1157 in test/e2e/propagationpolicy_test.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'deployment' seems to be unused, consider removing or renaming it as _ (revive)
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() {
Expand Down Expand Up @@ -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
})
})
})
})
Expand Down

0 comments on commit ad2e9a7

Please sign in to comment.