mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #102306 from ahg-g/ahg-vol-restrictions
Return UnschedulableAndUnresolvable instead of Error when failing to lookup volume-related resources
This commit is contained in:
commit
ae1f28d7b0
@ -109,39 +109,39 @@ func (pl *VolumeZone) Filter(ctx context.Context, _ *framework.CycleState, pod *
|
|||||||
}
|
}
|
||||||
pvcName := volume.PersistentVolumeClaim.ClaimName
|
pvcName := volume.PersistentVolumeClaim.ClaimName
|
||||||
if pvcName == "" {
|
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)
|
pvc, err := pl.pvcLister.PersistentVolumeClaims(pod.Namespace).Get(pvcName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return framework.AsStatus(err)
|
return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
pvName := pvc.Spec.VolumeName
|
pvName := pvc.Spec.VolumeName
|
||||||
if pvName == "" {
|
if pvName == "" {
|
||||||
scName := storagehelpers.GetPersistentVolumeClaimClass(pvc)
|
scName := storagehelpers.GetPersistentVolumeClaimClass(pvc)
|
||||||
if len(scName) == 0 {
|
if len(scName) == 0 {
|
||||||
return framework.NewStatus(framework.Error, "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)
|
class, err := pl.scLister.Get(scName)
|
||||||
if class == nil {
|
if err != nil {
|
||||||
return framework.NewStatus(framework.Error, fmt.Sprintf("StorageClass %q claimed by PersistentVolumeClaim %q not found", scName, pvcName))
|
return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error())
|
||||||
|
|
||||||
}
|
}
|
||||||
if class.VolumeBindingMode == nil {
|
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 {
|
if *class.VolumeBindingMode == storage.VolumeBindingWaitForFirstConsumer {
|
||||||
// Skip unbound volumes
|
// Skip unbound volumes
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
return framework.NewStatus(framework.Error, "PersistentVolume had no name")
|
return framework.NewStatus(framework.UnschedulableAndUnresolvable, "PersistentVolume had no name")
|
||||||
}
|
}
|
||||||
|
|
||||||
pv, err := pl.pvLister.Get(pvName)
|
pv, err := pl.pvLister.Get(pvName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return framework.AsStatus(err)
|
return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range pv.ObjectMeta.Labels {
|
for k, v := range pv.ObjectMeta.Labels {
|
||||||
|
@ -413,21 +413,21 @@ 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.Error,
|
wantStatus: 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.Error,
|
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable,
|
||||||
"StorageClass \"Class_0\" claimed by PersistentVolumeClaim \"PVC_NoSC\" not found"),
|
"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.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",
|
name: "unbound volume wait binding mode",
|
||||||
|
Loading…
Reference in New Issue
Block a user