mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +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)
|
manifest := &(pod.Spec)
|
||||||
for i := range manifest.Volumes {
|
for i := range manifest.Volumes {
|
||||||
volume := &manifest.Volumes[i]
|
volume := &manifest.Volumes[i]
|
||||||
if volume.PersistentVolumeClaim != nil {
|
if volume.PersistentVolumeClaim == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
pvcName := volume.PersistentVolumeClaim.ClaimName
|
pvcName := volume.PersistentVolumeClaim.ClaimName
|
||||||
if pvcName == "" {
|
if pvcName == "" {
|
||||||
return false, nil, fmt.Errorf("PersistentVolumeClaim had no name")
|
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
|
pvName := pvc.Spec.VolumeName
|
||||||
if pvName == "" {
|
if pvName == "" {
|
||||||
scName := v1helper.GetPersistentVolumeClaimClass(pvc)
|
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)
|
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 {
|
if class.VolumeBindingMode == nil {
|
||||||
return false, nil, fmt.Errorf("VolumeBindingMode not set for StorageClass %q", scName)
|
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
|
// Skip unbound volumes
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
return false, nil, fmt.Errorf("PersistentVolume had no name")
|
||||||
return false, nil, fmt.Errorf("PersistentVolumeClaim was not found: %q", pvcName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pv, err := c.pvLister.Get(pvName)
|
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
|
return true, nil, nil
|
||||||
}
|
}
|
||||||
|
@ -320,13 +320,15 @@ 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, "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",
|
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, "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",
|
name: "unbound volume immediate binding mode",
|
||||||
|
Loading…
Reference in New Issue
Block a user