Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/push-artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
push:
branches:
- "main"
- "erez/scheduler-auto-detect-dra-ci"
tags:
- '*.*.*'

Expand Down
8 changes: 1 addition & 7 deletions pkg/common/feature_gates/feature_gates.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"k8s.io/apimachinery/pkg/version"
featureutil "k8s.io/apiserver/pkg/util/feature"
discovery "k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
"k8s.io/kubernetes/pkg/features"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand All @@ -19,12 +18,7 @@ const (
minimalSupportedVersion = "v1beta1"
)

func SetDRAFeatureGate(config *rest.Config) error {
// Create a DiscoveryClient
discoveryClient, err := discovery.NewDiscoveryClientForConfig(config)
if err != nil {
return err
}
func SetDRAFeatureGate(discoveryClient discovery.DiscoveryInterface) error {
enabled := IsDynamicResourcesEnabled(discoveryClient)
return featureutil.DefaultMutableFeatureGate.SetFromMap(
map[string]bool{string(features.DynamicResourceAllocation): enabled})
Expand Down
55 changes: 55 additions & 0 deletions pkg/common/feature_gates/feature_gates_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2025 NVIDIA CORPORATION
// SPDX-License-Identifier: Apache-2.0

package featuregates

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
resourcev1 "k8s.io/api/resource/v1"
resourcev1alhpa3 "k8s.io/api/resource/v1alpha3"
resourcev1beta1 "k8s.io/api/resource/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
version "k8s.io/apimachinery/pkg/version"
featureutil "k8s.io/apiserver/pkg/util/feature"
fakediscovery "k8s.io/client-go/discovery/fake"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/kubernetes/pkg/features"
)

func TestCache(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Test cache")
}

var _ = Describe("New", func() {
Context("DRA Feature Gate", func() {
DescribeTable("should enable DRA feature gate based on Kubernetes version and resource API availability",
func(serverMajor, serverMinor string, resourceGroupVersions []string, expectDRAFeatureEnabled bool) {
fakeClient := fake.NewClientset()
fakeClient.Discovery().(*fakediscovery.FakeDiscovery).FakedServerVersion = &version.Info{
Major: serverMajor,
Minor: serverMinor,
}

for _, groupVersion := range resourceGroupVersions {
fakeClient.Resources = append(fakeClient.Resources, &metav1.APIResourceList{GroupVersion: groupVersion})
}

SetDRAFeatureGate(fakeClient.Discovery())

// Check if the DynamicResourceAllocation feature gate has the expected state
draEnabled := featureutil.DefaultFeatureGate.Enabled(features.DynamicResourceAllocation)
Expect(draEnabled).To(Equal(expectDRAFeatureEnabled))
},
Entry("compatible version (1.32) with resource API should enable DRA", "1", "32", []string{resourcev1beta1.SchemeGroupVersion.String()}, true),
Entry("compatible version (1.32) without resource API should not enable DRA", "1", "32", []string{}, false),
Entry("incompatible version (1.25) with resource API should not enable DRA", "1", "25", []string{resourcev1beta1.SchemeGroupVersion.String()}, false),
Entry("incompatible version (1.25) without resource API should not enable DRA", "1", "25", []string{}, false),
Entry("edge case version (1.31) with resource API should not enable DRA", "1", "31", []string{resourcev1alhpa3.SchemeGroupVersion.String()}, false),
Entry("higher compatible version (1.35) with resource API should enable DRA", "1", "34", []string{resourcev1.SchemeGroupVersion.String()}, true),
)
})
})
4 changes: 4 additions & 0 deletions pkg/scheduler/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
enginelisters "github.com/NVIDIA/KAI-scheduler/pkg/apis/client/listers/scheduling/v2alpha2"
schedulingv1alpha2 "github.com/NVIDIA/KAI-scheduler/pkg/apis/scheduling/v1alpha2"
enginev2alpha2 "github.com/NVIDIA/KAI-scheduler/pkg/apis/scheduling/v2alpha2"
featuregates "github.com/NVIDIA/KAI-scheduler/pkg/common/feature_gates"
draversionawareclient "github.com/NVIDIA/KAI-scheduler/pkg/common/resources/dra_version_aware_client"
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/api"
"github.com/NVIDIA/KAI-scheduler/pkg/scheduler/api/bindrequest_info"
Expand Down Expand Up @@ -156,6 +157,9 @@ func newSchedulerCache(schedulerCacheParams *SchedulerCacheParams) *SchedulerCac
sc.kubeAiSchedulerInformerFactory = kubeaischedulerinfo.NewSharedInformerFactory(sc.kubeAiSchedulerClient, 0)
sc.kueueInformerFactory = kueue.NewSharedInformerFactory(sc.kueueClient, 0)

if err := featuregates.SetDRAFeatureGate(sc.kubeClient.Discovery()); err != nil {
log.InfraLogger.Warningf("Failed to set DRA feature gate: ", err)
}
sc.internalPlugins = k8splugins.InitializeInternalPlugins(sc.kubeClient, sc.informerFactory, sc.SnapshotSharedLister())

sc.podLister = sc.informerFactory.Core().V1().Pods().Lister()
Expand Down
45 changes: 45 additions & 0 deletions pkg/scheduler/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
resourcev1 "k8s.io/api/resource/v1"
resourcev1alhpa3 "k8s.io/api/resource/v1alpha3"
resourcev1beta1 "k8s.io/api/resource/v1beta1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
version "k8s.io/apimachinery/pkg/version"
featureutil "k8s.io/apiserver/pkg/util/feature"
fakediscovery "k8s.io/client-go/discovery/fake"
"k8s.io/client-go/kubernetes/fake"
faketesting "k8s.io/client-go/testing"
"k8s.io/kubernetes/pkg/features"
"k8s.io/utils/ptr"

kubeaischedulerfake "github.com/NVIDIA/KAI-scheduler/pkg/apis/client/clientset/versioned/fake"
Expand All @@ -49,6 +56,44 @@ func TestCache(t *testing.T) {
}

var _ = Describe("Cache", func() {
Describe("New", func() {
Context("DRA Feature Gate", func() {
DescribeTable("should enable DRA feature gate based on Kubernetes version and resource API availability",
func(serverMajor, serverMinor string, resourceGroupVersions []string, expectDRAFeatureEnabled bool) {
fakeClient := fake.NewClientset()
fakeClient.Discovery().(*fakediscovery.FakeDiscovery).FakedServerVersion = &version.Info{
Major: serverMajor,
Minor: serverMinor,
}

for _, groupVersion := range resourceGroupVersions {
fakeClient.Resources = append(fakeClient.Resources, &metav1.APIResourceList{GroupVersion: groupVersion})
}

params := &SchedulerCacheParams{
KubeClient: fakeClient,
KAISchedulerClient: kubeaischedulerfake.NewSimpleClientset(),
KueueClient: kueuefake.NewSimpleClientset(),
NodePoolParams: &conf.SchedulingNodePoolParams{},
}

cache := New(params)

Expect(cache).NotTo(BeNil())

// Check if the DynamicResourceAllocation feature gate has the expected state
draEnabled := featureutil.DefaultFeatureGate.Enabled(features.DynamicResourceAllocation)
Expect(draEnabled).To(Equal(expectDRAFeatureEnabled))
},
Entry("compatible version (1.32) with resource API should enable DRA", "1", "32", []string{resourcev1beta1.SchemeGroupVersion.String()}, true),
Entry("compatible version (1.32) without resource API should not enable DRA", "1", "32", []string{}, false),
Entry("incompatible version (1.25) with resource API should not enable DRA", "1", "25", []string{resourcev1beta1.SchemeGroupVersion.String()}, false),
Entry("incompatible version (1.25) without resource API should not enable DRA", "1", "25", []string{}, false),
Entry("edge case version (1.31) with resource API should not enable DRA", "1", "31", []string{resourcev1alhpa3.SchemeGroupVersion.String()}, false),
Entry("higher compatible version (1.35) with resource API should enable DRA", "1", "34", []string{resourcev1.SchemeGroupVersion.String()}, true),
)
})
})
Describe("Bind", func() {
Context("failure to bind", func() {
It("should return error", func() {
Expand Down
Loading