add SchedulePriority e2e tests
Signed-off-by: wei-chenglai <qazwsx0939059006@gmail.com>
This commit is contained in:
parent
1417bef111
commit
d1d6a993fe
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
Copyright 2025 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 framework
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"github.com/onsi/gomega"
|
||||
schedulingv1 "k8s.io/api/scheduling/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
// CreatePriorityClass creates a PriorityClass with kubernetes client.
|
||||
func CreatePriorityClass(client kubernetes.Interface, pc *schedulingv1.PriorityClass) {
|
||||
ginkgo.By(fmt.Sprintf("Creating PriorityClass(%s)", pc.Name), func() {
|
||||
_, err := client.SchedulingV1().PriorityClasses().Create(context.TODO(), pc, metav1.CreateOptions{})
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
}
|
||||
|
||||
// RemovePriorityClass deletes a PriorityClass.
|
||||
func RemovePriorityClass(client kubernetes.Interface, name string) {
|
||||
ginkgo.By(fmt.Sprintf("Removing PriorityClass(%s)", name), func() {
|
||||
err := client.SchedulingV1().PriorityClasses().Delete(context.TODO(), name, metav1.DeleteOptions{})
|
||||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
|
||||
})
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
Copyright 2025 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 base
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"github.com/onsi/gomega"
|
||||
schedulingv1 "k8s.io/api/scheduling/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/rand"
|
||||
|
||||
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
|
||||
"github.com/karmada-io/karmada/pkg/util/names"
|
||||
"github.com/karmada-io/karmada/test/e2e/framework"
|
||||
testhelper "github.com/karmada-io/karmada/test/helper"
|
||||
)
|
||||
|
||||
var _ = ginkgo.Describe("[SchedulePriority] priority based resource scheduling", func() {
|
||||
ginkgo.Context("With KubePriorityClass source", func() {
|
||||
ginkgo.When("priorityclass exists", func() {
|
||||
var priorityClass *schedulingv1.PriorityClass
|
||||
var policy *policyv1alpha1.PropagationPolicy
|
||||
var deploymentName string
|
||||
|
||||
ginkgo.JustBeforeEach(func() {
|
||||
framework.CreatePriorityClass(kubeClient, priorityClass)
|
||||
framework.CreatePropagationPolicy(karmadaClient, policy)
|
||||
deployment := testhelper.NewDeployment(testNamespace, deploymentName)
|
||||
framework.CreateDeployment(kubeClient, deployment)
|
||||
ginkgo.DeferCleanup(func() {
|
||||
framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name)
|
||||
framework.RemovePropagationPolicy(karmadaClient, policy.Namespace, policy.Name)
|
||||
framework.RemovePriorityClass(kubeClient, priorityClass.Name)
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
priorityClass = testhelper.NewPriorityClass(fmt.Sprintf("test-priority-%s", rand.String(RandomStrLength)), 1000)
|
||||
deploymentName = deploymentNamePrefix + rand.String(RandomStrLength)
|
||||
policy = testhelper.NewPropagationPolicy(testNamespace, deploymentName, []policyv1alpha1.ResourceSelector{
|
||||
{
|
||||
APIVersion: "apps/v1",
|
||||
Kind: "Deployment",
|
||||
Name: deploymentName,
|
||||
},
|
||||
}, policyv1alpha1.Placement{
|
||||
ClusterAffinity: &policyv1alpha1.ClusterAffinity{
|
||||
ClusterNames: framework.ClusterNames(),
|
||||
},
|
||||
})
|
||||
policy.Spec.SchedulePriority = &policyv1alpha1.SchedulePriority{
|
||||
PriorityClassName: priorityClass.Name,
|
||||
PriorityClassSource: policyv1alpha1.KubePriorityClass,
|
||||
}
|
||||
})
|
||||
|
||||
ginkgo.It("ResourceBinding should inherit priority from propagationPolicy", func() {
|
||||
bindingName := names.GenerateBindingName("Deployment", deploymentName)
|
||||
framework.WaitResourceBindingFitWith(karmadaClient, testNamespace, bindingName, func(binding *workv1alpha2.ResourceBinding) bool {
|
||||
return binding.Spec.SchedulePriority != nil && binding.Spec.SchedulePriority.Priority == priorityClass.Value
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.When("priorityclass does not exist", func() {
|
||||
var policy *policyv1alpha1.PropagationPolicy
|
||||
var deploymentName string
|
||||
|
||||
ginkgo.JustBeforeEach(func() {
|
||||
framework.CreatePropagationPolicy(karmadaClient, policy)
|
||||
deployment := testhelper.NewDeployment(testNamespace, deploymentName)
|
||||
framework.CreateDeployment(kubeClient, deployment)
|
||||
ginkgo.DeferCleanup(func() {
|
||||
framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name)
|
||||
framework.RemovePropagationPolicy(karmadaClient, policy.Namespace, policy.Name)
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
deploymentName = deploymentNamePrefix + rand.String(RandomStrLength)
|
||||
policy = testhelper.NewPropagationPolicy(testNamespace, deploymentName, []policyv1alpha1.ResourceSelector{
|
||||
{
|
||||
APIVersion: "apps/v1",
|
||||
Kind: "Deployment",
|
||||
Name: deploymentName,
|
||||
},
|
||||
}, policyv1alpha1.Placement{
|
||||
ClusterAffinity: &policyv1alpha1.ClusterAffinity{
|
||||
ClusterNames: framework.ClusterNames(),
|
||||
},
|
||||
})
|
||||
policy.Spec.SchedulePriority = &policyv1alpha1.SchedulePriority{
|
||||
PriorityClassName: "non-existent-priority-class",
|
||||
PriorityClassSource: policyv1alpha1.KubePriorityClass,
|
||||
}
|
||||
})
|
||||
|
||||
ginkgo.It("ResourceBinding should not be created", func() {
|
||||
bindingName := names.GenerateBindingName("Deployment", deploymentName)
|
||||
gomega.Consistently(func(g gomega.Gomega) {
|
||||
_, err := karmadaClient.WorkV1alpha2().ResourceBindings(testNamespace).Get(context.TODO(), bindingName, metav1.GetOptions{})
|
||||
g.Expect(err).Should(gomega.HaveOccurred())
|
||||
g.Expect(apierrors.IsNotFound(err)).Should(gomega.BeTrue())
|
||||
}, pollTimeout, pollInterval).Should(gomega.Succeed())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// Future priority source tests can be added here as new contexts
|
||||
// ginkgo.Context("With PodPriorityClass source", func() {...})
|
||||
// ginkgo.Context("With FederatedPriorityClass source", func() {...})
|
||||
})
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
Copyright 2025 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 helper
|
||||
|
||||
import (
|
||||
schedulingv1 "k8s.io/api/scheduling/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// NewPriorityClass creates a new PriorityClass object.
|
||||
func NewPriorityClass(name string, value int32) *schedulingv1.PriorityClass {
|
||||
return &schedulingv1.PriorityClass{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
Value: value,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue