volumebinding: scheduler queueing hints - CSIStorageCapacity (#124961)

* volumebinding: scheduler queueing hints - CSIStorageCapacity

* Fixed points mentioned in the review

* Fixed points mentioned in the review

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

Co-authored-by: Kensei Nakada <handbomusic@gmail.com>

* Update pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go

Co-authored-by: Kensei Nakada <handbomusic@gmail.com>

* Fixed points mentioned in the review

* volume_binding.go を更新

Co-authored-by: Kensei Nakada <handbomusic@gmail.com>

---------

Co-authored-by: Kensei Nakada <handbomusic@gmail.com>
This commit is contained in:
bells17
2024-07-19 23:53:52 +09:00
committed by GitHub
parent 01eb9f4754
commit e1aa8197ed
3 changed files with 279 additions and 4 deletions

View File

@@ -1181,3 +1181,232 @@ func TestIsSchedulableAfterStorageClassChange(t *testing.T) {
})
}
}
func TestIsSchedulableAfterCSIStorageCapacityChange(t *testing.T) {
table := []struct {
name string
pod *v1.Pod
oldCap interface{}
newCap interface{}
wantErr bool
expect framework.QueueingHint
}{
{
name: "When a new CSIStorageCapacity is created, it returns Queue",
pod: makePod("pod-a").Pod,
oldCap: nil,
newCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
},
wantErr: false,
expect: framework.Queue,
},
{
name: "When the volume limit is increase(Capacity set), it returns Queue",
pod: makePod("pod-a").Pod,
oldCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
},
newCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
},
wantErr: false,
expect: framework.Queue,
},
{
name: "When the volume limit is increase(MaximumVolumeSize set), it returns Queue",
pod: makePod("pod-a").Pod,
oldCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
},
newCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
MaximumVolumeSize: resource.NewQuantity(100, resource.DecimalSI),
},
wantErr: false,
expect: framework.Queue,
},
{
name: "When the volume limit is increase(Capacity increase), it returns Queue",
pod: makePod("pod-a").Pod,
oldCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(50, resource.DecimalSI),
},
newCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
},
wantErr: false,
expect: framework.Queue,
},
{
name: "When the volume limit is increase(MaximumVolumeSize unset), it returns Queue",
pod: makePod("pod-a").Pod,
oldCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
MaximumVolumeSize: resource.NewQuantity(50, resource.DecimalSI),
},
newCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
},
wantErr: false,
expect: framework.Queue,
},
{
name: "When the volume limit is increase(MaximumVolumeSize increase), it returns Queue",
pod: makePod("pod-a").Pod,
oldCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
MaximumVolumeSize: resource.NewQuantity(50, resource.DecimalSI),
},
newCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
MaximumVolumeSize: resource.NewQuantity(60, resource.DecimalSI),
},
wantErr: false,
expect: framework.Queue,
},
{
name: "When there are no changes to the CSIStorageCapacity, it returns QueueSkip",
pod: makePod("pod-a").Pod,
oldCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
MaximumVolumeSize: resource.NewQuantity(50, resource.DecimalSI),
},
newCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
MaximumVolumeSize: resource.NewQuantity(50, resource.DecimalSI),
},
wantErr: false,
expect: framework.QueueSkip,
},
{
name: "When the volume limit is equal(Capacity), it returns QueueSkip",
pod: makePod("pod-a").Pod,
oldCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
},
newCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
},
wantErr: false,
expect: framework.QueueSkip,
},
{
name: "When the volume limit is equal(MaximumVolumeSize unset), it returns QueueSkip",
pod: makePod("pod-a").Pod,
oldCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
MaximumVolumeSize: resource.NewQuantity(50, resource.DecimalSI),
},
newCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(50, resource.DecimalSI),
},
wantErr: false,
expect: framework.QueueSkip,
},
{
name: "When the volume limit is decrease(Capacity), it returns QueueSkip",
pod: makePod("pod-a").Pod,
oldCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(100, resource.DecimalSI),
},
newCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
Capacity: resource.NewQuantity(90, resource.DecimalSI),
},
wantErr: false,
expect: framework.QueueSkip,
},
{
name: "When the volume limit is decrease(MaximumVolumeSize), it returns QueueSkip",
pod: makePod("pod-a").Pod,
oldCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
MaximumVolumeSize: resource.NewQuantity(100, resource.DecimalSI),
},
newCap: &storagev1.CSIStorageCapacity{
ObjectMeta: metav1.ObjectMeta{
Name: "cap-a",
},
MaximumVolumeSize: resource.NewQuantity(90, resource.DecimalSI),
},
wantErr: false,
expect: framework.QueueSkip,
},
{
name: "type conversion error",
oldCap: new(struct{}),
newCap: new(struct{}),
wantErr: true,
expect: framework.Queue,
},
}
for _, item := range table {
t.Run(item.name, func(t *testing.T) {
pl := &VolumeBinding{}
logger, _ := ktesting.NewTestContext(t)
qhint, err := pl.isSchedulableAfterCSIStorageCapacityChange(logger, item.pod, item.oldCap, item.newCap)
if (err != nil) != item.wantErr {
t.Errorf("error is unexpectedly returned or not returned from isSchedulableAfterCSIStorageCapacityChange. wantErr: %v actual error: %q", item.wantErr, err)
}
if qhint != item.expect {
t.Errorf("QHint does not match: %v, want: %v", qhint, item.expect)
}
})
}
}