Skip to content

Commit

Permalink
Return UnschedulableAndUnresolvable instead of Error when failing to …
Browse files Browse the repository at this point in the history
…lookup pvc or storageclass in VolumeZone plugin
  • Loading branch information
ahg-g committed Jun 2, 2021
1 parent 5f6b1fa commit e160aa0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
26 changes: 9 additions & 17 deletions pkg/scheduler/framework/plugins/volumezone/volume_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,47 +108,39 @@ func (pl *VolumeZone) Filter(ctx context.Context, _ *framework.CycleState, pod *
}
pvcName := volume.PersistentVolumeClaim.ClaimName
if pvcName == "" {
return framework.NewStatus(framework.Error, "PersistentVolumeClaim had no name")
return framework.NewStatus(framework.UnschedulableAndUnresolvable, "PersistentVolumeClaim had no name")
}
pvc, err := pl.pvcLister.PersistentVolumeClaims(pod.Namespace).Get(pvcName)
if err != nil {
return framework.NewStatus(framework.Error, err.Error())
}

if pvc == nil {
return framework.NewStatus(framework.Error, fmt.Sprintf("PersistentVolumeClaim was not found: %q", pvcName))
return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error())
}

pvName := pvc.Spec.VolumeName
if pvName == "" {
scName := v1helper.GetPersistentVolumeClaimClass(pvc)
if len(scName) == 0 {
return framework.NewStatus(framework.Error, fmt.Sprint("PersistentVolumeClaim had no pv name and storageClass name"))
return framework.NewStatus(framework.UnschedulableAndUnresolvable, "PersistentVolumeClaim had no pv name and storageClass name")
}

class, _ := pl.scLister.Get(scName)
if class == nil {
return framework.NewStatus(framework.Error, fmt.Sprintf("StorageClass %q claimed by PersistentVolumeClaim %q not found", scName, pvcName))
class, err := pl.scLister.Get(scName)
if err != nil {
return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error())

}
if class.VolumeBindingMode == nil {
return framework.NewStatus(framework.Error, fmt.Sprintf("VolumeBindingMode not set for StorageClass %q", scName))
return framework.NewStatus(framework.UnschedulableAndUnresolvable, fmt.Sprintf("VolumeBindingMode not set for StorageClass %q", scName))
}
if *class.VolumeBindingMode == storage.VolumeBindingWaitForFirstConsumer {
// Skip unbound volumes
continue
}

return framework.NewStatus(framework.Error, fmt.Sprint("PersistentVolume had no name"))
return framework.NewStatus(framework.UnschedulableAndUnresolvable, "PersistentVolume had no name")
}

pv, err := pl.pvLister.Get(pvName)
if err != nil {
return framework.NewStatus(framework.Error, err.Error())
}

if pv == nil {
return framework.NewStatus(framework.Error, fmt.Sprintf("PersistentVolume was not found: %q", pvName))
return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error())
}

for k, v := range pv.ObjectMeta.Labels {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,21 +413,21 @@ func TestWithBinding(t *testing.T) {
name: "unbound volume empty storage class",
Pod: createPodWithVolume("pod_1", "vol_1", "PVC_EmptySC"),
Node: testNode,
wantStatus: framework.NewStatus(framework.Error,
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable,
"PersistentVolumeClaim had no pv name and storageClass name"),
},
{
name: "unbound volume no storage class",
Pod: createPodWithVolume("pod_1", "vol_1", "PVC_NoSC"),
Node: testNode,
wantStatus: framework.NewStatus(framework.Error,
"StorageClass \"Class_0\" claimed by PersistentVolumeClaim \"PVC_NoSC\" not found"),
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable,
"unable to find storage class: Class_0"),
},
{
name: "unbound volume immediate binding mode",
Pod: createPodWithVolume("pod_1", "vol_1", "PVC_ImmediateSC"),
Node: testNode,
wantStatus: framework.NewStatus(framework.Error, "VolumeBindingMode not set for StorageClass \"Class_Immediate\""),
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, "VolumeBindingMode not set for StorageClass \"Class_Immediate\""),
},
{
name: "unbound volume wait binding mode",
Expand Down

0 comments on commit e160aa0

Please sign in to comment.