Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add e2e test for lazy propagation policy #4804

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 104 additions & 2 deletions test/e2e/lazy_activation_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/utils/pointer"

policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/test/e2e/framework"
testhelper "github.com/karmada-io/karmada/test/helper"
)
Expand All @@ -34,17 +36,18 @@ const waitIntervalForLazyPolicyTest = 3 * time.Second
// e2e test for https://github.com/karmada-io/karmada/blob/master/docs/proposals/scheduling/activation-preference/lazy-activation-preference.md#test-plan
var _ = ginkgo.Describe("Lazy activation policy testing", func() {
var namespace string
var deploymentName, configMapName, policyName string
var deploymentName, configMapName, policyName, policyHigherPriorityName string
var originalCluster, modifiedCluster string
var deployment *appsv1.Deployment
var configMap *corev1.ConfigMap
var policy *policyv1alpha1.PropagationPolicy
var policy, policyHigherPriority *policyv1alpha1.PropagationPolicy

ginkgo.BeforeEach(func() {
namespace = testNamespace
deploymentName = deploymentNamePrefix + rand.String(RandomStrLength)
configMapName = deploymentName
policyName = deploymentName
policyHigherPriorityName = deploymentName + "higherpriority"
originalCluster = framework.ClusterNames()[0]
modifiedCluster = framework.ClusterNames()[1]

Expand All @@ -60,6 +63,18 @@ var _ = ginkgo.Describe("Lazy activation policy testing", func() {
ClusterNames: []string{originalCluster},
},
})
policyHigherPriority = testhelper.NewLazyPropagationPolicy(namespace, policyHigherPriorityName, []policyv1alpha1.ResourceSelector{
{
APIVersion: deployment.APIVersion,
Kind: deployment.Kind,
Name: deploymentName,
}}, policyv1alpha1.Placement{
ClusterAffinity: &policyv1alpha1.ClusterAffinity{
ClusterNames: []string{modifiedCluster},
},
})
policyHigherPriority.Spec.Priority = pointer.Int32(2)
policyHigherPriority.Spec.Preemption = policyv1alpha1.PreemptAlways
})

ginkgo.Context("1. Policy created before resource", func() {
Expand All @@ -72,6 +87,7 @@ var _ = ginkgo.Describe("Lazy activation policy testing", func() {
framework.RemovePropagationPolicyIfExist(karmadaClient, namespace, policyName)
framework.RemoveDeployment(kubeClient, namespace, deploymentName)
framework.WaitDeploymentDisappearOnCluster(originalCluster, namespace, deploymentName)
framework.WaitDeploymentDisappearOnCluster(modifiedCluster, namespace, deploymentName)
})
})

Expand All @@ -90,6 +106,92 @@ var _ = ginkgo.Describe("Lazy activation policy testing", func() {
})
})

// Simple Case 3 (Lazy to immediate)
// refer: https://github.com/karmada-io/karmada/blob/master/docs/proposals/scheduling/activation-preference/lazy-activation-preference.md#simple-case-3-lazy-to-immediate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it's best not to use the master branch, you should use a fixed commit ID instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// refer: https://github.com/karmada-io/karmada/blob/master/docs/proposals/scheduling/activation-preference/lazy-activation-preference.md#simple-case-3-lazy-to-immediate
// refer: https://github.com/karmada-io/karmada/blob/fdad87efce1d088c8002856f5ee7586427f1a989/docs/proposals/scheduling/activation-preference/lazy-activation-preference.md?plain=1#L263

@chaunceyjiang Is it like this? The new link loses information such as the tag name, leaving only the number of rows. And the original link can find the title according to the tag name, which is relatively more flexible. So I'm more inclined not to modify. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ginkgo.It("Simple Case 3 (Lazy to immediate)", func() {
ginkgo.By("step 1: deployment propagate success when policy created before it", func() {
waitDeploymentPresentOnCluster(originalCluster, namespace, deploymentName)
})

