Skip to content

Commit 239aad8

Browse files
committed
chore(scheduler): use framework.Features in scheduler plugins
1 parent 566f939 commit 239aad8

File tree

9 files changed

+53
-41
lines changed

9 files changed

+53
-41
lines changed

pkg/scheduler/framework/plugins/feature/feature.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type Features struct {
2323
EnableDRAAdminAccess bool
2424
EnableDynamicResourceAllocation bool
2525
EnableVolumeCapacityPriority bool
26+
EnableVolumeAttributesClass bool
27+
EnableCSIMigrationPortworx bool
2628
EnableNodeInclusionPolicyInPodTopologySpread bool
2729
EnableMatchLabelKeysInPodTopologySpread bool
2830
EnableInPlacePodVerticalScaling bool

pkg/scheduler/framework/plugins/noderesources/balanced_allocation.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ func NewBalancedAllocation(_ context.Context, baArgs runtime.Object, h framework
127127
return &BalancedAllocation{
128128
handle: h,
129129
resourceAllocationScorer: resourceAllocationScorer{
130-
Name: BalancedAllocationName,
131-
scorer: balancedResourceScorer,
132-
useRequested: true,
133-
resources: args.Resources,
130+
Name: BalancedAllocationName,
131+
enableInPlacePodVerticalScaling: fts.EnableInPlacePodVerticalScaling,
132+
enablePodLevelResources: fts.EnablePodLevelResources,
133+
scorer: balancedResourceScorer,
134+
useRequested: true,
135+
resources: args.Resources,
134136
},
135137
}, nil
136138
}

pkg/scheduler/framework/plugins/noderesources/resource_allocation.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ import (
2121

2222
v1 "k8s.io/api/core/v1"
2323
"k8s.io/apimachinery/pkg/api/resource"
24-
utilfeature "k8s.io/apiserver/pkg/util/feature"
2524
"k8s.io/klog/v2"
2625

2726
resourcehelper "k8s.io/component-helpers/resource"
28-
"k8s.io/kubernetes/pkg/features"
2927
"k8s.io/kubernetes/pkg/scheduler/apis/config"
3028
"k8s.io/kubernetes/pkg/scheduler/framework"
3129
schedutil "k8s.io/kubernetes/pkg/scheduler/util"
@@ -36,7 +34,9 @@ type scorer func(args *config.NodeResourcesFitArgs) *resourceAllocationScorer
3634

3735
// resourceAllocationScorer contains information to calculate resource allocation score.
3836
type resourceAllocationScorer struct {
39-
Name string
37+
Name string
38+
enableInPlacePodVerticalScaling bool
39+
enablePodLevelResources bool
4040
// used to decide whether to use Requested or NonZeroRequested for
4141
// cpu and memory.
4242
useRequested bool
@@ -118,9 +118,9 @@ func (r *resourceAllocationScorer) calculateResourceAllocatableRequest(logger kl
118118
func (r *resourceAllocationScorer) calculatePodResourceRequest(pod *v1.Pod, resourceName v1.ResourceName) int64 {
119119

120120
opts := resourcehelper.PodResourcesOptions{
121-
UseStatusResources: utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling),
121+
UseStatusResources: r.enableInPlacePodVerticalScaling,
122122
// SkipPodLevelResources is set to false when PodLevelResources feature is enabled.
123-
SkipPodLevelResources: !utilfeature.DefaultFeatureGate.Enabled(features.PodLevelResources),
123+
SkipPodLevelResources: !r.enablePodLevelResources,
124124
}
125125

126126
if !r.useRequested {

pkg/scheduler/framework/plugins/nodevolumelimits/csi.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ type CSILimits struct {
6363
scLister storagelisters.StorageClassLister
6464
vaLister storagelisters.VolumeAttachmentLister
6565

66-
randomVolumeIDPrefix string
66+
enableCSIMigrationPortworx bool
67+
randomVolumeIDPrefix string
6768

6869
translator InTreeToCSITranslator
6970
}
@@ -377,7 +378,7 @@ func (pl *CSILimits) checkAttachableInlineVolume(logger klog.Logger, vol *v1.Vol
377378
if err != nil {
378379
return fmt.Errorf("looking up provisioner name for volume %s: %w", vol.Name, err)
379380
}
380-
if !isCSIMigrationOn(csiNode, inTreeProvisionerName) {
381+
if !isCSIMigrationOn(csiNode, inTreeProvisionerName, pl.enableCSIMigrationPortworx) {
381382
csiNodeName := ""
382383
if csiNode != nil {
383384
csiNodeName = csiNode.Name
@@ -438,7 +439,7 @@ func (pl *CSILimits) getCSIDriverInfo(logger klog.Logger, csiNode *storagev1.CSI
438439
return "", ""
439440
}
440441

441-
if !isCSIMigrationOn(csiNode, pluginName) {
442+
if !isCSIMigrationOn(csiNode, pluginName, pl.enableCSIMigrationPortworx) {
442443
logger.V(5).Info("CSI Migration of plugin is not enabled", "plugin", pluginName)
443444
return "", ""
444445
}
@@ -486,7 +487,7 @@ func (pl *CSILimits) getCSIDriverInfoFromSC(logger klog.Logger, csiNode *storage
486487

487488
provisioner := storageClass.Provisioner
488489
if pl.translator.IsMigratableIntreePluginByName(provisioner) {
489-
if !isCSIMigrationOn(csiNode, provisioner) {
490+
if !isCSIMigrationOn(csiNode, provisioner, pl.enableCSIMigrationPortworx) {
490491
logger.V(5).Info("CSI Migration of provisioner is not enabled", "provisioner", provisioner)
491492
return "", ""
492493
}
@@ -513,13 +514,14 @@ func NewCSI(_ context.Context, _ runtime.Object, handle framework.Handle, fts fe
513514
csiTranslator := csitrans.New()
514515

515516
return &CSILimits{
516-
csiNodeLister: csiNodesLister,
517-
pvLister: pvLister,
518-
pvcLister: pvcLister,
519-
scLister: scLister,
520-
vaLister: vaLister,
521-
randomVolumeIDPrefix: rand.String(32),
522-
translator: csiTranslator,
517+
csiNodeLister: csiNodesLister,
518+
pvLister: pvLister,
519+
pvcLister: pvcLister,
520+
scLister: scLister,
521+
vaLister: vaLister,
522+
enableCSIMigrationPortworx: fts.EnableCSIMigrationPortworx,
523+
randomVolumeIDPrefix: rand.String(32),
524+
translator: csiTranslator,
523525
}, nil
524526
}
525527

pkg/scheduler/framework/plugins/nodevolumelimits/utils.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ import (
2222
v1 "k8s.io/api/core/v1"
2323
storagev1 "k8s.io/api/storage/v1"
2424
"k8s.io/apimachinery/pkg/util/sets"
25-
utilfeature "k8s.io/apiserver/pkg/util/feature"
2625
csilibplugins "k8s.io/csi-translation-lib/plugins"
27-
"k8s.io/kubernetes/pkg/features"
2826
)
2927

3028
// isCSIMigrationOn returns a boolean value indicating whether
3129
// the CSI migration has been enabled for a particular storage plugin.
32-
func isCSIMigrationOn(csiNode *storagev1.CSINode, pluginName string) bool {
30+
func isCSIMigrationOn(csiNode *storagev1.CSINode, pluginName string, enableCSIMigrationPortworx bool) bool {
3331
if csiNode == nil || len(pluginName) == 0 {
3432
return false
3533
}
@@ -40,7 +38,7 @@ func isCSIMigrationOn(csiNode *storagev1.CSINode, pluginName string) bool {
4038
case csilibplugins.AWSEBSInTreePluginName:
4139
return true
4240
case csilibplugins.PortworxVolumePluginName:
43-
if !utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationPortworx) {
41+
if !enableCSIMigrationPortworx {
4442
return false
4543
}
4644
case csilibplugins.GCEPDInTreePluginName:

pkg/scheduler/framework/plugins/registry.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ func NewInTreeRegistry() runtime.Registry {
4949
EnableDRAAdminAccess: feature.DefaultFeatureGate.Enabled(features.DRAAdminAccess),
5050
EnableDynamicResourceAllocation: feature.DefaultFeatureGate.Enabled(features.DynamicResourceAllocation),
5151
EnableVolumeCapacityPriority: feature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority),
52+
EnableVolumeAttributesClass: feature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass),
53+
EnableCSIMigrationPortworx: feature.DefaultFeatureGate.Enabled(features.CSIMigrationPortworx),
5254
EnableNodeInclusionPolicyInPodTopologySpread: feature.DefaultFeatureGate.Enabled(features.NodeInclusionPolicyInPodTopologySpread),
5355
EnableMatchLabelKeysInPodTopologySpread: feature.DefaultFeatureGate.Enabled(features.MatchLabelKeysInPodTopologySpread),
5456
EnableInPlacePodVerticalScaling: feature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling),

pkg/scheduler/framework/plugins/volumebinding/binder.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"k8s.io/apimachinery/pkg/util/sets"
3434
"k8s.io/apimachinery/pkg/util/wait"
3535
"k8s.io/apiserver/pkg/storage"
36-
utilfeature "k8s.io/apiserver/pkg/util/feature"
3736
coreinformers "k8s.io/client-go/informers/core/v1"
3837
storageinformers "k8s.io/client-go/informers/storage/v1"
3938
clientset "k8s.io/client-go/kubernetes"
@@ -45,7 +44,7 @@ import (
4544
csiplugins "k8s.io/csi-translation-lib/plugins"
4645
"k8s.io/klog/v2"
4746
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
48-
"k8s.io/kubernetes/pkg/features"
47+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/feature"
4948
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding/metrics"
5049
"k8s.io/kubernetes/pkg/scheduler/util/assumecache"
5150
)
@@ -203,7 +202,9 @@ type PodVolumeClaims struct {
203202
}
204203

205204
type volumeBinder struct {
206-
kubeClient clientset.Interface
205+
kubeClient clientset.Interface
206+
enableVolumeAttributesClass bool
207+
enableCSIMigrationPortworx bool
207208

208209
classLister storagelisters.StorageClassLister
209210
podLister corelisters.PodLister
@@ -238,6 +239,7 @@ type CapacityCheck struct {
238239
func NewVolumeBinder(
239240
logger klog.Logger,
240241
kubeClient clientset.Interface,
242+
fts feature.Features,
241243
podInformer coreinformers.PodInformer,
242244
nodeInformer coreinformers.NodeInformer,
243245
csiNodeInformer storageinformers.CSINodeInformer,
@@ -247,15 +249,17 @@ func NewVolumeBinder(
247249
capacityCheck CapacityCheck,
248250
bindTimeout time.Duration) SchedulerVolumeBinder {
249251
b := &volumeBinder{
250-
kubeClient: kubeClient,
251-
podLister: podInformer.Lister(),
252-
classLister: storageClassInformer.Lister(),
253-
nodeLister: nodeInformer.Lister(),
254-
csiNodeLister: csiNodeInformer.Lister(),
255-
pvcCache: NewPVCAssumeCache(logger, pvcInformer.Informer()),
256-
pvCache: NewPVAssumeCache(logger, pvInformer.Informer()),
257-
bindTimeout: bindTimeout,
258-
translator: csitrans.New(),
252+
kubeClient: kubeClient,
253+
enableVolumeAttributesClass: fts.EnableVolumeAttributesClass,
254+
enableCSIMigrationPortworx: fts.EnableCSIMigrationPortworx,
255+
podLister: podInformer.Lister(),
256+
classLister: storageClassInformer.Lister(),
257+
nodeLister: nodeInformer.Lister(),
258+
csiNodeLister: csiNodeInformer.Lister(),
259+
pvcCache: NewPVCAssumeCache(logger, pvcInformer.Informer()),
260+
pvCache: NewPVAssumeCache(logger, pvInformer.Informer()),
261+
bindTimeout: bindTimeout,
262+
translator: csitrans.New(),
259263
}
260264

261265
b.csiDriverLister = capacityCheck.CSIDriverInformer.Lister()
@@ -855,7 +859,7 @@ func (b *volumeBinder) findMatchingVolumes(logger klog.Logger, pod *v1.Pod, clai
855859
pvs := unboundVolumesDelayBinding[storageClassName]
856860

857861
// Find a matching PV
858-
pv, err := volume.FindMatchingVolume(pvc, pvs, node, chosenPVs, true, utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass))
862+
pv, err := volume.FindMatchingVolume(pvc, pvs, node, chosenPVs, true, b.enableVolumeAttributesClass)
859863
if err != nil {
860864
return false, nil, nil, err
861865
}
@@ -1033,7 +1037,7 @@ func (a byPVCSize) Less(i, j int) bool {
10331037
}
10341038

10351039
// isCSIMigrationOnForPlugin checks if CSI migration is enabled for a given plugin.
1036-
func isCSIMigrationOnForPlugin(pluginName string) bool {
1040+
func isCSIMigrationOnForPlugin(pluginName string, enableCSIMigrationPortworx bool) bool {
10371041
switch pluginName {
10381042
case csiplugins.AWSEBSInTreePluginName:
10391043
return true
@@ -1044,7 +1048,7 @@ func isCSIMigrationOnForPlugin(pluginName string) bool {
10441048
case csiplugins.CinderInTreePluginName:
10451049
return true
10461050
case csiplugins.PortworxVolumePluginName:
1047-
return utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationPortworx)
1051+
return enableCSIMigrationPortworx
10481052
}
10491053
return false
10501054
}
@@ -1083,7 +1087,7 @@ func (b *volumeBinder) tryTranslatePVToCSI(logger klog.Logger, pv *v1.Persistent
10831087
return nil, fmt.Errorf("could not get plugin name from pv: %v", err)
10841088
}
10851089

1086-
if !isCSIMigrationOnForPlugin(pluginName) {
1090+
if !isCSIMigrationOnForPlugin(pluginName, b.enableCSIMigrationPortworx) {
10871091
return pv, nil
10881092
}
10891093

pkg/scheduler/framework/plugins/volumebinding/binder_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
_ "k8s.io/klog/v2/ktesting/init"
4646
"k8s.io/kubernetes/pkg/controller"
4747
pvtesting "k8s.io/kubernetes/pkg/controller/volume/persistentvolume/testing"
48+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/feature"
4849
"k8s.io/kubernetes/pkg/scheduler/util/assumecache"
4950
)
5051

@@ -167,6 +168,7 @@ func newTestBinder(t *testing.T, ctx context.Context) *testEnv {
167168
binder := NewVolumeBinder(
168169
logger,
169170
client,
171+
feature.Features{},
170172
podInformer,
171173
nodeInformer,
172174
csiNodeInformer,

pkg/scheduler/framework/plugins/volumebinding/volume_binding.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ func New(ctx context.Context, plArgs runtime.Object, fh framework.Handle, fts fe
579579
CSIDriverInformer: fh.SharedInformerFactory().Storage().V1().CSIDrivers(),
580580
CSIStorageCapacityInformer: fh.SharedInformerFactory().Storage().V1().CSIStorageCapacities(),
581581
}
582-
binder := NewVolumeBinder(klog.FromContext(ctx), fh.ClientSet(), podInformer, nodeInformer, csiNodeInformer, pvcInformer, pvInformer, storageClassInformer, capacityCheck, time.Duration(args.BindTimeoutSeconds)*time.Second)
582+
binder := NewVolumeBinder(klog.FromContext(ctx), fh.ClientSet(), fts, podInformer, nodeInformer, csiNodeInformer, pvcInformer, pvInformer, storageClassInformer, capacityCheck, time.Duration(args.BindTimeoutSeconds)*time.Second)
583583

584584
// build score function
585585
var scorer volumeCapacityScorer

0 commit comments

Comments
 (0)