Skip to content

Commit 83c5f99

Browse files
authored
Merge pull request kubernetes#128184 from cupnes/add-storage-capacity-scoring
KEP-4049: Add storage capacity scoring to VolumeBinding plugin
2 parents fd34707 + d663306 commit 83c5f99

File tree

18 files changed

+535
-178
lines changed

18 files changed

+535
-178
lines changed

cmd/kube-scheduler/app/server_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ import (
3939
basecompatibility "k8s.io/component-base/compatibility"
4040
componentbaseconfig "k8s.io/component-base/config"
4141
"k8s.io/component-base/featuregate"
42-
featuregatetesting "k8s.io/component-base/featuregate/testing"
4342
configv1 "k8s.io/kube-scheduler/config/v1"
4443
"k8s.io/kubernetes/cmd/kube-scheduler/app/options"
45-
"k8s.io/kubernetes/pkg/features"
4644
"k8s.io/kubernetes/pkg/scheduler/apis/config"
4745
"k8s.io/kubernetes/pkg/scheduler/apis/config/testing/defaults"
4846
"k8s.io/kubernetes/pkg/scheduler/framework"
@@ -222,19 +220,6 @@ leaderElection:
222220
wantErr bool
223221
wantFeaturesGates map[string]bool
224222
}{
225-
{
226-
name: "default config with an alpha feature enabled",
227-
flags: []string{
228-
"--kubeconfig", configKubeconfig,
229-
"--feature-gates=VolumeCapacityPriority=true",
230-
},
231-
wantPlugins: map[string]*config.Plugins{
232-
"default-scheduler": defaults.ExpandedPluginsV1,
233-
},
234-
restoreFeatures: map[featuregate.Feature]bool{
235-
features.VolumeCapacityPriority: false,
236-
},
237-
},
238223
{
239224
name: "component configuration v1 with only scheduler name configured",
240225
flags: []string{
@@ -435,9 +420,6 @@ leaderElection:
435420

436421
for _, tc := range testcases {
437422
t.Run(tc.name, func(t *testing.T) {
438-
for k, v := range tc.restoreFeatures {
439-
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, k, v)
440-
}
441423
componentGlobalsRegistry := basecompatibility.NewComponentGlobalsRegistry()
442424
verKube := basecompatibility.NewEffectiveVersionFromString("1.32", "1.31", "1.31")
443425
fg := feature.DefaultFeatureGate.DeepCopy()

pkg/features/kube_features.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,13 @@ const (
692692
// Enables trafficDistribution field on Services.
693693
ServiceTrafficDistribution featuregate.Feature = "ServiceTrafficDistribution"
694694

695+
// owner: @cupnes
696+
// kep: https://kep.k8s.io/4049
697+
//
698+
// Enables scoring nodes by available storage capacity with
699+
// StorageCapacityScoring feature gate.
700+
StorageCapacityScoring featuregate.Feature = "StorageCapacityScoring"
701+
695702
// owner: @gjkim42 @SergeyKanzhelev @matthyx @tzneal
696703
// kep: http://kep.k8s.io/753
697704
//
@@ -798,9 +805,6 @@ const (
798805
// Enables user specified volume attributes for persistent volumes, like iops and throughput.
799806
VolumeAttributesClass featuregate.Feature = "VolumeAttributesClass"
800807

801-
// owner: @cofyc
802-
VolumeCapacityPriority featuregate.Feature = "VolumeCapacityPriority"
803-
804808
// owner: @ksubrmnn
805809
//
806810
// Allows kube-proxy to create DSR loadbalancers for Windows

pkg/features/versioned_kube_features.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,10 @@ var defaultVersionedKubernetesFeatureGates = map[featuregate.Feature]featuregate
766766
{Version: version.MustParse("1.31"), Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // GA in 1.31, remove in 1.33
767767
},
768768

769+
StorageCapacityScoring: {
770+
{Version: version.MustParse("1.33"), Default: false, PreRelease: featuregate.Alpha},
771+
},
772+
769773
StorageVersionMigrator: {
770774
{Version: version.MustParse("1.30"), Default: false, PreRelease: featuregate.Alpha},
771775
},
@@ -836,10 +840,6 @@ var defaultVersionedKubernetesFeatureGates = map[featuregate.Feature]featuregate
836840
{Version: version.MustParse("1.31"), Default: false, PreRelease: featuregate.Beta},
837841
},
838842

839-
VolumeCapacityPriority: {
840-
{Version: version.MustParse("1.21"), Default: false, PreRelease: featuregate.Alpha},
841-
},
842-
843843
WinDSR: {
844844
{Version: version.MustParse("1.14"), Default: false, PreRelease: featuregate.Alpha},
845845
},

pkg/generated/openapi/zz_generated.openapi.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/scheduler/apis/config/types_pluginargs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ type VolumeBindingArgs struct {
163163
// 1) 0 for 0 utilization
164164
// 2) 10 for 100 utilization
165165
// All points must be sorted in increasing order by utilization.
166-
// +featureGate=VolumeCapacityPriority
166+
// +featureGate=StorageCapacityScoring
167167
// +optional
168168
Shape []UtilizationShapePoint
169169
}

pkg/scheduler/apis/config/v1/defaults.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ func SetDefaults_VolumeBindingArgs(obj *configv1.VolumeBindingArgs) {
192192
if obj.BindTimeoutSeconds == nil {
193193
obj.BindTimeoutSeconds = ptr.To[int64](600)
194194
}
195-
if len(obj.Shape) == 0 && feature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority) {
195+
if len(obj.Shape) == 0 && feature.DefaultFeatureGate.Enabled(features.StorageCapacityScoring) {
196196
obj.Shape = []configv1.UtilizationShapePoint{
197197
{
198198
Utilization: 0,
199-
Score: 0,
199+
Score: int32(config.MaxCustomPriorityScore),
200200
},
201201
{
202202
Utilization: 100,
203-
Score: int32(config.MaxCustomPriorityScore),
203+
Score: 0,
204204
},
205205
}
206206
}

pkg/scheduler/apis/config/v1/defaults_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,26 +810,26 @@ func TestPluginArgsDefaults(t *testing.T) {
810810
},
811811
},
812812
{
813-
name: "VolumeBindingArgs empty, VolumeCapacityPriority disabled",
813+
name: "VolumeBindingArgs empty, StorageCapacityScoring disabled",
814814
features: map[featuregate.Feature]bool{
815-
features.VolumeCapacityPriority: false,
815+
features.StorageCapacityScoring: false,
816816
},
817817
in: &configv1.VolumeBindingArgs{},
818818
want: &configv1.VolumeBindingArgs{
819819
BindTimeoutSeconds: ptr.To[int64](600),
820820
},
821821
},
822822
{
823-
name: "VolumeBindingArgs empty, VolumeCapacityPriority enabled",
823+
name: "VolumeBindingArgs empty, StorageCapacityScoring enabled",
824824
features: map[featuregate.Feature]bool{
825-
features.VolumeCapacityPriority: true,
825+
features.StorageCapacityScoring: true,
826826
},
827827
in: &configv1.VolumeBindingArgs{},
828828
want: &configv1.VolumeBindingArgs{
829829
BindTimeoutSeconds: ptr.To[int64](600),
830830
Shape: []configv1.UtilizationShapePoint{
831-
{Utilization: 0, Score: 0},
832-
{Utilization: 100, Score: 10},
831+
{Utilization: 0, Score: 10},
832+
{Utilization: 100, Score: 0},
833833
},
834834
},
835835
},

pkg/scheduler/apis/config/validation/validation_pluginargs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,13 @@ func ValidateNodeAffinityArgs(path *field.Path, args *config.NodeAffinityArgs) e
261261

262262
// VolumeBindingArgsValidationOptions contains the different settings for validation.
263263
type VolumeBindingArgsValidationOptions struct {
264-
AllowVolumeCapacityPriority bool
264+
AllowStorageCapacityScoring bool
265265
}
266266

267267
// ValidateVolumeBindingArgs validates that VolumeBindingArgs are set correctly.
268268
func ValidateVolumeBindingArgs(path *field.Path, args *config.VolumeBindingArgs) error {
269269
return ValidateVolumeBindingArgsWithOptions(path, args, VolumeBindingArgsValidationOptions{
270-
AllowVolumeCapacityPriority: utilfeature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority),
270+
AllowStorageCapacityScoring: utilfeature.DefaultFeatureGate.Enabled(features.StorageCapacityScoring),
271271
})
272272
}
273273

@@ -279,13 +279,13 @@ func ValidateVolumeBindingArgsWithOptions(path *field.Path, args *config.VolumeB
279279
allErrs = append(allErrs, field.Invalid(path.Child("bindTimeoutSeconds"), args.BindTimeoutSeconds, "invalid BindTimeoutSeconds, should not be a negative value"))
280280
}
281281

282-
if opts.AllowVolumeCapacityPriority {
282+
if opts.AllowStorageCapacityScoring {
283283
allErrs = append(allErrs, validateFunctionShape(args.Shape, path.Child("shape"))...)
284284
} else if args.Shape != nil {
285285
// When the feature is off, return an error if the config is not nil.
286286
// This prevents unexpected configuration from taking effect when the
287287
// feature turns on in the future.
288-
allErrs = append(allErrs, field.Invalid(path.Child("shape"), args.Shape, "unexpected field `shape`, remove it or turn on the feature gate VolumeCapacityPriority"))
288+
allErrs = append(allErrs, field.Invalid(path.Child("shape"), args.Shape, "unexpected field `shape`, remove it or turn on the feature gate StorageCapacityScoring"))
289289
}
290290
return allErrs.ToAggregate()
291291
}

pkg/scheduler/apis/config/validation/validation_pluginargs_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -559,19 +559,19 @@ func TestValidateVolumeBindingArgs(t *testing.T) {
559559
}}),
560560
},
561561
{
562-
name: "[VolumeCapacityPriority=off] shape should be nil when the feature is off",
562+
name: "[StorageCapacityScoring=off] shape should be nil when the feature is off",
563563
features: map[featuregate.Feature]bool{
564-
features.VolumeCapacityPriority: false,
564+
features.StorageCapacityScoring: false,
565565
},
566566
args: config.VolumeBindingArgs{
567567
BindTimeoutSeconds: 10,
568568
Shape: nil,
569569
},
570570
},
571571
{
572-
name: "[VolumeCapacityPriority=off] error if the shape is not nil when the feature is off",
572+
name: "[StorageCapacityScoring=off] error if the shape is not nil when the feature is off",
573573
features: map[featuregate.Feature]bool{
574-
features.VolumeCapacityPriority: false,
574+
features.StorageCapacityScoring: false,
575575
},
576576
args: config.VolumeBindingArgs{
577577
BindTimeoutSeconds: 10,
@@ -586,9 +586,9 @@ func TestValidateVolumeBindingArgs(t *testing.T) {
586586
}}),
587587
},
588588
{
589-
name: "[VolumeCapacityPriority=on] shape should not be empty",
589+
name: "[StorageCapacityScoring=on] shape should not be empty",
590590
features: map[featuregate.Feature]bool{
591-
features.VolumeCapacityPriority: true,
591+
features.StorageCapacityScoring: true,
592592
},
593593
args: config.VolumeBindingArgs{
594594
BindTimeoutSeconds: 10,
@@ -600,9 +600,9 @@ func TestValidateVolumeBindingArgs(t *testing.T) {
600600
}}),
601601
},
602602
{
603-
name: "[VolumeCapacityPriority=on] shape points must be sorted in increasing order",
603+
name: "[StorageCapacityScoring=on] shape points must be sorted in increasing order",
604604
features: map[featuregate.Feature]bool{
605-
features.VolumeCapacityPriority: true,
605+
features.StorageCapacityScoring: true,
606606
},
607607
args: config.VolumeBindingArgs{
608608
BindTimeoutSeconds: 10,
@@ -618,9 +618,9 @@ func TestValidateVolumeBindingArgs(t *testing.T) {
618618
}}),
619619
},
620620
{
621-
name: "[VolumeCapacityPriority=on] shape point: invalid utilization and score",
621+
name: "[StorageCapacityScoring=on] shape point: invalid utilization and score",
622622
features: map[featuregate.Feature]bool{
623-
features.VolumeCapacityPriority: true,
623+
features.StorageCapacityScoring: true,
624624
},
625625
args: config.VolumeBindingArgs{
626626
BindTimeoutSeconds: 10,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ type Features struct {
2323
EnableDRAPrioritizedList bool
2424
EnableDRAAdminAccess bool
2525
EnableDynamicResourceAllocation bool
26-
EnableVolumeCapacityPriority bool
2726
EnableVolumeAttributesClass bool
2827
EnableCSIMigrationPortworx bool
2928
EnableNodeInclusionPolicyInPodTopologySpread bool
@@ -33,4 +32,5 @@ type Features struct {
3332
EnableSchedulingQueueHint bool
3433
EnableAsyncPreemption bool
3534
EnablePodLevelResources bool
35+
EnableStorageCapacityScoring bool
3636
}

0 commit comments

Comments
 (0)