Merge pull request #84611 from cwdsuzhou/Nov/simplyfy_zone_checker

Simplify volume zone checker codes
This commit is contained in:
Kubernetes Prow Robot 2019-12-19 08:09:57 -08:00 committed by GitHub
commit 9fad2e3201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 60 deletions

View File

@ -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
}

View File

@ -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",