Switch control from VolumeCapacityPriority to StorageCapacityScoring

The tests and comments have also been updated because while
VolumeCapacityPriority preferred a node with the least allocatable,
StorageCapacityScoring preferred a node with the maximum allocatable.
This commit is contained in:
Yuma Ogami 2025-02-18 09:16:13 +00:00
parent f6ddee95f9
commit 43382b1b39
12 changed files with 60 additions and 78 deletions

View File

@ -226,13 +226,13 @@ leaderElection:
name: "default config with an alpha feature enabled",
flags: []string{
"--kubeconfig", configKubeconfig,
"--feature-gates=VolumeCapacityPriority=true",
"--feature-gates=StorageCapacityScoring=true",
},
wantPlugins: map[string]*config.Plugins{
"default-scheduler": defaults.ExpandedPluginsV1,
},
restoreFeatures: map[featuregate.Feature]bool{
features.VolumeCapacityPriority: false,
features.StorageCapacityScoring: false,
},
},
{

View File

@ -681,7 +681,7 @@ const (
// kep: https://kep.k8s.io/4049
//
// Enables scoring nodes by available storage capacity with
// StorageCapacityScoring feature gate (dynamic provisioning only).
// StorageCapacityScoring feature gate.
StorageCapacityScoring featuregate.Feature = "StorageCapacityScoring"
// owner: @gjkim42 @SergeyKanzhelev @matthyx @tzneal

View File

@ -64030,7 +64030,7 @@ func schema_k8sio_kube_scheduler_config_v1_VolumeBindingArgs(ref common.Referenc
},
},
SchemaProps: spec.SchemaProps{
Description: "Shape specifies the points defining the score function shape, which is used to score nodes based on the utilization of statically provisioned PVs. The utilization is calculated by dividing the total requested storage of the pod by the total capacity of feasible PVs on each node. Each point contains utilization (ranges from 0 to 100) and its associated score (ranges from 0 to 10). You can turn the priority by specifying different scores for different utilization numbers. The default shape points are: 1) 0 for 0 utilization 2) 10 for 100 utilization All points must be sorted in increasing order by utilization.",
Description: "Shape specifies the points defining the score function shape, which is used to score nodes based on the utilization of provisioned PVs. The utilization is calculated by dividing the total requested storage of the pod by the total capacity of feasible PVs on each node. Each point contains utilization (ranges from 0 to 100) and its associated score (ranges from 0 to 10). You can turn the priority by specifying different scores for different utilization numbers. The default shape points are: 1) 10 for 0 utilization 2) 0 for 100 utilization All points must be sorted in increasing order by utilization.",
Type: []string{"array"},
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{

View File

@ -163,7 +163,7 @@ type VolumeBindingArgs struct {
// 1) 0 for 0 utilization
// 2) 10 for 100 utilization
// All points must be sorted in increasing order by utilization.
// +featureGate=VolumeCapacityPriority
// +featureGate=StorageCapacityScoring
// +optional
Shape []UtilizationShapePoint
}

View File

@ -192,29 +192,16 @@ func SetDefaults_VolumeBindingArgs(obj *configv1.VolumeBindingArgs) {
if obj.BindTimeoutSeconds == nil {
obj.BindTimeoutSeconds = ptr.To[int64](600)
}
if len(obj.Shape) == 0 && feature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority) {
if feature.DefaultFeatureGate.Enabled(features.StorageCapacityScoring) {
obj.Shape = []configv1.UtilizationShapePoint{
{
Utilization: 0,
Score: int32(config.MaxCustomPriorityScore),
},
{
Utilization: 100,
Score: 0,
},
}
} else {
obj.Shape = []configv1.UtilizationShapePoint{
{
Utilization: 0,
Score: 0,
},
{
Utilization: 100,
Score: int32(config.MaxCustomPriorityScore),
},
}
if len(obj.Shape) == 0 && feature.DefaultFeatureGate.Enabled(features.StorageCapacityScoring) {
obj.Shape = []configv1.UtilizationShapePoint{
{
Utilization: 0,
Score: int32(config.MaxCustomPriorityScore),
},
{
Utilization: 100,
Score: 0,
},
}
}
}

View File

@ -810,9 +810,9 @@ func TestPluginArgsDefaults(t *testing.T) {
},
},
{
name: "VolumeBindingArgs empty, VolumeCapacityPriority disabled",
name: "VolumeBindingArgs empty, StorageCapacityScoring disabled",
features: map[featuregate.Feature]bool{
features.VolumeCapacityPriority: false,
features.StorageCapacityScoring: false,
},
in: &configv1.VolumeBindingArgs{},
want: &configv1.VolumeBindingArgs{
@ -820,16 +820,16 @@ func TestPluginArgsDefaults(t *testing.T) {
},
},
{
name: "VolumeBindingArgs empty, VolumeCapacityPriority enabled",
name: "VolumeBindingArgs empty, StorageCapacityScoring enabled",
features: map[featuregate.Feature]bool{
features.VolumeCapacityPriority: true,
features.StorageCapacityScoring: true,
},
in: &configv1.VolumeBindingArgs{},
want: &configv1.VolumeBindingArgs{
BindTimeoutSeconds: ptr.To[int64](600),
Shape: []configv1.UtilizationShapePoint{
{Utilization: 0, Score: 0},
{Utilization: 100, Score: 10},
{Utilization: 0, Score: 10},
{Utilization: 100, Score: 0},
},
},
},

View File

@ -261,13 +261,13 @@ func ValidateNodeAffinityArgs(path *field.Path, args *config.NodeAffinityArgs) e
// VolumeBindingArgsValidationOptions contains the different settings for validation.
type VolumeBindingArgsValidationOptions struct {
AllowVolumeCapacityPriority bool
AllowStorageCapacityScoring bool
}
// ValidateVolumeBindingArgs validates that VolumeBindingArgs are set correctly.
func ValidateVolumeBindingArgs(path *field.Path, args *config.VolumeBindingArgs) error {
return ValidateVolumeBindingArgsWithOptions(path, args, VolumeBindingArgsValidationOptions{
AllowVolumeCapacityPriority: utilfeature.DefaultFeatureGate.Enabled(features.VolumeCapacityPriority),
AllowStorageCapacityScoring: utilfeature.DefaultFeatureGate.Enabled(features.StorageCapacityScoring),
})
}
@ -279,13 +279,13 @@ func ValidateVolumeBindingArgsWithOptions(path *field.Path, args *config.VolumeB
allErrs = append(allErrs, field.Invalid(path.Child("bindTimeoutSeconds"), args.BindTimeoutSeconds, "invalid BindTimeoutSeconds, should not be a negative value"))
}
if opts.AllowVolumeCapacityPriority {
if opts.AllowStorageCapacityScoring {
allErrs = append(allErrs, validateFunctionShape(args.Shape, path.Child("shape"))...)
} else if args.Shape != nil {
// When the feature is off, return an error if the config is not nil.
// This prevents unexpected configuration from taking effect when the
// feature turns on in the future.
allErrs = append(allErrs, field.Invalid(path.Child("shape"), args.Shape, "unexpected field `shape`, remove it or turn on the feature gate VolumeCapacityPriority"))
allErrs = append(allErrs, field.Invalid(path.Child("shape"), args.Shape, "unexpected field `shape`, remove it or turn on the feature gate StorageCapacityScoring"))
}
return allErrs.ToAggregate()
}

View File

@ -559,9 +559,9 @@ func TestValidateVolumeBindingArgs(t *testing.T) {
}}),
},
{
name: "[VolumeCapacityPriority=off] shape should be nil when the feature is off",
name: "[StorageCapacityScoring=off] shape should be nil when the feature is off",
features: map[featuregate.Feature]bool{
features.VolumeCapacityPriority: false,
features.StorageCapacityScoring: false,
},
args: config.VolumeBindingArgs{
BindTimeoutSeconds: 10,
@ -569,9 +569,9 @@ func TestValidateVolumeBindingArgs(t *testing.T) {
},
},
{
name: "[VolumeCapacityPriority=off] error if the shape is not nil when the feature is off",
name: "[StorageCapacityScoring=off] error if the shape is not nil when the feature is off",
features: map[featuregate.Feature]bool{
features.VolumeCapacityPriority: false,
features.StorageCapacityScoring: false,
},
args: config.VolumeBindingArgs{
BindTimeoutSeconds: 10,
@ -586,9 +586,9 @@ func TestValidateVolumeBindingArgs(t *testing.T) {
}}),
},
{
name: "[VolumeCapacityPriority=on] shape should not be empty",
name: "[StorageCapacityScoring=on] shape should not be empty",
features: map[featuregate.Feature]bool{
features.VolumeCapacityPriority: true,
features.StorageCapacityScoring: true,
},
args: config.VolumeBindingArgs{
BindTimeoutSeconds: 10,
@ -600,9 +600,9 @@ func TestValidateVolumeBindingArgs(t *testing.T) {
}}),
},
{
name: "[VolumeCapacityPriority=on] shape points must be sorted in increasing order",
name: "[StorageCapacityScoring=on] shape points must be sorted in increasing order",
features: map[featuregate.Feature]bool{
features.VolumeCapacityPriority: true,
features.StorageCapacityScoring: true,
},
args: config.VolumeBindingArgs{
BindTimeoutSeconds: 10,
@ -618,9 +618,9 @@ func TestValidateVolumeBindingArgs(t *testing.T) {
}}),
},
{
name: "[VolumeCapacityPriority=on] shape point: invalid utilization and score",
name: "[StorageCapacityScoring=on] shape point: invalid utilization and score",
features: map[featuregate.Feature]bool{
features.VolumeCapacityPriority: true,
features.StorageCapacityScoring: true,
},
args: config.VolumeBindingArgs{
BindTimeoutSeconds: 10,

View File

@ -592,7 +592,7 @@ func New(ctx context.Context, plArgs runtime.Object, fh framework.Handle, fts fe
return nil, fmt.Errorf("want args to be of type VolumeBindingArgs, got %T", plArgs)
}
if err := validation.ValidateVolumeBindingArgsWithOptions(nil, args, validation.VolumeBindingArgsValidationOptions{
AllowVolumeCapacityPriority: fts.EnableVolumeCapacityPriority,
AllowStorageCapacityScoring: fts.EnableStorageCapacityScoring,
}); err != nil {
return nil, err
}
@ -610,7 +610,7 @@ func New(ctx context.Context, plArgs runtime.Object, fh framework.Handle, fts fe
// build score function
var scorer volumeCapacityScorer
if fts.EnableVolumeCapacityPriority {
if fts.EnableStorageCapacityScoring {
shape := make(helper.FunctionShape, 0, len(args.Shape))
for _, point := range args.Shape {
shape = append(shape, helper.FunctionShapePoint{

View File

@ -327,7 +327,7 @@ func TestVolumeBinding(t *testing.T) {
withNodeAffinity(map[string][]string{v1.LabelHostname: {"node-b"}}).PersistentVolume,
},
fts: feature.Features{
EnableVolumeCapacityPriority: true,
EnableStorageCapacityScoring: true,
},
wantPreFilterStatus: nil,
wantStateAfterPreFilter: &stateData{
@ -417,7 +417,7 @@ func TestVolumeBinding(t *testing.T) {
withNodeAffinity(map[string][]string{v1.LabelHostname: {"node-b"}}).PersistentVolume,
},
fts: feature.Features{
EnableVolumeCapacityPriority: true,
EnableStorageCapacityScoring: true,
},
wantPreFilterStatus: nil,
wantStateAfterPreFilter: &stateData{
@ -536,7 +536,7 @@ func TestVolumeBinding(t *testing.T) {
}).PersistentVolume,
},
fts: feature.Features{
EnableVolumeCapacityPriority: true,
EnableStorageCapacityScoring: true,
},
wantPreFilterStatus: nil,
wantStateAfterPreFilter: &stateData{
@ -654,7 +654,7 @@ func TestVolumeBinding(t *testing.T) {
}).PersistentVolume,
},
fts: feature.Features{
EnableVolumeCapacityPriority: true,
EnableStorageCapacityScoring: true,
},
args: &config.VolumeBindingArgs{
BindTimeoutSeconds: 300,
@ -750,7 +750,6 @@ func TestVolumeBinding(t *testing.T) {
makeCapacity("node-c", waitSCWithStorageCapacity.Name, makeNode("node-c").withLabel(nodeLabelKey, "node-c").Node, "10Gi", ""),
},
fts: feature.Features{
EnableVolumeCapacityPriority: true,
EnableStorageCapacityScoring: true,
},
wantPreFilterStatus: nil,
@ -807,7 +806,6 @@ func TestVolumeBinding(t *testing.T) {
makeCapacity("node-c", waitSCWithStorageCapacity.Name, makeNode("node-c").withLabel(nodeLabelKey, "node-c").Node, "10Gi", ""),
},
fts: feature.Features{
EnableVolumeCapacityPriority: true,
EnableStorageCapacityScoring: true,
},
wantPreFilterStatus: nil,
@ -863,7 +861,6 @@ func TestVolumeBinding(t *testing.T) {
makeCapacity("node-a", waitSCWithStorageCapacity.Name, makeNode("node-a").withLabel(nodeLabelKey, "node-a").Node, "100Gi", ""),
},
fts: feature.Features{
EnableVolumeCapacityPriority: true,
EnableStorageCapacityScoring: true,
},
wantPreFilterStatus: nil,
@ -902,7 +899,6 @@ func TestVolumeBinding(t *testing.T) {
makeCapacity("node-c", waitSCWithStorageCapacity.Name, makeNode("node-c").withLabel(nodeLabelKey, "node-c").Node, "10Gi", ""),
},
fts: feature.Features{
EnableVolumeCapacityPriority: true,
EnableStorageCapacityScoring: true,
},
wantPreFilterStatus: nil,
@ -944,7 +940,6 @@ func TestVolumeBinding(t *testing.T) {
makeCapacity("node-c", waitSCWithStorageCapacity.Name, makeNode("node-c").withLabel(nodeLabelKey, "node-c").Node, "10Gi", ""),
},
fts: feature.Features{
EnableVolumeCapacityPriority: true,
EnableStorageCapacityScoring: true,
},
args: &config.VolumeBindingArgs{
@ -1006,7 +1001,7 @@ func TestVolumeBinding(t *testing.T) {
args = &config.VolumeBindingArgs{
BindTimeoutSeconds: 300,
}
if item.fts.EnableVolumeCapacityPriority {
if item.fts.EnableStorageCapacityScoring {
args.Shape = defaultShapePoint
}
}

View File

@ -159,17 +159,17 @@ type VolumeBindingArgs struct {
BindTimeoutSeconds *int64 `json:"bindTimeoutSeconds,omitempty"`
// Shape specifies the points defining the score function shape, which is
// used to score nodes based on the utilization of statically provisioned
// PVs. The utilization is calculated by dividing the total requested
// used to score nodes based on the utilization of provisioned PVs.
// The utilization is calculated by dividing the total requested
// storage of the pod by the total capacity of feasible PVs on each node.
// Each point contains utilization (ranges from 0 to 100) and its
// associated score (ranges from 0 to 10). You can turn the priority by
// specifying different scores for different utilization numbers.
// The default shape points are:
// 1) 0 for 0 utilization
// 2) 10 for 100 utilization
// 1) 10 for 0 utilization
// 2) 0 for 100 utilization
// All points must be sorted in increasing order by utilization.
// +featureGate=VolumeCapacityPriority
// +featureGate=StorageCapacityScoring
// +optional
// +listType=atomic
Shape []UtilizationShapePoint `json:"shape,omitempty"`

View File

@ -16,7 +16,7 @@ limitations under the License.
package volumescheduling
// This file tests the VolumeCapacityPriority feature.
// This file tests the StorageCapacityScoring feature.
import (
"context"
@ -46,7 +46,7 @@ func mergeNodeLabels(node *v1.Node, labels map[string]string) *v1.Node {
return node
}
func setupClusterForVolumeCapacityPriority(t *testing.T, nsName string, resyncPeriod time.Duration, provisionDelaySeconds int) *testConfig {
func setupClusterForStorageCapacityScoring(t *testing.T, nsName string, resyncPeriod time.Duration, provisionDelaySeconds int) *testConfig {
testCtx := testutil.InitTestSchedulerWithOptions(t, testutil.InitTestAPIServer(t, nsName, nil), resyncPeriod)
testutil.SyncSchedulerInformerFactory(testCtx)
go testCtx.Scheduler.Run(testCtx.Ctx)
@ -75,10 +75,10 @@ func setupClusterForVolumeCapacityPriority(t *testing.T, nsName string, resyncPe
}
}
func TestVolumeCapacityPriority(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.VolumeCapacityPriority, true)
func TestStorageCapacityScoring(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.StorageCapacityScoring, true)
config := setupClusterForVolumeCapacityPriority(t, "volume-capacity-priority", 0, 0)
config := setupClusterForStorageCapacityScoring(t, "storage-capacity-scoring", 0, 0)
defer config.teardown()
tests := []struct {
@ -90,7 +90,7 @@ func TestVolumeCapacityPriority(t *testing.T) {
wantNodeName string
}{
{
name: "local volumes with close capacity are preferred",
name: "local volumes with max capacity are preferred",
pod: makePod("pod", config.ns, []string{"data"}),
nodes: []*v1.Node{
makeNode(0),
@ -108,10 +108,10 @@ func TestVolumeCapacityPriority(t *testing.T) {
pvcs: []*v1.PersistentVolumeClaim{
setPVCRequestStorage(makePVC("data", config.ns, &waitSSDSC.Name, ""), resource.MustParse("20Gi")),
},
wantNodeName: "node-2",
wantNodeName: "node-0",
},
{
name: "local volumes with close capacity are preferred (multiple pvcs)",
name: "local volumes with max capacity are preferred (multiple pvcs)",
pod: makePod("pod", config.ns, []string{"data-0", "data-1"}),
nodes: []*v1.Node{
makeNode(0),
@ -130,10 +130,10 @@ func TestVolumeCapacityPriority(t *testing.T) {
setPVCRequestStorage(makePVC("data-0", config.ns, &waitSSDSC.Name, ""), resource.MustParse("80Gi")),
setPVCRequestStorage(makePVC("data-1", config.ns, &waitSSDSC.Name, ""), resource.MustParse("80Gi")),
},
wantNodeName: "node-1",
wantNodeName: "node-0",
},
{
name: "local volumes with close capacity are preferred (multiple pvcs, multiple classes)",
name: "local volumes with max capacity are preferred (multiple pvcs, multiple classes)",
pod: makePod("pod", config.ns, []string{"data-0", "data-1"}),
nodes: []*v1.Node{
makeNode(0),
@ -152,10 +152,10 @@ func TestVolumeCapacityPriority(t *testing.T) {
setPVCRequestStorage(makePVC("data-0", config.ns, &waitSSDSC.Name, ""), resource.MustParse("80Gi")),
setPVCRequestStorage(makePVC("data-1", config.ns, &waitHDDSC.Name, ""), resource.MustParse("80Gi")),
},
wantNodeName: "node-1",
wantNodeName: "node-0",
},
{
name: "zonal volumes with close capacity are preferred (multiple pvcs, multiple classes)",
name: "zonal volumes with max capacity are preferred (multiple pvcs, multiple classes)",
pod: makePod("pod", config.ns, []string{"data-0", "data-1"}),
nodes: []*v1.Node{
mergeNodeLabels(makeNode(0), map[string]string{
@ -201,7 +201,7 @@ func TestVolumeCapacityPriority(t *testing.T) {
setPVCRequestStorage(makePVC("data-0", config.ns, &waitSSDSC.Name, ""), resource.MustParse("80Gi")),
setPVCRequestStorage(makePVC("data-1", config.ns, &waitHDDSC.Name, ""), resource.MustParse("80Gi")),
},
wantNodeName: "node-1",
wantNodeName: "node-0",
},
}