Files
kubernetes/test/e2e/scheduling/workload.go
Antoni Zawodny 3f094dc228 Create Workload API v1alpha2 (#136976)
* Drop WorkloadRef field and introduce SchedulingGroup field in Pod API

* Introduce v1alpha2 Workload and PodGroup APIs, drop v1alpha1 Workload API

Co-authored-by: yongruilin <yongrlin@outlook.com>

* Run hack/update-codegen.sh

* Adjust kube-scheduler code and integration tests to v1alpha2 API

* Drop v1alpha1 scheduling API group and run make update

---------

Co-authored-by: yongruilin <yongrlin@outlook.com>
2026-03-10 07:59:10 +05:30

119 lines
4.1 KiB
Go

/*
Copyright 2025 The Kubernetes 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 scheduling
import (
"context"
schedulingv1alpha2 "k8s.io/api/scheduling/v1alpha2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/apis/scheduling"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/test/e2e/framework"
e2econformance "k8s.io/kubernetes/test/e2e/framework/conformance"
admissionapi "k8s.io/pod-security-admission/api"
)
var _ = SIGDescribe("Workload", framework.WithFeatureGate(features.GenericWorkload), func() {
f := framework.NewDefaultFramework("workload-test")
f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
f.Context("CRUD Tests", func() {
/*
Testname: CRUD operations for Workloads
Description: kube-apiserver must support create/get/list/update/patch/delete
operations for scheduling.k8s.io/v1alpha2 Workload.
*/
framework.It("Workload API availability", func(ctx context.Context) {
e2econformance.TestResource(ctx, f,
&e2econformance.ResourceTestcase[*schedulingv1alpha2.Workload]{
GVR: schedulingv1alpha2.SchemeGroupVersion.WithResource("workloads"),
Namespaced: new(true),
InitialSpec: &schedulingv1alpha2.Workload{
Spec: schedulingv1alpha2.WorkloadSpec{
ControllerRef: &schedulingv1alpha2.TypedLocalObjectReference{
APIGroup: "batch",
Kind: "Job",
Name: "foo",
},
PodGroupTemplates: []schedulingv1alpha2.PodGroupTemplate{
{
Name: "pg1",
SchedulingPolicy: schedulingv1alpha2.PodGroupSchedulingPolicy{
Gang: &schedulingv1alpha2.GangSchedulingPolicy{
MinCount: 5,
},
},
},
},
},
},
UpdateSpec: func(obj *schedulingv1alpha2.Workload) *schedulingv1alpha2.Workload {
obj.Labels["foo"] = "bar"
return obj
},
StrategicMergePatchSpec: `{"metadata": {"labels": {"baz": "qux"}}}`,
},
)
})
/*
Testname: CRUD operations for PodGroups
Description: kube-apiserver must support create/get/list/update/patch/delete
operations for scheduling.k8s.io/v1alpha2 PodGroup.
*/
framework.It("PodGroup API availability", func(ctx context.Context) {
e2econformance.TestResource(ctx, f,
&e2econformance.ResourceTestcase[*schedulingv1alpha2.PodGroup]{
GVR: schedulingv1alpha2.SchemeGroupVersion.WithResource("podgroups"),
Namespaced: new(true),
InitialSpec: &schedulingv1alpha2.PodGroup{
Spec: schedulingv1alpha2.PodGroupSpec{
PodGroupTemplateRef: &schedulingv1alpha2.PodGroupTemplateReference{
Workload: &schedulingv1alpha2.WorkloadPodGroupTemplateReference{
PodGroupTemplateName: "pg1",
WorkloadName: "w1",
},
},
SchedulingPolicy: schedulingv1alpha2.PodGroupSchedulingPolicy{
Gang: &schedulingv1alpha2.GangSchedulingPolicy{
MinCount: 5,
},
},
},
},
UpdateSpec: func(obj *schedulingv1alpha2.PodGroup) *schedulingv1alpha2.PodGroup {
obj.Labels["foo"] = "bar"
return obj
},
UpdateStatus: func(obj *schedulingv1alpha2.PodGroup) *schedulingv1alpha2.PodGroup {
obj.Status.Conditions = append(obj.Status.Conditions, metav1.Condition{
Type: scheduling.PodGroupScheduled,
Status: metav1.ConditionFalse,
Reason: scheduling.PodGroupReasonUnschedulable,
Message: "Test status condition message",
LastTransitionTime: metav1.Now(),
})
return obj
},
StrategicMergePatchSpec: `{"metadata": {"labels": {"baz": "qux"}}}`,
},
)
})
})
})