From b8fe514232f4c8dc96521c515d7a90116cff90cb Mon Sep 17 00:00:00 2001 From: Yibo Zhuang Date: Thu, 30 Sep 2021 21:49:46 -0700 Subject: [PATCH] Scheduler volumebinding plugin - handle Lost PVC as UnschedulableAndUnresolvable This change adds an additional check in the volumebinding scheduler plugin to handle PVC with phase ClaimLost which will allow the scheduler to return UnschedulableAndUnresolvable during the PreFilter stage and skip the rest of the node evaluation since the PVC is bound to a PV that does not exist. Without this change, the FailedScheduling error message would look like: 0/10 nodes are available: 2 node(s) had taint {node/test: true}, that the pod didn't tolerate, 6 node(s) had taint {node/unhealthy: true}, that the pod didn't tolerate, 2 pvc(s) bound to non-existent pv(s) Which is still evaluating every single node to determine that the pod cannot be scheduled because the PVC is bound to a non-existent PV With this change, the FailedScheduling error message would look like: 0/10 nodes are available: 1 persistentvolumeclaim "foo" bound to non-existent persistentvolume "bar" Signed-off By: Yibo Zhuang --- .../plugins/volumebinding/test_utils.go | 7 +++++++ .../plugins/volumebinding/volume_binding.go | 4 ++++ .../volumebinding/volume_binding_test.go | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/pkg/scheduler/framework/plugins/volumebinding/test_utils.go b/pkg/scheduler/framework/plugins/volumebinding/test_utils.go index bd5bc4a1c52..ff759d3d8c5 100644 --- a/pkg/scheduler/framework/plugins/volumebinding/test_utils.go +++ b/pkg/scheduler/framework/plugins/volumebinding/test_utils.go @@ -135,6 +135,13 @@ func (pvcb pvcBuilder) withRequestStorage(request resource.Quantity) pvcBuilder return pvcb } +func (pvcb pvcBuilder) withPhase(phase v1.PersistentVolumeClaimPhase) pvcBuilder { + pvcb.PersistentVolumeClaim.Status = v1.PersistentVolumeClaimStatus{ + Phase: phase, + } + return pvcb +} + type podBuilder struct { *v1.Pod } diff --git a/pkg/scheduler/framework/plugins/volumebinding/volume_binding.go b/pkg/scheduler/framework/plugins/volumebinding/volume_binding.go index 90511dda5ab..349294aae71 100644 --- a/pkg/scheduler/framework/plugins/volumebinding/volume_binding.go +++ b/pkg/scheduler/framework/plugins/volumebinding/volume_binding.go @@ -150,6 +150,10 @@ func (pl *VolumeBinding) podHasPVCs(pod *v1.Pod) (bool, error) { return hasPVC, err } + if pvc.Status.Phase == v1.ClaimLost { + return hasPVC, fmt.Errorf("persistentvolumeclaim %q bound to non-existent persistentvolume %q", pvc.Name, pvc.Spec.VolumeName) + } + if pvc.DeletionTimestamp != nil { return hasPVC, fmt.Errorf("persistentvolumeclaim %q is being deleted", pvc.Name) } diff --git a/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go b/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go index caf22c72a89..51d5425f9e9 100644 --- a/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go +++ b/pkg/scheduler/framework/plugins/volumebinding/volume_binding_test.go @@ -266,6 +266,23 @@ func TestVolumeBinding(t *testing.T) { 0, }, }, + { + name: "pv not found claim lost", + pod: makePod("pod-a").withPVCVolume("pvc-a", "").Pod, + nodes: []*v1.Node{ + makeNode("node-a").Node, + }, + pvcs: []*v1.PersistentVolumeClaim{ + makePVC("pvc-a", waitSC.Name).withBoundPV("pv-a").withPhase(v1.ClaimLost).PersistentVolumeClaim, + }, + wantPreFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, `persistentvolumeclaim "pvc-a" bound to non-existent persistentvolume "pv-a"`), + wantFilterStatus: []*framework.Status{ + nil, + }, + wantScores: []int64{ + 0, + }, + }, { name: "local volumes with close capacity are preferred", pod: makePod("pod-a").withPVCVolume("pvc-a", "").Pod,