volumezone: scheduler queueing hints: pv (#125001)

* volumezone: scheduler queueing hints

* add_comment
This commit is contained in:
Hiroyuki Moriya
2024-07-12 21:14:27 +09:00
committed by GitHub
parent a39f42582f
commit 52a622ad6d
2 changed files with 148 additions and 16 deletions

View File

@@ -675,6 +675,105 @@ func TestIsSchedulableAfterStorageClassAdded(t *testing.T) {
}
}
func TestIsSchedulableAfterPersistentVolumeChange(t *testing.T) {
testcases := map[string]struct {
pod *v1.Pod
oldObj, newObj interface{}
expectedHint framework.QueueingHint
expectedErr bool
}{
"error-wrong-new-object": {
pod: createPodWithVolume("pod_1", "PVC_1"),
newObj: "not-a-pv",
expectedHint: framework.Queue,
expectedErr: true,
},
"error-wrong-old-object": {
pod: createPodWithVolume("pod_1", "PVC_1"),
oldObj: "not-a-pv",
newObj: st.MakePersistentVolume().Name("Vol_1").Obj(),
expectedHint: framework.Queue,
expectedErr: true,
},
"new-pv-was-added": {
pod: createPodWithVolume("pod_1", "PVC_1"),
newObj: &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: "Vol_1",
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-b"},
},
},
expectedHint: framework.Queue,
},
"pv-was-updated-and-changed-topology": {
pod: createPodWithVolume("pod_1", "PVC_1"),
oldObj: &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: "Vol_1",
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a"},
},
},
newObj: &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: "Vol_1",
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-b"},
},
},
expectedHint: framework.Queue,
},
"pv-was-updated-and-added-topology-label": {
pod: createPodWithVolume("pod_1", "PVC_1"),
oldObj: &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: "Vol_1",
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a"},
},
},
newObj: &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: "Vol_1",
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a",
v1.LabelTopologyZone: "zone"},
},
},
expectedHint: framework.Queue,
},
"pv-was-updated-but-no-topology-is-changed": {
pod: createPodWithVolume("pod_1", "PVC_1"),
oldObj: &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: "Vol_1",
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a",
v1.LabelTopologyZone: "zone"},
},
},
newObj: &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: "Vol_1",
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a",
v1.LabelTopologyZone: "zone"},
},
},
expectedHint: framework.QueueSkip,
},
}
for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
logger, _ := ktesting.NewTestContext(t)
p := &VolumeZone{}
got, err := p.isSchedulableAfterPersistentVolumeChange(logger, tc.pod, tc.oldObj, tc.newObj)
if err != nil && !tc.expectedErr {
t.Errorf("unexpected error: %v", err)
}
if got != tc.expectedHint {
t.Errorf("isSchedulableAfterPersistentVolumeChange() = %v, want %v", got, tc.expectedHint)
}
})
}
}
func BenchmarkVolumeZone(b *testing.B) {
tests := []struct {
Name string