mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 13:57:38 +00:00
Update scheduler to check PreventPodSchedulingIfMissing
This commit is contained in:
@@ -355,7 +355,7 @@ func (pl *CSILimits) Filter(ctx context.Context, _ fwk.CycleState, pod *v1.Pod,
|
||||
func (pl *CSILimits) checkCSIDriverOnNode(pluginName string, csiNode *storagev1.CSINode) (bool, error) {
|
||||
// the registered driver must be a CSI driver to enforce this limit, if we can't find the driver,
|
||||
// we assume the driver may not be a CSI driver and allow the pod to be scheduled.
|
||||
_, err := pl.csiDriverLister.Get(pluginName)
|
||||
csiDriver, err := pl.csiDriverLister.Get(pluginName)
|
||||
if err != nil {
|
||||
if apierrors.IsNotFound(err) {
|
||||
return true, nil
|
||||
@@ -363,6 +363,12 @@ func (pl *CSILimits) checkCSIDriverOnNode(pluginName string, csiNode *storagev1.
|
||||
return false, fmt.Errorf("error getting CSIDriver for provider %s: %w", pluginName, err)
|
||||
}
|
||||
|
||||
driverOptin := csiDriver.Spec.PreventPodSchedulingIfMissing
|
||||
|
||||
if driverOptin == nil || !*driverOptin {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if csiNode == nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -1275,49 +1275,76 @@ func getFakeCSIDriverLister(driverNames ...string) fakeCSIDriverLister {
|
||||
return list
|
||||
}
|
||||
|
||||
func getFakeCSIDriverListerWithPreventPodSchedulingIfMissing(driverNames ...string) fakeCSIDriverLister {
|
||||
var list fakeCSIDriverLister
|
||||
for _, name := range driverNames {
|
||||
list = append(list, storagev1.CSIDriver{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: name},
|
||||
Spec: storagev1.CSIDriverSpec{
|
||||
PreventPodSchedulingIfMissing: ptr.To(true),
|
||||
},
|
||||
})
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func TestVolumeLimitScalingGate(t *testing.T) {
|
||||
// Pod uses a PVC that resolves to the EBS CSI driver via PV
|
||||
newPod := st.MakePod().PVC("csi-ebs.csi.aws.com-0").Obj()
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
enableVolumeLimitScaling bool
|
||||
limitSource string
|
||||
limit int32
|
||||
csiDriverPresent bool
|
||||
wantStatus *fwk.Status
|
||||
name string
|
||||
enableVolumeLimitScaling bool
|
||||
limitSource string
|
||||
limit int32
|
||||
csiDriverPresent bool
|
||||
preventPodSchedulingIfMissing bool
|
||||
wantStatus *fwk.Status
|
||||
}{
|
||||
{
|
||||
name: "gate enabled - fail when driver not installed and CSIDriver exists",
|
||||
enableVolumeLimitScaling: true,
|
||||
limitSource: "no-csi-driver",
|
||||
limit: 0,
|
||||
csiDriverPresent: true,
|
||||
wantStatus: fwk.NewStatus(fwk.Unschedulable, fmt.Sprintf("%s CSI driver is not installed on the node", ebsCSIDriverName)),
|
||||
name: "gate enabled - allow scheduling when CSIDriver exists but PreventPodSchedulingIfMissing is not set",
|
||||
enableVolumeLimitScaling: true,
|
||||
limitSource: "no-csi-driver",
|
||||
limit: 0,
|
||||
csiDriverPresent: true,
|
||||
preventPodSchedulingIfMissing: false,
|
||||
wantStatus: nil,
|
||||
},
|
||||
{
|
||||
name: "gate disabled - skip driver presence check (regardless of CSIDriver presence)",
|
||||
enableVolumeLimitScaling: false,
|
||||
limitSource: "no-csi-driver",
|
||||
limit: 0,
|
||||
csiDriverPresent: true,
|
||||
wantStatus: nil,
|
||||
name: "gate enabled - fail when driver not installed and PreventPodSchedulingIfMissing is true",
|
||||
enableVolumeLimitScaling: true,
|
||||
limitSource: "no-csi-driver",
|
||||
limit: 0,
|
||||
csiDriverPresent: true,
|
||||
preventPodSchedulingIfMissing: true,
|
||||
wantStatus: fwk.NewStatus(fwk.Unschedulable, fmt.Sprintf("%s CSI driver is not installed on the node", ebsCSIDriverName)),
|
||||
},
|
||||
{
|
||||
name: "gate enabled - driver installed within limit",
|
||||
enableVolumeLimitScaling: true,
|
||||
limitSource: "csinode",
|
||||
limit: 2,
|
||||
csiDriverPresent: true,
|
||||
wantStatus: nil,
|
||||
name: "gate disabled - skip driver presence check (regardless of CSIDriver presence)",
|
||||
enableVolumeLimitScaling: false,
|
||||
limitSource: "no-csi-driver",
|
||||
limit: 0,
|
||||
csiDriverPresent: true,
|
||||
preventPodSchedulingIfMissing: true,
|
||||
wantStatus: nil,
|
||||
},
|
||||
{
|
||||
name: "gate enabled - allow scheduling when CSIDriver object missing",
|
||||
enableVolumeLimitScaling: true,
|
||||
limitSource: "no-csi-driver",
|
||||
limit: 0,
|
||||
csiDriverPresent: false,
|
||||
wantStatus: nil,
|
||||
name: "gate enabled - driver installed within limit",
|
||||
enableVolumeLimitScaling: true,
|
||||
limitSource: "csinode",
|
||||
limit: 2,
|
||||
csiDriverPresent: true,
|
||||
preventPodSchedulingIfMissing: true,
|
||||
wantStatus: nil,
|
||||
},
|
||||
{
|
||||
name: "gate enabled - allow scheduling when CSIDriver object missing",
|
||||
enableVolumeLimitScaling: true,
|
||||
limitSource: "no-csi-driver",
|
||||
limit: 0,
|
||||
csiDriverPresent: false,
|
||||
preventPodSchedulingIfMissing: false,
|
||||
wantStatus: nil,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1334,6 +1361,9 @@ func TestVolumeLimitScalingGate(t *testing.T) {
|
||||
vaLister: getFakeVolumeAttachmentLister(0, ebsCSIDriverName),
|
||||
csiDriverLister: func() fakeCSIDriverLister {
|
||||
if tt.csiDriverPresent {
|
||||
if tt.preventPodSchedulingIfMissing {
|
||||
return getFakeCSIDriverListerWithPreventPodSchedulingIfMissing(ebsCSIDriverName)
|
||||
}
|
||||
return getFakeCSIDriverLister(ebsCSIDriverName)
|
||||
}
|
||||
return getFakeCSIDriverLister()
|
||||
|
||||
Reference in New Issue
Block a user