mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
Merge pull request #121387 from KunWuLuan/SidercarContainerChecking
move SidecarContainers featureGate checking
This commit is contained in:
commit
e13f098c8e
@ -211,6 +211,14 @@ func computePodResourceRequest(pod *v1.Pod) *preFilterState {
|
||||
|
||||
// PreFilter invoked at the prefilter extension point.
|
||||
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))
|
||||
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.
|
||||
// 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 {
|
||||
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)
|
||||
if err != nil {
|
||||
return framework.AsStatus(err)
|
||||
|
@ -694,16 +694,16 @@ func TestRestartableInitContainers(t *testing.T) {
|
||||
name string
|
||||
pod *v1.Pod
|
||||
enableSidecarContainers bool
|
||||
wantStatus *framework.Status
|
||||
wantPreFilterStatus *framework.Status
|
||||
}{
|
||||
{
|
||||
name: "allow pod without restartable init containers if sidecar containers is disabled",
|
||||
pod: newPod(),
|
||||
},
|
||||
{
|
||||
name: "not allow pod with restartable init containers if sidecar containers is disabled",
|
||||
pod: newPodWithRestartableInitContainers(),
|
||||
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, "Pod has a restartable init container and the SidecarContainers feature is disabled"),
|
||||
name: "not allow pod with restartable init containers if sidecar containers is disabled",
|
||||
pod: newPodWithRestartableInitContainers(),
|
||||
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",
|
||||
@ -732,13 +732,16 @@ func TestRestartableInitContainers(t *testing.T) {
|
||||
}
|
||||
cycleState := framework.NewCycleState()
|
||||
_, 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() {
|
||||
t.Errorf("prefilter failed with status: %v", preFilterStatus)
|
||||
return
|
||||
}
|
||||
|
||||
gotStatus := p.(framework.FilterPlugin).Filter(context.Background(), cycleState, test.pod, nodeInfo)
|
||||
if diff := cmp.Diff(gotStatus, test.wantStatus); diff != "" {
|
||||
t.Errorf("status does not match: %v, want: %v", gotStatus, test.wantStatus)
|
||||
filterStatus := p.(framework.FilterPlugin).Filter(ctx, cycleState, test.pod, nodeInfo)
|
||||
if !filterStatus.IsSuccess() {
|
||||
t.Error("status does not match (-expected +actual):\n- Success\n +\n", filterStatus.Code())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user