return skip

This commit is contained in:
kidddddddddddddddddddddd 2023-01-07 21:25:48 +08:00
parent ca5c522080
commit de7c8db7cb
2 changed files with 57 additions and 57 deletions

View File

@ -98,6 +98,9 @@ func (pl *VolumeZone) PreFilter(ctx context.Context, cs *framework.CycleState, p
if !status.IsSuccess() { if !status.IsSuccess() {
return nil, status return nil, status
} }
if len(podPVTopologies) == 0 {
return nil, framework.NewStatus(framework.Skip)
}
cs.Write(preFilterStateKey, &stateData{podPVTopologies: podPVTopologies}) cs.Write(preFilterStateKey, &stateData{podPVTopologies: podPVTopologies})
return nil, nil return nil, nil
} }
@ -186,11 +189,6 @@ func (pl *VolumeZone) PreFilterExtensions() framework.PreFilterExtensions {
// require calling out to the cloud provider. It seems that we are moving away // require calling out to the cloud provider. It seems that we are moving away
// from inline volume declarations anyway. // from inline volume declarations anyway.
func (pl *VolumeZone) Filter(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status { func (pl *VolumeZone) Filter(ctx context.Context, cs *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
// If a pod doesn't have any volume attached to it, the predicate will always be true.
// Thus we make a fast path for it, to avoid unnecessary computations in this case.
if len(pod.Spec.Volumes) == 0 {
return nil
}
var podPVTopologies []pvTopology var podPVTopologies []pvTopology
state, err := getStateData(cs) state, err := getStateData(cs)
if err != nil { if err != nil {

View File

@ -95,7 +95,8 @@ func TestSingleZone(t *testing.T) {
name string name string
Pod *v1.Pod Pod *v1.Pod
Node *v1.Node Node *v1.Node
wantStatus *framework.Status wantPreFilterStatus *framework.Status
wantFilterStatus *framework.Status
}{ }{
{ {
name: "pod without volume", name: "pod without volume",
@ -106,6 +107,7 @@ func TestSingleZone(t *testing.T) {
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a"}, Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-a"},
}, },
}, },
wantPreFilterStatus: framework.NewStatus(framework.Skip),
}, },
{ {
name: "node without labels", name: "node without labels",
@ -145,7 +147,7 @@ func TestSingleZone(t *testing.T) {
Labels: map[string]string{v1.LabelFailureDomainBetaRegion: "no_us-west1", "uselessLabel": "none"}, Labels: map[string]string{v1.LabelFailureDomainBetaRegion: "no_us-west1", "uselessLabel": "none"},
}, },
}, },
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict), wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict),
}, },
{ {
name: "beta zone label doesn't match", name: "beta zone label doesn't match",
@ -156,7 +158,7 @@ func TestSingleZone(t *testing.T) {
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "no_us-west1-a", "uselessLabel": "none"}, Labels: map[string]string{v1.LabelFailureDomainBetaZone: "no_us-west1-a", "uselessLabel": "none"},
}, },
}, },
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict), wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict),
}, },
{ {
name: "zone label matched", name: "zone label matched",
@ -187,7 +189,7 @@ func TestSingleZone(t *testing.T) {
Labels: map[string]string{v1.LabelTopologyRegion: "no_us-west1", "uselessLabel": "none"}, Labels: map[string]string{v1.LabelTopologyRegion: "no_us-west1", "uselessLabel": "none"},
}, },
}, },
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict), wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict),
}, },
{ {
name: "zone label doesn't match", name: "zone label doesn't match",
@ -198,7 +200,7 @@ func TestSingleZone(t *testing.T) {
Labels: map[string]string{v1.LabelTopologyZone: "no_us-west1-a", "uselessLabel": "none"}, Labels: map[string]string{v1.LabelTopologyZone: "no_us-west1-a", "uselessLabel": "none"},
}, },
}, },
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict), wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict),
}, },
{ {
name: "pv with zone and region, node with only zone", name: "pv with zone and region, node with only zone",
@ -211,7 +213,7 @@ func TestSingleZone(t *testing.T) {
}, },
}, },
}, },
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict), wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict),
}, },
} }
@ -229,14 +231,13 @@ func TestSingleZone(t *testing.T) {
nil, nil,
} }
_, gotPreFilterStatus := p.PreFilter(ctx, state, test.Pod) _, preFilterStatus := p.PreFilter(ctx, state, test.Pod)
if !gotPreFilterStatus.IsSuccess() { if diff := cmp.Diff(preFilterStatus, test.wantPreFilterStatus); diff != "" {
if diff := cmp.Diff(gotPreFilterStatus, test.wantStatus); diff != "" {
t.Errorf("status does not match (-want,+got):\n%s", diff) t.Errorf("status does not match (-want,+got):\n%s", diff)
} }
} else { if preFilterStatus.IsSuccess() {
gotStatus := p.Filter(ctx, state, test.Pod, node) filterStatus := p.Filter(ctx, state, test.Pod, node)
if diff := cmp.Diff(gotStatus, test.wantStatus); diff != "" { if diff := cmp.Diff(filterStatus, test.wantFilterStatus); diff != "" {
t.Errorf("status does not match (-want,+got):\n%s", diff) t.Errorf("status does not match (-want,+got):\n%s", diff)
} }
} }
@ -294,7 +295,8 @@ func TestMultiZone(t *testing.T) {
name string name string
Pod *v1.Pod Pod *v1.Pod
Node *v1.Node Node *v1.Node
wantStatus *framework.Status wantPreFilterStatus *framework.Status
wantFilterStatus *framework.Status
}{ }{
{ {
name: "node without labels", name: "node without labels",
@ -324,7 +326,7 @@ func TestMultiZone(t *testing.T) {
Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-b", "uselessLabel": "none"}, Labels: map[string]string{v1.LabelFailureDomainBetaZone: "us-west1-b", "uselessLabel": "none"},
}, },
}, },
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict), wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict),
}, },
{ {
name: "zone label matched", name: "zone label matched",
@ -345,7 +347,7 @@ func TestMultiZone(t *testing.T) {
Labels: map[string]string{v1.LabelTopologyZone: "us-west1-b", "uselessLabel": "none"}, Labels: map[string]string{v1.LabelTopologyZone: "us-west1-b", "uselessLabel": "none"},
}, },
}, },
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict), wantFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonConflict),
}, },
} }
@ -362,14 +364,13 @@ func TestMultiZone(t *testing.T) {
pvcLister, pvcLister,
nil, nil,
} }
_, gotPreFilterStatus := p.PreFilter(ctx, state, test.Pod) _, preFilterStatus := p.PreFilter(ctx, state, test.Pod)
if !gotPreFilterStatus.IsSuccess() { if diff := cmp.Diff(preFilterStatus, test.wantPreFilterStatus); diff != "" {
if diff := cmp.Diff(gotPreFilterStatus, test.wantStatus); diff != "" {
t.Errorf("status does not match (-want,+got):\n%s", diff) t.Errorf("status does not match (-want,+got):\n%s", diff)
} }
} else { if preFilterStatus.IsSuccess() {
gotStatus := p.Filter(context.Background(), state, test.Pod, node) filterStatus := p.Filter(context.Background(), state, test.Pod, node)
if diff := cmp.Diff(gotStatus, test.wantStatus); diff != "" { if diff := cmp.Diff(filterStatus, test.wantFilterStatus); diff != "" {
t.Errorf("status does not match (-want,+got):\n%s", diff) t.Errorf("status does not match (-want,+got):\n%s", diff)
} }
} }
@ -435,7 +436,8 @@ func TestWithBinding(t *testing.T) {
name string name string
Pod *v1.Pod Pod *v1.Pod
Node *v1.Node Node *v1.Node
wantStatus *framework.Status wantPreFilterStatus *framework.Status
wantFilterStatus *framework.Status
}{ }{
{ {
name: "label zone failure domain matched", name: "label zone failure domain matched",
@ -446,26 +448,27 @@ func TestWithBinding(t *testing.T) {
name: "unbound volume empty storage class", name: "unbound volume empty storage class",
Pod: createPodWithVolume("pod_1", "vol_1", "PVC_EmptySC"), Pod: createPodWithVolume("pod_1", "vol_1", "PVC_EmptySC"),
Node: testNode, Node: testNode,
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, wantPreFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable,
"PersistentVolumeClaim had no pv name and storageClass name"), "PersistentVolumeClaim had no pv name and storageClass name"),
}, },
{ {
name: "unbound volume no storage class", name: "unbound volume no storage class",
Pod: createPodWithVolume("pod_1", "vol_1", "PVC_NoSC"), Pod: createPodWithVolume("pod_1", "vol_1", "PVC_NoSC"),
Node: testNode, Node: testNode,
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, wantPreFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable,
"unable to find storage class: Class_0"), "unable to find storage class: Class_0"),
}, },
{ {
name: "unbound volume immediate binding mode", name: "unbound volume immediate binding mode",
Pod: createPodWithVolume("pod_1", "vol_1", "PVC_ImmediateSC"), Pod: createPodWithVolume("pod_1", "vol_1", "PVC_ImmediateSC"),
Node: testNode, Node: testNode,
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, "VolumeBindingMode not set for StorageClass \"Class_Immediate\""), wantPreFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, "VolumeBindingMode not set for StorageClass \"Class_Immediate\""),
}, },
{ {
name: "unbound volume wait binding mode", name: "unbound volume wait binding mode",
Pod: createPodWithVolume("pod_1", "vol_1", "PVC_WaitSC"), Pod: createPodWithVolume("pod_1", "vol_1", "PVC_WaitSC"),
Node: testNode, Node: testNode,
wantPreFilterStatus: framework.NewStatus(framework.Skip),
}, },
} }
@ -482,14 +485,13 @@ func TestWithBinding(t *testing.T) {
pvcLister, pvcLister,
scLister, scLister,
} }
_, gotPreFilterStatus := p.PreFilter(ctx, state, test.Pod) _, preFilterStatus := p.PreFilter(ctx, state, test.Pod)
if !gotPreFilterStatus.IsSuccess() { if diff := cmp.Diff(preFilterStatus, test.wantPreFilterStatus); diff != "" {
if diff := cmp.Diff(gotPreFilterStatus, test.wantStatus); diff != "" {
t.Errorf("status does not match (-want,+got):\n%s", diff) t.Errorf("status does not match (-want,+got):\n%s", diff)
} }
} else { if preFilterStatus.IsSuccess() {
gotStatus := p.Filter(ctx, state, test.Pod, node) filterStatus := p.Filter(ctx, state, test.Pod, node)
if diff := cmp.Diff(gotStatus, test.wantStatus); diff != "" { if diff := cmp.Diff(filterStatus, test.wantFilterStatus); diff != "" {
t.Errorf("status does not match (-want,+got):\n%s", diff) t.Errorf("status does not match (-want,+got):\n%s", diff)
} }
} }