mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	move SidecarContainers featureGate checking
to PreFilter Signed-off-by: KunWuLuan <kunwuluan@gmail.com>
This commit is contained in:
		@@ -211,6 +211,14 @@ func computePodResourceRequest(pod *v1.Pod) *preFilterState {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// PreFilter invoked at the prefilter extension point.
 | 
					// PreFilter invoked at the prefilter extension point.
 | 
				
			||||||
func (f *Fit) PreFilter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
 | 
					func (f *Fit) PreFilter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
 | 
				
			||||||
 | 
						if !f.enableSidecarContainers && hasRestartableInitContainer(pod) {
 | 
				
			||||||
 | 
							// Scheduler will calculate resources usage for a Pod containing
 | 
				
			||||||
 | 
							// restartable init containers that will be equal or more than kubelet will
 | 
				
			||||||
 | 
							// require to run the Pod. So there will be no overbooking. However, to
 | 
				
			||||||
 | 
							// avoid the inconsistency in resource calculation between the scheduler
 | 
				
			||||||
 | 
							// and the older (before v1.28) kubelet, make the Pod unschedulable.
 | 
				
			||||||
 | 
							return nil, framework.NewStatus(framework.UnschedulableAndUnresolvable, "Pod has a restartable init container and the SidecarContainers feature is disabled")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	cycleState.Write(preFilterStateKey, computePodResourceRequest(pod))
 | 
						cycleState.Write(preFilterStateKey, computePodResourceRequest(pod))
 | 
				
			||||||
	return nil, nil
 | 
						return nil, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -253,15 +261,6 @@ func (f *Fit) EventsToRegister() []framework.ClusterEventWithHint {
 | 
				
			|||||||
// Checks if a node has sufficient resources, such as cpu, memory, gpu, opaque int resources etc to run a pod.
 | 
					// Checks if a node has sufficient resources, such as cpu, memory, gpu, opaque int resources etc to run a pod.
 | 
				
			||||||
// It returns a list of insufficient resources, if empty, then the node has all the resources requested by the pod.
 | 
					// It returns a list of insufficient resources, if empty, then the node has all the resources requested by the pod.
 | 
				
			||||||
func (f *Fit) Filter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
 | 
					func (f *Fit) Filter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
 | 
				
			||||||
	if !f.enableSidecarContainers && hasRestartableInitContainer(pod) {
 | 
					 | 
				
			||||||
		// Scheduler will calculate resources usage for a Pod containing
 | 
					 | 
				
			||||||
		// restartable init containers that will be equal or more than kubelet will
 | 
					 | 
				
			||||||
		// require to run the Pod. So there will be no overbooking. However, to
 | 
					 | 
				
			||||||
		// avoid the inconsistency in resource calculation between the scheduler
 | 
					 | 
				
			||||||
		// and the older (before v1.28) kubelet, make the Pod unschedulable.
 | 
					 | 
				
			||||||
		return framework.NewStatus(framework.UnschedulableAndUnresolvable, "Pod has a restartable init container and the SidecarContainers feature is disabled")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	s, err := getPreFilterState(cycleState)
 | 
						s, err := getPreFilterState(cycleState)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return framework.AsStatus(err)
 | 
							return framework.AsStatus(err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -694,16 +694,16 @@ func TestRestartableInitContainers(t *testing.T) {
 | 
				
			|||||||
		name                    string
 | 
							name                    string
 | 
				
			||||||
		pod                     *v1.Pod
 | 
							pod                     *v1.Pod
 | 
				
			||||||
		enableSidecarContainers bool
 | 
							enableSidecarContainers bool
 | 
				
			||||||
		wantStatus              *framework.Status
 | 
							wantPreFilterStatus     *framework.Status
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "allow pod without restartable init containers if sidecar containers is disabled",
 | 
								name: "allow pod without restartable init containers if sidecar containers is disabled",
 | 
				
			||||||
			pod:  newPod(),
 | 
								pod:  newPod(),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:       "not allow pod with restartable init containers if sidecar containers is disabled",
 | 
								name:                "not allow pod with restartable init containers if sidecar containers is disabled",
 | 
				
			||||||
			pod:        newPodWithRestartableInitContainers(),
 | 
								pod:                 newPodWithRestartableInitContainers(),
 | 
				
			||||||
			wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, "Pod has a restartable init container and the SidecarContainers feature is disabled"),
 | 
								wantPreFilterStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, "Pod has a restartable init container and the SidecarContainers feature is disabled"),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:                    "allow pod without restartable init containers if sidecar containers is enabled",
 | 
								name:                    "allow pod without restartable init containers if sidecar containers is enabled",
 | 
				
			||||||
@@ -732,13 +732,16 @@ func TestRestartableInitContainers(t *testing.T) {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			cycleState := framework.NewCycleState()
 | 
								cycleState := framework.NewCycleState()
 | 
				
			||||||
			_, preFilterStatus := p.(framework.PreFilterPlugin).PreFilter(context.Background(), cycleState, test.pod)
 | 
								_, preFilterStatus := p.(framework.PreFilterPlugin).PreFilter(context.Background(), cycleState, test.pod)
 | 
				
			||||||
 | 
								if diff := cmp.Diff(test.wantPreFilterStatus, preFilterStatus); diff != "" {
 | 
				
			||||||
 | 
									t.Error("status does not match (-expected +actual):\n", diff)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			if !preFilterStatus.IsSuccess() {
 | 
								if !preFilterStatus.IsSuccess() {
 | 
				
			||||||
				t.Errorf("prefilter failed with status: %v", preFilterStatus)
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), cycleState, test.pod, nodeInfo)
 | 
								filterStatus := p.(framework.FilterPlugin).Filter(ctx, cycleState, test.pod, nodeInfo)
 | 
				
			||||||
			if diff := cmp.Diff(gotStatus, test.wantStatus); diff != "" {
 | 
								if !filterStatus.IsSuccess() {
 | 
				
			||||||
				t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
 | 
									t.Error("status does not match (-expected +actual):\n- Success\n +\n", filterStatus.Code())
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user