Skip to content

Commit

Permalink
Merge pull request #4622 from Affan-7/lazy-activation-e2e
Browse files Browse the repository at this point in the history
Add e2e test for lazy propogation policy: Policy created before resource
  • Loading branch information
karmada-bot authored Mar 22, 2024
2 parents c55c2cc + 19e988f commit 0a88f33
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
73 changes: 73 additions & 0 deletions test/e2e/lazy_activation_policy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Copyright 2024 The Karmada Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"github.com/onsi/ginkgo/v2"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/util/rand"

policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
"github.com/karmada-io/karmada/test/e2e/framework"
testhelper "github.com/karmada-io/karmada/test/helper"
)

var _ = ginkgo.Describe("Lazy activation policy testing", func() {
ginkgo.Context("Policy created before resource testing", func() {
var policy *policyv1alpha1.PropagationPolicy
var deployment *appsv1.Deployment
var targetMember string

ginkgo.BeforeEach(func() {
targetMember = framework.ClusterNames()[0]
policyNamespace := testNamespace
policyName := deploymentNamePrefix + rand.String(RandomStrLength)

deployment = testhelper.NewDeployment(testNamespace, policyName)

policy = testhelper.NewLazyPropagationPolicy(policyNamespace, policyName, []policyv1alpha1.ResourceSelector{
{
APIVersion: deployment.APIVersion,
Kind: deployment.Kind,
Name: deployment.Name,
}}, policyv1alpha1.Placement{
ClusterAffinity: &policyv1alpha1.ClusterAffinity{
ClusterNames: []string{targetMember},
},
})
})

ginkgo.BeforeEach(func() {
framework.CreatePropagationPolicy(karmadaClient, policy)
framework.CreateDeployment(kubeClient, deployment)
ginkgo.DeferCleanup(func() {
framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name)
})

framework.WaitDeploymentPresentOnClusterFitWith(targetMember, deployment.Namespace, deployment.Name,
func(deployment *appsv1.Deployment) bool { return true })
})

ginkgo.It("policy created before resource testing", func() {
framework.WaitDeploymentPresentOnClusterFitWith(targetMember, deployment.Namespace, deployment.Name,
func(deployment *appsv1.Deployment) bool { return true })
framework.RemovePropagationPolicy(karmadaClient, policy.Namespace, policy.Name)
framework.WaitDeploymentPresentOnClusterFitWith(targetMember, deployment.Namespace, deployment.Name,
func(deployment *appsv1.Deployment) bool { return true })
})
})
})
15 changes: 15 additions & 0 deletions test/helper/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ func NewPropagationPolicy(ns, name string, rsSelectors []policyv1alpha1.Resource
}
}

// NewLazyPropagationPolicy will build a PropagationPolicy object with Lazy activation.
func NewLazyPropagationPolicy(ns, name string, rsSelectors []policyv1alpha1.ResourceSelector, placement policyv1alpha1.Placement) *policyv1alpha1.PropagationPolicy {
return &policyv1alpha1.PropagationPolicy{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: name,
},
Spec: policyv1alpha1.PropagationSpec{
ActivationPreference: policyv1alpha1.LazyActivation,
ResourceSelectors: rsSelectors,
Placement: placement,
},
}
}

// NewExplicitPriorityPropagationPolicy will build a PropagationPolicy object with explicit priority.
func NewExplicitPriorityPropagationPolicy(ns, name string, rsSelectors []policyv1alpha1.ResourceSelector,
placement policyv1alpha1.Placement, priority int32) *policyv1alpha1.PropagationPolicy {
Expand Down

0 comments on commit 0a88f33

Please sign in to comment.