scheduler: fail the volume attach limit when PVC is missing
Previously, the situation was ignored, which might have had the effect that Pod scheduling continued (?) even though the Pod+PVC weren't known to be in an acceptable state.
This commit is contained in:
		@@ -180,6 +180,14 @@ func (pl *CSILimits) filterAttachableVolumes(
 | 
				
			|||||||
		pvc, err := pl.pvcLister.PersistentVolumeClaims(pod.Namespace).Get(pvcName)
 | 
							pvc, err := pl.pvcLister.PersistentVolumeClaims(pod.Namespace).Get(pvcName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 | 
								if newPod {
 | 
				
			||||||
 | 
									// The PVC is required to proceed with
 | 
				
			||||||
 | 
									// scheduling of a new pod because it cannot
 | 
				
			||||||
 | 
									// run without it. Bail out immediately.
 | 
				
			||||||
 | 
									return fmt.Errorf("looking up PVC %s/%s: %v", pod.Namespace, pvcName, err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// If the PVC is invalid, we don't count the volume because
 | 
				
			||||||
 | 
								// there's no guarantee that it belongs to the running predicate.
 | 
				
			||||||
			klog.V(5).InfoS("Unable to look up PVC info", "PVC", fmt.Sprintf("%s/%s", pod.Namespace, pvcName))
 | 
								klog.V(5).InfoS("Unable to look up PVC info", "PVC", fmt.Sprintf("%s/%s", pod.Namespace, pvcName))
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -559,6 +559,7 @@ func TestCSILimits(t *testing.T) {
 | 
				
			|||||||
			ephemeralEnabled: true,
 | 
								ephemeralEnabled: true,
 | 
				
			||||||
			driverNames:      []string{ebsCSIDriverName},
 | 
								driverNames:      []string{ebsCSIDriverName},
 | 
				
			||||||
			test:             "ephemeral volume missing",
 | 
								test:             "ephemeral volume missing",
 | 
				
			||||||
 | 
								wantStatus:       framework.NewStatus(framework.Error, `looking up PVC test/abc-xyz: persistentvolumeclaim "abc-xyz" not found`),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			newPod:           ephemeralVolumePod,
 | 
								newPod:           ephemeralVolumePod,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -221,7 +221,7 @@ func (pl *nonCSILimits) Filter(ctx context.Context, _ *framework.CycleState, pod
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	newVolumes := make(sets.String)
 | 
						newVolumes := make(sets.String)
 | 
				
			||||||
	if err := pl.filterVolumes(pod, newVolumes); err != nil {
 | 
						if err := pl.filterVolumes(pod, true /* new pod */, newVolumes); err != nil {
 | 
				
			||||||
		return framework.AsStatus(err)
 | 
							return framework.AsStatus(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -254,7 +254,7 @@ func (pl *nonCSILimits) Filter(ctx context.Context, _ *framework.CycleState, pod
 | 
				
			|||||||
	// count unique volumes
 | 
						// count unique volumes
 | 
				
			||||||
	existingVolumes := make(sets.String)
 | 
						existingVolumes := make(sets.String)
 | 
				
			||||||
	for _, existingPod := range nodeInfo.Pods {
 | 
						for _, existingPod := range nodeInfo.Pods {
 | 
				
			||||||
		if err := pl.filterVolumes(existingPod.Pod, existingVolumes); err != nil {
 | 
							if err := pl.filterVolumes(existingPod.Pod, false /* existing pod */, existingVolumes); err != nil {
 | 
				
			||||||
			return framework.AsStatus(err)
 | 
								return framework.AsStatus(err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -278,7 +278,7 @@ func (pl *nonCSILimits) Filter(ctx context.Context, _ *framework.CycleState, pod
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (pl *nonCSILimits) filterVolumes(pod *v1.Pod, filteredVolumes sets.String) error {
 | 
					func (pl *nonCSILimits) filterVolumes(pod *v1.Pod, newPod bool, filteredVolumes sets.String) error {
 | 
				
			||||||
	volumes := pod.Spec.Volumes
 | 
						volumes := pod.Spec.Volumes
 | 
				
			||||||
	for i := range volumes {
 | 
						for i := range volumes {
 | 
				
			||||||
		vol := &volumes[i]
 | 
							vol := &volumes[i]
 | 
				
			||||||
@@ -319,6 +319,12 @@ func (pl *nonCSILimits) filterVolumes(pod *v1.Pod, filteredVolumes sets.String)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		pvc, err := pl.pvcLister.PersistentVolumeClaims(pod.Namespace).Get(pvcName)
 | 
							pvc, err := pl.pvcLister.PersistentVolumeClaims(pod.Namespace).Get(pvcName)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 | 
								if newPod {
 | 
				
			||||||
 | 
									// The PVC is required to proceed with
 | 
				
			||||||
 | 
									// scheduling of a new pod because it cannot
 | 
				
			||||||
 | 
									// run without it. Bail out immediately.
 | 
				
			||||||
 | 
									return fmt.Errorf("looking up PVC %s/%s: %v", pod.Namespace, pvcName, err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			// If the PVC is invalid, we don't count the volume because
 | 
								// If the PVC is invalid, we don't count the volume because
 | 
				
			||||||
			// there's no guarantee that it belongs to the running predicate.
 | 
								// there's no guarantee that it belongs to the running predicate.
 | 
				
			||||||
			klog.V(4).InfoS("Unable to look up PVC info, assuming PVC doesn't match predicate when counting limits", "PVC", fmt.Sprintf("%s/%s", pod.Namespace, pvcName), "err", err)
 | 
								klog.V(4).InfoS("Unable to look up PVC info, assuming PVC doesn't match predicate when counting limits", "PVC", fmt.Sprintf("%s/%s", pod.Namespace, pvcName), "err", err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -95,6 +95,7 @@ func TestEphemeralLimits(t *testing.T) {
 | 
				
			|||||||
			newPod:           ephemeralVolumePod,
 | 
								newPod:           ephemeralVolumePod,
 | 
				
			||||||
			ephemeralEnabled: true,
 | 
								ephemeralEnabled: true,
 | 
				
			||||||
			test:             "volume missing",
 | 
								test:             "volume missing",
 | 
				
			||||||
 | 
								wantStatus:       framework.NewStatus(framework.Error, `looking up PVC test/abc-xyz: persistentvolumeclaim "abc-xyz" not found`),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			newPod:           ephemeralVolumePod,
 | 
								newPod:           ephemeralVolumePod,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user