Skip to content

Commit

Permalink
RB suspension: e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Monokaix <changxuzheng@huawei.com>
  • Loading branch information
Monokaix committed Dec 19, 2024
1 parent ddcf8fd commit 55e7bb2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/e2e/clusterpropagationpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/meta"
Expand All @@ -37,6 +38,8 @@ import (
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
"github.com/karmada-io/karmada/pkg/controllers/binding"
"github.com/karmada-io/karmada/pkg/events"
"github.com/karmada-io/karmada/pkg/util/helper"
"github.com/karmada-io/karmada/pkg/util/names"
"github.com/karmada-io/karmada/test/e2e/framework"
Expand Down Expand Up @@ -1150,4 +1153,37 @@ var _ = ginkgo.Describe("[Suspension] ClusterPropagationPolicy testing", func()
}, pollTimeout, pollInterval).Should(gomega.Equal(true))
})
})

ginkgo.It("suspend the CPP scheduling", func() {
ginkgo.By("update the cpp suspension scheduling to true", func() {
policy.Spec.Suspension = &policyv1alpha1.Suspension{
Scheduling: ptr.To(true),
}
framework.UpdateClusterPropagationPolicyWithSpec(karmadaClient, policy.Name, policy.Spec)
})

ginkgo.By("check CRB suspension spec", func() {
framework.WaitClusterResourceBindingFitWith(karmadaClient, resourceBindingName, func(binding *workv1alpha2.ClusterResourceBinding) bool {
return binding.Spec.Suspension != nil && ptr.Deref(binding.Spec.Suspension.Scheduling, false)
})
})

ginkgo.By("check Work Scheduling status condition", func() {
gomega.Eventually(func() bool {
crb, err := karmadaClient.WorkV1alpha2().ClusterResourceBindings().Get(context.TODO(), resourceBindingName, metav1.GetOptions{})
if err != nil {
return false
}
return crb != nil && meta.IsStatusConditionPresentAndEqual(crb.Status.Conditions, workv1alpha2.Suspended, metav1.ConditionTrue)
}, pollTimeout, pollInterval).Should(gomega.Equal(true))
})

ginkgo.By("check scheduling event", func() {
framework.WaitEventFitWith(kubeClient, "", resourceBindingName,
func(event corev1.Event) bool {
return event.Reason == events.EventReasonBindingScheduling &&
event.Message == binding.SuspendedSchedulingConditionMessage
})
})
})
})
37 changes: 37 additions & 0 deletions test/e2e/propagationpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
"github.com/karmada-io/karmada/pkg/controllers/binding"
"github.com/karmada-io/karmada/pkg/controllers/execution"
"github.com/karmada-io/karmada/pkg/events"
"github.com/karmada-io/karmada/pkg/util/helper"
Expand Down Expand Up @@ -1246,6 +1247,42 @@ var _ = ginkgo.Describe("[Suspension] PropagationPolicy testing", func() {
})
})

ginkgo.It("suspend the PP scheduling", func() {
ginkgo.By("update the pp suspension scheduling to true", func() {
policy.Spec.Suspension = &policyv1alpha1.Suspension{
Scheduling: ptr.To(true),
}
framework.UpdatePropagationPolicyWithSpec(karmadaClient, policy.Namespace, policy.Name, policy.Spec)
})

ginkgo.By("check RB suspension spec", 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.Scheduling, false)
})
})

ginkgo.By("check RB Scheduling status condition", func() {
rbName := names.GenerateBindingName(deployment.Kind, deployment.Name)
gomega.Eventually(func() bool {
rb, err := karmadaClient.WorkV1alpha2().ResourceBindings(testNamespace).Get(context.TODO(), rbName, metav1.GetOptions{})
if err != nil {
return false
}
return rb != nil && meta.IsStatusConditionPresentAndEqual(rb.Status.Conditions, workv1alpha2.Suspended, metav1.ConditionTrue)
}, pollTimeout, pollInterval).Should(gomega.Equal(true))
})

ginkgo.By("check scheduling event", func() {
rbName := names.GenerateBindingName(deployment.Kind, deployment.Name)
framework.WaitEventFitWith(kubeClient, testNamespace, rbName,
func(event corev1.Event) bool {
return event.Reason == events.EventReasonBindingScheduling &&
event.Message == binding.SuspendedSchedulingConditionMessage
})
})
})

ginkgo.It("suspension resume", func() {
ginkgo.By("update deployment replicas", func() {
framework.UpdateDeploymentReplicas(kubeClient, deployment, updateDeploymentReplicas)
Expand Down

0 comments on commit 55e7bb2

Please sign in to comment.