ginkgo.By("step 2: after policy updated (cluster=member2, remove lazy activationPreference field), the propagation of deployment changed", func() {
// 1. remove lazy activationPreference field
policy.Spec.ActivationPreference = ""
// 2. update policy placement with clusterAffinities
changePlacementTargetCluster(policy, modifiedCluster)
// 3. the propagation of deployment changed
framework.WaitDeploymentDisappearOnCluster(originalCluster, namespace, deploymentName)
waitDeploymentPresentOnCluster(modifiedCluster, namespace, deploymentName)
})
})

ginkgo.Context("Immediate to lazy", func() {
ginkgo.BeforeEach(func() {
// remove lazy activationPreference field
policy.Spec.ActivationPreference = ""
})

// Simple Case 4 (Immediate to lazy)
// refer: https://github.com/karmada-io/karmada/blob/master/docs/proposals/scheduling/activation-preference/lazy-activation-preference.md#simple-case-4-immediate-to-lazy
ginkgo.It("Simple Case 4 (Immediate to lazy)", func() {
ginkgo.By("step 1: deployment propagate success", func() {
waitDeploymentPresentOnCluster(originalCluster, namespace, deploymentName)
})

ginkgo.By("step 2: after policy updated (cluster=member2, activationPreference=lazy), the propagation of deployment unchanged", func() {
// 1. activationPreference=lazy
policy.Spec.ActivationPreference = policyv1alpha1.LazyActivation
// 2. update policy placement with clusterAffinities
changePlacementTargetCluster(policy, modifiedCluster)
// 3. wait to distinguish whether the state will not change or have no time to change
time.Sleep(waitIntervalForLazyPolicyTest)
waitDeploymentPresentOnCluster(originalCluster, namespace, deploymentName)
framework.WaitDeploymentDisappearOnCluster(modifiedCluster, namespace, deploymentName)
})

ginkgo.By("step3: resource would propagate when itself updated", func() {
// 1. update annotation of the deployment
updateDeploymentManually(deployment)
// 2. the propagation of deployment changed
framework.WaitDeploymentDisappearOnCluster(originalCluster, namespace, deploymentName)
waitDeploymentPresentOnCluster(modifiedCluster, namespace, deploymentName)
})
})
})

// Combined Case 4 (Policy preemption)
// refer: https://github.com/chaosi-zju/karmada/blob/lazy-proposal/docs/proposals/scheduling/activation-preference/lazy-activation-preference.md#combined-case-4-policy-preemption
ginkgo.It("Policy preemption", func() {
ginkgo.By("step 1: deployment propagate success when policy created before it", func() {
waitDeploymentPresentOnCluster(originalCluster, namespace, deploymentName)
})

ginkgo.By("step 2: create PP2 (match nginx, cluster=member2, lazy, priority=2, preemption=true)", func() {
framework.CreatePropagationPolicy(karmadaClient, policyHigherPriority)
// 1. annotation of policy name changed
framework.WaitDeploymentFitWith(kubeClient, namespace, deploymentName, func(deployment *appsv1.Deployment) bool {
policyNameAnnotation := util.GetAnnotationValue(deployment.GetAnnotations(), policyv1alpha1.PropagationPolicyNameAnnotation)
return policyNameAnnotation == policyHigherPriorityName
})
// 2. wait to distinguish whether the state will not change or have no time to change
time.Sleep(waitIntervalForLazyPolicyTest)
// propagation unchanged
waitDeploymentPresentOnCluster(originalCluster, namespace, deploymentName)
framework.WaitDeploymentDisappearOnCluster(modifiedCluster, namespace, deploymentName)
})

ginkgo.By("step 3: update deployment", func() {
// 1. update annotation of the deployment
updateDeploymentManually(deployment)
// 2. the propagation of deployment changed
waitDeploymentPresentOnCluster(modifiedCluster, namespace, deploymentName)
framework.WaitDeploymentDisappearOnCluster(originalCluster, namespace, deploymentName)
})

ginkgo.By("step 4: clean up", func() {
framework.RemovePropagationPolicyIfExist(karmadaClient, namespace, policyHigherPriorityName)
})
})

ginkgo.Context("Propagate dependencies", func() {
ginkgo.BeforeEach(func() {
policy.Spec.PropagateDeps = true
Expand Down
Loading