mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #84611 from cwdsuzhou/Nov/simplyfy_zone_checker
Simplify volume zone checker codes
This commit is contained in:
commit
9fad2e3201
@ -667,7 +667,9 @@ func (c *VolumeZoneChecker) predicate(pod *v1.Pod, meta Metadata, nodeInfo *sche
|
||||
manifest := &(pod.Spec)
|
||||
for i := range manifest.Volumes {
|
||||
volume := &manifest.Volumes[i]
|
||||
if volume.PersistentVolumeClaim != nil {
|
||||
if volume.PersistentVolumeClaim == nil {
|
||||
continue
|
||||
}
|
||||
pvcName := volume.PersistentVolumeClaim.ClaimName
|
||||
if pvcName == "" {
|
||||
return false, nil, fmt.Errorf("PersistentVolumeClaim had no name")
|
||||
@ -684,9 +686,16 @@ func (c *VolumeZoneChecker) predicate(pod *v1.Pod, meta Metadata, nodeInfo *sche
|
||||
pvName := pvc.Spec.VolumeName
|
||||
if pvName == "" {
|
||||
scName := v1helper.GetPersistentVolumeClaimClass(pvc)
|
||||
if len(scName) > 0 {
|
||||
if len(scName) == 0 {
|
||||
return false, nil, fmt.Errorf("PersistentVolumeClaim had no pv name and storageClass name")
|
||||
}
|
||||
|
||||
class, _ := c.scLister.Get(scName)
|
||||
if class != nil {
|
||||
if class == nil {
|
||||
return false, nil, fmt.Errorf("StorageClass %q claimed by PersistentVolumeClaim %q not found",
|
||||
scName, pvcName)
|
||||
|
||||
}
|
||||
if class.VolumeBindingMode == nil {
|
||||
return false, nil, fmt.Errorf("VolumeBindingMode not set for StorageClass %q", scName)
|
||||
}
|
||||
@ -694,9 +703,8 @@ func (c *VolumeZoneChecker) predicate(pod *v1.Pod, meta Metadata, nodeInfo *sche
|
||||
// Skip unbound volumes
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil, fmt.Errorf("PersistentVolumeClaim was not found: %q", pvcName)
|
||||
|
||||
return false, nil, fmt.Errorf("PersistentVolume had no name")
|
||||
}
|
||||
|
||||
pv, err := c.pvLister.Get(pvName)
|
||||
@ -725,7 +733,6 @@ func (c *VolumeZoneChecker) predicate(pod *v1.Pod, meta Metadata, nodeInfo *sche
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil, nil
|
||||
}
|
||||
|
@ -320,13 +320,15 @@ 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, "PersistentVolumeClaim was not found: \"PVC_EmptySC\""),
|
||||
wantStatus: framework.NewStatus(framework.Error,
|
||||
"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, "PersistentVolumeClaim was not found: \"PVC_NoSC\""),
|
||||
wantStatus: framework.NewStatus(framework.Error,
|
||||
"StorageClass \"Class_0\" claimed by PersistentVolumeClaim \"PVC_NoSC\" not found"),
|
||||
},
|
||||
{
|
||||
name: "unbound volume immediate binding mode",
|
||||
|
Loading…
Reference in New Issue
Block a user