mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-20 00:15:11 +00:00
pvc
This commit is contained in:
@@ -541,244 +541,6 @@ func TestWithBinding(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsSchedulableAfterStorageClassAdded(t *testing.T) {
|
||||
var modeWait = storagev1.VolumeBindingWaitForFirstConsumer
|
||||
pvLister := tf.PersistentVolumeLister{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "Vol_1", Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a"}},
|
||||
},
|
||||
}
|
||||
|
||||
pvcLister := tf.PersistentVolumeClaimLister{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "PVC_1", Namespace: "default"},
|
||||
Spec: v1.PersistentVolumeClaimSpec{VolumeName: "Vol_1"},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "PVC_2", Namespace: "default"},
|
||||
Spec: v1.PersistentVolumeClaimSpec{StorageClassName: ptr.To("SC_2")},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "PVC_3", Namespace: "default"},
|
||||
Spec: v1.PersistentVolumeClaimSpec{StorageClassName: ptr.To("SC_3")},
|
||||
},
|
||||
}
|
||||
|
||||
scLister := tf.StorageClassLister{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "SC_1", Namespace: "default"},
|
||||
},
|
||||
}
|
||||
|
||||
testcases := map[string]struct {
|
||||
pod *v1.Pod
|
||||
oldObj, newObj interface{}
|
||||
expectedHint framework.QueueingHint
|
||||
expectedErr bool
|
||||
}{
|
||||
"backoff-wrong-new-object": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
newObj: "not-a-storageclass",
|
||||
expectedHint: framework.Queue,
|
||||
expectedErr: true,
|
||||
},
|
||||
"pvc-was-not-bound-to-sc": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
newObj: &storagev1.StorageClass{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "SC_1"},
|
||||
},
|
||||
expectedHint: framework.QueueSkip,
|
||||
},
|
||||
"pvc-was-bound-to-different-sc": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_2"),
|
||||
newObj: &storagev1.StorageClass{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "SC_1"},
|
||||
},
|
||||
expectedHint: framework.QueueSkip,
|
||||
},
|
||||
"pvc-was-bound-to-added-sc-but-not-wait-mode": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_3"),
|
||||
newObj: &storagev1.StorageClass{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "SC_3"},
|
||||
},
|
||||
expectedHint: framework.QueueSkip,
|
||||
},
|
||||
"pvc-was-bound-to-added-sc-and-wait-mode": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_3"),
|
||||
newObj: &storagev1.StorageClass{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "SC_3"},
|
||||
VolumeBindingMode: &modeWait,
|
||||
},
|
||||
expectedHint: framework.Queue,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testcases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
logger, _ := ktesting.NewTestContext(t)
|
||||
p := &VolumeZone{
|
||||
pvLister,
|
||||
pvcLister,
|
||||
scLister,
|
||||
}
|
||||
|
||||
got, err := p.isSchedulableAfterStorageClassAdded(logger, tc.pod, tc.oldObj, tc.newObj)
|
||||
if err != nil && !tc.expectedErr {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if got != tc.expectedHint {
|
||||
t.Errorf("isSchedulableAfterStorageClassAdded() = %v, want %v", got, tc.expectedHint)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsSchedulableAfterNodeChange(t *testing.T) {
|
||||
pvLister := tf.PersistentVolumeLister{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "Vol_1", Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a"}},
|
||||
},
|
||||
}
|
||||
|
||||
pvcLister := tf.PersistentVolumeClaimLister{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "PVC_1", Namespace: "default"},
|
||||
Spec: v1.PersistentVolumeClaimSpec{VolumeName: "Vol_1"},
|
||||
},
|
||||
}
|
||||
|
||||
testcases := map[string]struct {
|
||||
pod *v1.Pod
|
||||
oldObj, newObj interface{}
|
||||
expectedHint framework.QueueingHint
|
||||
expectedErr bool
|
||||
}{
|
||||
"backoff-wrong-new-object": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
newObj: "not-a-node",
|
||||
expectedHint: framework.Queue,
|
||||
expectedErr: true,
|
||||
},
|
||||
"backoff-wrong-old-object": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
oldObj: "not-a-node",
|
||||
newObj: st.MakeNode().Obj(),
|
||||
expectedHint: framework.Queue,
|
||||
expectedErr: true,
|
||||
},
|
||||
"pvcName-is-null-and-getPVbyPod-return-unschedulable": {
|
||||
pod: createPodWithVolume("pod_1", ""),
|
||||
oldObj: st.MakeNode().Obj(),
|
||||
newObj: st.MakeNode().Obj(),
|
||||
expectedHint: framework.Queue,
|
||||
expectedErr: true,
|
||||
},
|
||||
"new-node-was-added-and-matched-labels": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
newObj: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "host1",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a"},
|
||||
},
|
||||
},
|
||||
expectedHint: framework.Queue,
|
||||
},
|
||||
"new-node-was-added-but-didn't-match-key": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
newObj: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "host1",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-b"},
|
||||
},
|
||||
},
|
||||
expectedHint: framework.QueueSkip,
|
||||
},
|
||||
"non-match-node-was-updated-and-matched-labels": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
oldObj: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "host1",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-b"},
|
||||
},
|
||||
},
|
||||
newObj: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "host1",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a"},
|
||||
},
|
||||
},
|
||||
expectedHint: framework.Queue,
|
||||
},
|
||||
"non-match-node-was-updated-but-didn't-match-key": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
oldObj: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "host1",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-b"},
|
||||
},
|
||||
},
|
||||
newObj: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "host1",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-c"},
|
||||
},
|
||||
},
|
||||
expectedHint: framework.QueueSkip,
|
||||
},
|
||||
"matched-node-was-updated-and-matched-labels": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
oldObj: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "host1",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a"},
|
||||
},
|
||||
},
|
||||
newObj: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "host1",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a"},
|
||||
},
|
||||
},
|
||||
expectedHint: framework.QueueSkip,
|
||||
},
|
||||
"matched-node-was-updated-but-didn't-match-key": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
oldObj: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "host1",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a"},
|
||||
},
|
||||
},
|
||||
newObj: &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "host1",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-b"},
|
||||
},
|
||||
},
|
||||
expectedHint: framework.QueueSkip,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testcases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
logger, _ := ktesting.NewTestContext(t)
|
||||
p := &VolumeZone{
|
||||
pvLister,
|
||||
pvcLister,
|
||||
nil,
|
||||
}
|
||||
|
||||
got, err := p.isSchedulableAfterNodeChange(logger, tc.pod, tc.oldObj, tc.newObj)
|
||||
if err != nil && !tc.expectedErr {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if got != tc.expectedHint {
|
||||
t.Errorf("isSchedulableAfterNodeChange() = %v, want %v", got, tc.expectedHint)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsSchedulableAfterPersistentVolumeClaimAdded(t *testing.T) {
|
||||
var modeWait = storagev1.VolumeBindingWaitForFirstConsumer
|
||||
pvLister := tf.PersistentVolumeLister{
|
||||
@@ -930,151 +692,6 @@ func TestIsSchedulableAfterPersistentVolumeClaimAdded(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsSchedulableAfterPersistentVolumeChange(t *testing.T) {
|
||||
pvLister := tf.PersistentVolumeLister{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "Vol_2", Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-b"}},
|
||||
},
|
||||
}
|
||||
|
||||
pvcLister := tf.PersistentVolumeClaimLister{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "PVC_1", Namespace: "default"},
|
||||
Spec: v1.PersistentVolumeClaimSpec{VolumeName: "Vol_1"},
|
||||
},
|
||||
}
|
||||
|
||||
testcases := map[string]struct {
|
||||
pod *v1.Pod
|
||||
oldObj, newObj interface{}
|
||||
expectedHint framework.QueueingHint
|
||||
expectedErr bool
|
||||
}{
|
||||
"backoff-wrong-new-object": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
newObj: "not-a-pv",
|
||||
expectedHint: framework.Queue,
|
||||
expectedErr: true,
|
||||
},
|
||||
"backoff-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,
|
||||
},
|
||||
"pv-was-added-but-pod's-pvcName-is-null": {
|
||||
pod: st.MakePod().Name("pod_1").Namespace("default").Obj(),
|
||||
newObj: &v1.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "Vol_1",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-b"},
|
||||
},
|
||||
},
|
||||
expectedHint: framework.QueueSkip,
|
||||
},
|
||||
"new-pv-was-added-and-bound-to-pod's-pvc": {
|
||||
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,
|
||||
},
|
||||
"new-pv-was-added-and-bound-to-pod's-pvc-but-doesn't-have-labels": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
newObj: &v1.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "Vol_1",
|
||||
},
|
||||
},
|
||||
expectedHint: framework.QueueSkip,
|
||||
},
|
||||
"new-pv-was-added-but-not-bound-to-pod's-pvc": {
|
||||
pod: createPodWithVolume("pod_1", "PVC_1"),
|
||||
newObj: &v1.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "Vol_2",
|
||||
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-b"},
|
||||
},
|
||||
},
|
||||
expectedHint: framework.QueueSkip,
|
||||
},
|
||||
"pv-was-updated-and-changed-key": {
|
||||
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-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-and-changed-labels-order": {
|
||||
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.LabelTopologyZone: "zone",
|
||||
v1.LabelFailureDomainBetaZone: "us-west1-a"},
|
||||
},
|
||||
},
|
||||
expectedHint: framework.QueueSkip,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testcases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
logger, _ := ktesting.NewTestContext(t)
|
||||
p := &VolumeZone{
|
||||
pvLister,
|
||||
pvcLister,
|
||||
nil,
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user