diff --git a/pkg/kubelet/cm/.mockery.yaml b/pkg/kubelet/cm/.mockery.yaml new file mode 100644 index 00000000000..3a8ae030844 --- /dev/null +++ b/pkg/kubelet/cm/.mockery.yaml @@ -0,0 +1,11 @@ +--- +dir: testing +filename: "mock_{{.InterfaceName | snakecase}}.go" +boilerplate-file: ../../../hack/boilerplate/boilerplate.generatego.txt +outpkg: testing +with-expecter: true +packages: + k8s.io/kubernetes/pkg/kubelet/cm: + interfaces: + ContainerManager: + PodContainerManager: diff --git a/pkg/kubelet/cm/container_manager.go b/pkg/kubelet/cm/container_manager.go index f8d69c0e49e..71a1291d193 100644 --- a/pkg/kubelet/cm/container_manager.go +++ b/pkg/kubelet/cm/container_manager.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +//go:generate mockery package cm import ( diff --git a/pkg/kubelet/cm/testing/mock_container_manager.go b/pkg/kubelet/cm/testing/mock_container_manager.go new file mode 100644 index 00000000000..ef93f5df41c --- /dev/null +++ b/pkg/kubelet/cm/testing/mock_container_manager.go @@ -0,0 +1,1636 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by mockery v2.40.3. DO NOT EDIT. + +package testing + +import ( + cm "k8s.io/kubernetes/pkg/kubelet/cm" + cache "k8s.io/kubernetes/pkg/kubelet/pluginmanager/cache" + + config "k8s.io/kubernetes/pkg/kubelet/config" + + container "k8s.io/kubernetes/pkg/kubelet/container" + + context "context" + + corev1 "k8s.io/api/core/v1" + + cri "k8s.io/cri-api/pkg/apis" + + framework "k8s.io/kubernetes/pkg/scheduler/framework" + + healthz "k8s.io/apiserver/pkg/server/healthz" + + lifecycle "k8s.io/kubernetes/pkg/kubelet/lifecycle" + + mock "github.com/stretchr/testify/mock" + + resourceupdates "k8s.io/kubernetes/pkg/kubelet/cm/resourceupdates" + + status "k8s.io/kubernetes/pkg/kubelet/status" + + types "k8s.io/apimachinery/pkg/types" + + v1 "k8s.io/kubelet/pkg/apis/podresources/v1" +) + +// MockContainerManager is an autogenerated mock type for the ContainerManager type +type MockContainerManager struct { + mock.Mock +} + +type MockContainerManager_Expecter struct { + mock *mock.Mock +} + +func (_m *MockContainerManager) EXPECT() *MockContainerManager_Expecter { + return &MockContainerManager_Expecter{mock: &_m.Mock} +} + +// GetAllocatableCPUs provides a mock function with given fields: +func (_m *MockContainerManager) GetAllocatableCPUs() []int64 { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetAllocatableCPUs") + } + + var r0 []int64 + if rf, ok := ret.Get(0).(func() []int64); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]int64) + } + } + + return r0 +} + +// MockContainerManager_GetAllocatableCPUs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllocatableCPUs' +type MockContainerManager_GetAllocatableCPUs_Call struct { + *mock.Call +} + +// GetAllocatableCPUs is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetAllocatableCPUs() *MockContainerManager_GetAllocatableCPUs_Call { + return &MockContainerManager_GetAllocatableCPUs_Call{Call: _e.mock.On("GetAllocatableCPUs")} +} + +func (_c *MockContainerManager_GetAllocatableCPUs_Call) Run(run func()) *MockContainerManager_GetAllocatableCPUs_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetAllocatableCPUs_Call) Return(_a0 []int64) *MockContainerManager_GetAllocatableCPUs_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetAllocatableCPUs_Call) RunAndReturn(run func() []int64) *MockContainerManager_GetAllocatableCPUs_Call { + _c.Call.Return(run) + return _c +} + +// GetAllocatableDevices provides a mock function with given fields: +func (_m *MockContainerManager) GetAllocatableDevices() []*v1.ContainerDevices { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetAllocatableDevices") + } + + var r0 []*v1.ContainerDevices + if rf, ok := ret.Get(0).(func() []*v1.ContainerDevices); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*v1.ContainerDevices) + } + } + + return r0 +} + +// MockContainerManager_GetAllocatableDevices_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllocatableDevices' +type MockContainerManager_GetAllocatableDevices_Call struct { + *mock.Call +} + +// GetAllocatableDevices is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetAllocatableDevices() *MockContainerManager_GetAllocatableDevices_Call { + return &MockContainerManager_GetAllocatableDevices_Call{Call: _e.mock.On("GetAllocatableDevices")} +} + +func (_c *MockContainerManager_GetAllocatableDevices_Call) Run(run func()) *MockContainerManager_GetAllocatableDevices_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetAllocatableDevices_Call) Return(_a0 []*v1.ContainerDevices) *MockContainerManager_GetAllocatableDevices_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetAllocatableDevices_Call) RunAndReturn(run func() []*v1.ContainerDevices) *MockContainerManager_GetAllocatableDevices_Call { + _c.Call.Return(run) + return _c +} + +// GetAllocatableMemory provides a mock function with given fields: +func (_m *MockContainerManager) GetAllocatableMemory() []*v1.ContainerMemory { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetAllocatableMemory") + } + + var r0 []*v1.ContainerMemory + if rf, ok := ret.Get(0).(func() []*v1.ContainerMemory); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*v1.ContainerMemory) + } + } + + return r0 +} + +// MockContainerManager_GetAllocatableMemory_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllocatableMemory' +type MockContainerManager_GetAllocatableMemory_Call struct { + *mock.Call +} + +// GetAllocatableMemory is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetAllocatableMemory() *MockContainerManager_GetAllocatableMemory_Call { + return &MockContainerManager_GetAllocatableMemory_Call{Call: _e.mock.On("GetAllocatableMemory")} +} + +func (_c *MockContainerManager_GetAllocatableMemory_Call) Run(run func()) *MockContainerManager_GetAllocatableMemory_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetAllocatableMemory_Call) Return(_a0 []*v1.ContainerMemory) *MockContainerManager_GetAllocatableMemory_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetAllocatableMemory_Call) RunAndReturn(run func() []*v1.ContainerMemory) *MockContainerManager_GetAllocatableMemory_Call { + _c.Call.Return(run) + return _c +} + +// GetAllocateResourcesPodAdmitHandler provides a mock function with given fields: +func (_m *MockContainerManager) GetAllocateResourcesPodAdmitHandler() lifecycle.PodAdmitHandler { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetAllocateResourcesPodAdmitHandler") + } + + var r0 lifecycle.PodAdmitHandler + if rf, ok := ret.Get(0).(func() lifecycle.PodAdmitHandler); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(lifecycle.PodAdmitHandler) + } + } + + return r0 +} + +// MockContainerManager_GetAllocateResourcesPodAdmitHandler_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllocateResourcesPodAdmitHandler' +type MockContainerManager_GetAllocateResourcesPodAdmitHandler_Call struct { + *mock.Call +} + +// GetAllocateResourcesPodAdmitHandler is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetAllocateResourcesPodAdmitHandler() *MockContainerManager_GetAllocateResourcesPodAdmitHandler_Call { + return &MockContainerManager_GetAllocateResourcesPodAdmitHandler_Call{Call: _e.mock.On("GetAllocateResourcesPodAdmitHandler")} +} + +func (_c *MockContainerManager_GetAllocateResourcesPodAdmitHandler_Call) Run(run func()) *MockContainerManager_GetAllocateResourcesPodAdmitHandler_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetAllocateResourcesPodAdmitHandler_Call) Return(_a0 lifecycle.PodAdmitHandler) *MockContainerManager_GetAllocateResourcesPodAdmitHandler_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetAllocateResourcesPodAdmitHandler_Call) RunAndReturn(run func() lifecycle.PodAdmitHandler) *MockContainerManager_GetAllocateResourcesPodAdmitHandler_Call { + _c.Call.Return(run) + return _c +} + +// GetCPUs provides a mock function with given fields: podUID, containerName +func (_m *MockContainerManager) GetCPUs(podUID string, containerName string) []int64 { + ret := _m.Called(podUID, containerName) + + if len(ret) == 0 { + panic("no return value specified for GetCPUs") + } + + var r0 []int64 + if rf, ok := ret.Get(0).(func(string, string) []int64); ok { + r0 = rf(podUID, containerName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]int64) + } + } + + return r0 +} + +// MockContainerManager_GetCPUs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCPUs' +type MockContainerManager_GetCPUs_Call struct { + *mock.Call +} + +// GetCPUs is a helper method to define mock.On call +// - podUID string +// - containerName string +func (_e *MockContainerManager_Expecter) GetCPUs(podUID interface{}, containerName interface{}) *MockContainerManager_GetCPUs_Call { + return &MockContainerManager_GetCPUs_Call{Call: _e.mock.On("GetCPUs", podUID, containerName)} +} + +func (_c *MockContainerManager_GetCPUs_Call) Run(run func(podUID string, containerName string)) *MockContainerManager_GetCPUs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string)) + }) + return _c +} + +func (_c *MockContainerManager_GetCPUs_Call) Return(_a0 []int64) *MockContainerManager_GetCPUs_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetCPUs_Call) RunAndReturn(run func(string, string) []int64) *MockContainerManager_GetCPUs_Call { + _c.Call.Return(run) + return _c +} + +// GetCapacity provides a mock function with given fields: localStorageCapacityIsolation +func (_m *MockContainerManager) GetCapacity(localStorageCapacityIsolation bool) corev1.ResourceList { + ret := _m.Called(localStorageCapacityIsolation) + + if len(ret) == 0 { + panic("no return value specified for GetCapacity") + } + + var r0 corev1.ResourceList + if rf, ok := ret.Get(0).(func(bool) corev1.ResourceList); ok { + r0 = rf(localStorageCapacityIsolation) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(corev1.ResourceList) + } + } + + return r0 +} + +// MockContainerManager_GetCapacity_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCapacity' +type MockContainerManager_GetCapacity_Call struct { + *mock.Call +} + +// GetCapacity is a helper method to define mock.On call +// - localStorageCapacityIsolation bool +func (_e *MockContainerManager_Expecter) GetCapacity(localStorageCapacityIsolation interface{}) *MockContainerManager_GetCapacity_Call { + return &MockContainerManager_GetCapacity_Call{Call: _e.mock.On("GetCapacity", localStorageCapacityIsolation)} +} + +func (_c *MockContainerManager_GetCapacity_Call) Run(run func(localStorageCapacityIsolation bool)) *MockContainerManager_GetCapacity_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *MockContainerManager_GetCapacity_Call) Return(_a0 corev1.ResourceList) *MockContainerManager_GetCapacity_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetCapacity_Call) RunAndReturn(run func(bool) corev1.ResourceList) *MockContainerManager_GetCapacity_Call { + _c.Call.Return(run) + return _c +} + +// GetDevicePluginResourceCapacity provides a mock function with given fields: +func (_m *MockContainerManager) GetDevicePluginResourceCapacity() (corev1.ResourceList, corev1.ResourceList, []string) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetDevicePluginResourceCapacity") + } + + var r0 corev1.ResourceList + var r1 corev1.ResourceList + var r2 []string + if rf, ok := ret.Get(0).(func() (corev1.ResourceList, corev1.ResourceList, []string)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() corev1.ResourceList); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(corev1.ResourceList) + } + } + + if rf, ok := ret.Get(1).(func() corev1.ResourceList); ok { + r1 = rf() + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(corev1.ResourceList) + } + } + + if rf, ok := ret.Get(2).(func() []string); ok { + r2 = rf() + } else { + if ret.Get(2) != nil { + r2 = ret.Get(2).([]string) + } + } + + return r0, r1, r2 +} + +// MockContainerManager_GetDevicePluginResourceCapacity_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDevicePluginResourceCapacity' +type MockContainerManager_GetDevicePluginResourceCapacity_Call struct { + *mock.Call +} + +// GetDevicePluginResourceCapacity is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetDevicePluginResourceCapacity() *MockContainerManager_GetDevicePluginResourceCapacity_Call { + return &MockContainerManager_GetDevicePluginResourceCapacity_Call{Call: _e.mock.On("GetDevicePluginResourceCapacity")} +} + +func (_c *MockContainerManager_GetDevicePluginResourceCapacity_Call) Run(run func()) *MockContainerManager_GetDevicePluginResourceCapacity_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetDevicePluginResourceCapacity_Call) Return(_a0 corev1.ResourceList, _a1 corev1.ResourceList, _a2 []string) *MockContainerManager_GetDevicePluginResourceCapacity_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockContainerManager_GetDevicePluginResourceCapacity_Call) RunAndReturn(run func() (corev1.ResourceList, corev1.ResourceList, []string)) *MockContainerManager_GetDevicePluginResourceCapacity_Call { + _c.Call.Return(run) + return _c +} + +// GetDevices provides a mock function with given fields: podUID, containerName +func (_m *MockContainerManager) GetDevices(podUID string, containerName string) []*v1.ContainerDevices { + ret := _m.Called(podUID, containerName) + + if len(ret) == 0 { + panic("no return value specified for GetDevices") + } + + var r0 []*v1.ContainerDevices + if rf, ok := ret.Get(0).(func(string, string) []*v1.ContainerDevices); ok { + r0 = rf(podUID, containerName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*v1.ContainerDevices) + } + } + + return r0 +} + +// MockContainerManager_GetDevices_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDevices' +type MockContainerManager_GetDevices_Call struct { + *mock.Call +} + +// GetDevices is a helper method to define mock.On call +// - podUID string +// - containerName string +func (_e *MockContainerManager_Expecter) GetDevices(podUID interface{}, containerName interface{}) *MockContainerManager_GetDevices_Call { + return &MockContainerManager_GetDevices_Call{Call: _e.mock.On("GetDevices", podUID, containerName)} +} + +func (_c *MockContainerManager_GetDevices_Call) Run(run func(podUID string, containerName string)) *MockContainerManager_GetDevices_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string)) + }) + return _c +} + +func (_c *MockContainerManager_GetDevices_Call) Return(_a0 []*v1.ContainerDevices) *MockContainerManager_GetDevices_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetDevices_Call) RunAndReturn(run func(string, string) []*v1.ContainerDevices) *MockContainerManager_GetDevices_Call { + _c.Call.Return(run) + return _c +} + +// GetDynamicResources provides a mock function with given fields: pod, _a1 +func (_m *MockContainerManager) GetDynamicResources(pod *corev1.Pod, _a1 *corev1.Container) []*v1.DynamicResource { + ret := _m.Called(pod, _a1) + + if len(ret) == 0 { + panic("no return value specified for GetDynamicResources") + } + + var r0 []*v1.DynamicResource + if rf, ok := ret.Get(0).(func(*corev1.Pod, *corev1.Container) []*v1.DynamicResource); ok { + r0 = rf(pod, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*v1.DynamicResource) + } + } + + return r0 +} + +// MockContainerManager_GetDynamicResources_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDynamicResources' +type MockContainerManager_GetDynamicResources_Call struct { + *mock.Call +} + +// GetDynamicResources is a helper method to define mock.On call +// - pod *corev1.Pod +// - _a1 *corev1.Container +func (_e *MockContainerManager_Expecter) GetDynamicResources(pod interface{}, _a1 interface{}) *MockContainerManager_GetDynamicResources_Call { + return &MockContainerManager_GetDynamicResources_Call{Call: _e.mock.On("GetDynamicResources", pod, _a1)} +} + +func (_c *MockContainerManager_GetDynamicResources_Call) Run(run func(pod *corev1.Pod, _a1 *corev1.Container)) *MockContainerManager_GetDynamicResources_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*corev1.Pod), args[1].(*corev1.Container)) + }) + return _c +} + +func (_c *MockContainerManager_GetDynamicResources_Call) Return(_a0 []*v1.DynamicResource) *MockContainerManager_GetDynamicResources_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetDynamicResources_Call) RunAndReturn(run func(*corev1.Pod, *corev1.Container) []*v1.DynamicResource) *MockContainerManager_GetDynamicResources_Call { + _c.Call.Return(run) + return _c +} + +// GetHealthCheckers provides a mock function with given fields: +func (_m *MockContainerManager) GetHealthCheckers() []healthz.HealthChecker { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetHealthCheckers") + } + + var r0 []healthz.HealthChecker + if rf, ok := ret.Get(0).(func() []healthz.HealthChecker); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]healthz.HealthChecker) + } + } + + return r0 +} + +// MockContainerManager_GetHealthCheckers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetHealthCheckers' +type MockContainerManager_GetHealthCheckers_Call struct { + *mock.Call +} + +// GetHealthCheckers is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetHealthCheckers() *MockContainerManager_GetHealthCheckers_Call { + return &MockContainerManager_GetHealthCheckers_Call{Call: _e.mock.On("GetHealthCheckers")} +} + +func (_c *MockContainerManager_GetHealthCheckers_Call) Run(run func()) *MockContainerManager_GetHealthCheckers_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetHealthCheckers_Call) Return(_a0 []healthz.HealthChecker) *MockContainerManager_GetHealthCheckers_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetHealthCheckers_Call) RunAndReturn(run func() []healthz.HealthChecker) *MockContainerManager_GetHealthCheckers_Call { + _c.Call.Return(run) + return _c +} + +// GetMemory provides a mock function with given fields: podUID, containerName +func (_m *MockContainerManager) GetMemory(podUID string, containerName string) []*v1.ContainerMemory { + ret := _m.Called(podUID, containerName) + + if len(ret) == 0 { + panic("no return value specified for GetMemory") + } + + var r0 []*v1.ContainerMemory + if rf, ok := ret.Get(0).(func(string, string) []*v1.ContainerMemory); ok { + r0 = rf(podUID, containerName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*v1.ContainerMemory) + } + } + + return r0 +} + +// MockContainerManager_GetMemory_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMemory' +type MockContainerManager_GetMemory_Call struct { + *mock.Call +} + +// GetMemory is a helper method to define mock.On call +// - podUID string +// - containerName string +func (_e *MockContainerManager_Expecter) GetMemory(podUID interface{}, containerName interface{}) *MockContainerManager_GetMemory_Call { + return &MockContainerManager_GetMemory_Call{Call: _e.mock.On("GetMemory", podUID, containerName)} +} + +func (_c *MockContainerManager_GetMemory_Call) Run(run func(podUID string, containerName string)) *MockContainerManager_GetMemory_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string)) + }) + return _c +} + +func (_c *MockContainerManager_GetMemory_Call) Return(_a0 []*v1.ContainerMemory) *MockContainerManager_GetMemory_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetMemory_Call) RunAndReturn(run func(string, string) []*v1.ContainerMemory) *MockContainerManager_GetMemory_Call { + _c.Call.Return(run) + return _c +} + +// GetMountedSubsystems provides a mock function with given fields: +func (_m *MockContainerManager) GetMountedSubsystems() *cm.CgroupSubsystems { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetMountedSubsystems") + } + + var r0 *cm.CgroupSubsystems + if rf, ok := ret.Get(0).(func() *cm.CgroupSubsystems); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*cm.CgroupSubsystems) + } + } + + return r0 +} + +// MockContainerManager_GetMountedSubsystems_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMountedSubsystems' +type MockContainerManager_GetMountedSubsystems_Call struct { + *mock.Call +} + +// GetMountedSubsystems is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetMountedSubsystems() *MockContainerManager_GetMountedSubsystems_Call { + return &MockContainerManager_GetMountedSubsystems_Call{Call: _e.mock.On("GetMountedSubsystems")} +} + +func (_c *MockContainerManager_GetMountedSubsystems_Call) Run(run func()) *MockContainerManager_GetMountedSubsystems_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetMountedSubsystems_Call) Return(_a0 *cm.CgroupSubsystems) *MockContainerManager_GetMountedSubsystems_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetMountedSubsystems_Call) RunAndReturn(run func() *cm.CgroupSubsystems) *MockContainerManager_GetMountedSubsystems_Call { + _c.Call.Return(run) + return _c +} + +// GetNodeAllocatableAbsolute provides a mock function with given fields: +func (_m *MockContainerManager) GetNodeAllocatableAbsolute() corev1.ResourceList { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetNodeAllocatableAbsolute") + } + + var r0 corev1.ResourceList + if rf, ok := ret.Get(0).(func() corev1.ResourceList); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(corev1.ResourceList) + } + } + + return r0 +} + +// MockContainerManager_GetNodeAllocatableAbsolute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNodeAllocatableAbsolute' +type MockContainerManager_GetNodeAllocatableAbsolute_Call struct { + *mock.Call +} + +// GetNodeAllocatableAbsolute is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetNodeAllocatableAbsolute() *MockContainerManager_GetNodeAllocatableAbsolute_Call { + return &MockContainerManager_GetNodeAllocatableAbsolute_Call{Call: _e.mock.On("GetNodeAllocatableAbsolute")} +} + +func (_c *MockContainerManager_GetNodeAllocatableAbsolute_Call) Run(run func()) *MockContainerManager_GetNodeAllocatableAbsolute_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetNodeAllocatableAbsolute_Call) Return(_a0 corev1.ResourceList) *MockContainerManager_GetNodeAllocatableAbsolute_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetNodeAllocatableAbsolute_Call) RunAndReturn(run func() corev1.ResourceList) *MockContainerManager_GetNodeAllocatableAbsolute_Call { + _c.Call.Return(run) + return _c +} + +// GetNodeAllocatableReservation provides a mock function with given fields: +func (_m *MockContainerManager) GetNodeAllocatableReservation() corev1.ResourceList { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetNodeAllocatableReservation") + } + + var r0 corev1.ResourceList + if rf, ok := ret.Get(0).(func() corev1.ResourceList); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(corev1.ResourceList) + } + } + + return r0 +} + +// MockContainerManager_GetNodeAllocatableReservation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNodeAllocatableReservation' +type MockContainerManager_GetNodeAllocatableReservation_Call struct { + *mock.Call +} + +// GetNodeAllocatableReservation is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetNodeAllocatableReservation() *MockContainerManager_GetNodeAllocatableReservation_Call { + return &MockContainerManager_GetNodeAllocatableReservation_Call{Call: _e.mock.On("GetNodeAllocatableReservation")} +} + +func (_c *MockContainerManager_GetNodeAllocatableReservation_Call) Run(run func()) *MockContainerManager_GetNodeAllocatableReservation_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetNodeAllocatableReservation_Call) Return(_a0 corev1.ResourceList) *MockContainerManager_GetNodeAllocatableReservation_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetNodeAllocatableReservation_Call) RunAndReturn(run func() corev1.ResourceList) *MockContainerManager_GetNodeAllocatableReservation_Call { + _c.Call.Return(run) + return _c +} + +// GetNodeConfig provides a mock function with given fields: +func (_m *MockContainerManager) GetNodeConfig() cm.NodeConfig { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetNodeConfig") + } + + var r0 cm.NodeConfig + if rf, ok := ret.Get(0).(func() cm.NodeConfig); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(cm.NodeConfig) + } + + return r0 +} + +// MockContainerManager_GetNodeConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNodeConfig' +type MockContainerManager_GetNodeConfig_Call struct { + *mock.Call +} + +// GetNodeConfig is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetNodeConfig() *MockContainerManager_GetNodeConfig_Call { + return &MockContainerManager_GetNodeConfig_Call{Call: _e.mock.On("GetNodeConfig")} +} + +func (_c *MockContainerManager_GetNodeConfig_Call) Run(run func()) *MockContainerManager_GetNodeConfig_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetNodeConfig_Call) Return(_a0 cm.NodeConfig) *MockContainerManager_GetNodeConfig_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetNodeConfig_Call) RunAndReturn(run func() cm.NodeConfig) *MockContainerManager_GetNodeConfig_Call { + _c.Call.Return(run) + return _c +} + +// GetPluginRegistrationHandlers provides a mock function with given fields: +func (_m *MockContainerManager) GetPluginRegistrationHandlers() map[string]cache.PluginHandler { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetPluginRegistrationHandlers") + } + + var r0 map[string]cache.PluginHandler + if rf, ok := ret.Get(0).(func() map[string]cache.PluginHandler); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[string]cache.PluginHandler) + } + } + + return r0 +} + +// MockContainerManager_GetPluginRegistrationHandlers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPluginRegistrationHandlers' +type MockContainerManager_GetPluginRegistrationHandlers_Call struct { + *mock.Call +} + +// GetPluginRegistrationHandlers is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetPluginRegistrationHandlers() *MockContainerManager_GetPluginRegistrationHandlers_Call { + return &MockContainerManager_GetPluginRegistrationHandlers_Call{Call: _e.mock.On("GetPluginRegistrationHandlers")} +} + +func (_c *MockContainerManager_GetPluginRegistrationHandlers_Call) Run(run func()) *MockContainerManager_GetPluginRegistrationHandlers_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetPluginRegistrationHandlers_Call) Return(_a0 map[string]cache.PluginHandler) *MockContainerManager_GetPluginRegistrationHandlers_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetPluginRegistrationHandlers_Call) RunAndReturn(run func() map[string]cache.PluginHandler) *MockContainerManager_GetPluginRegistrationHandlers_Call { + _c.Call.Return(run) + return _c +} + +// GetPodCgroupRoot provides a mock function with given fields: +func (_m *MockContainerManager) GetPodCgroupRoot() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetPodCgroupRoot") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// MockContainerManager_GetPodCgroupRoot_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodCgroupRoot' +type MockContainerManager_GetPodCgroupRoot_Call struct { + *mock.Call +} + +// GetPodCgroupRoot is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetPodCgroupRoot() *MockContainerManager_GetPodCgroupRoot_Call { + return &MockContainerManager_GetPodCgroupRoot_Call{Call: _e.mock.On("GetPodCgroupRoot")} +} + +func (_c *MockContainerManager_GetPodCgroupRoot_Call) Run(run func()) *MockContainerManager_GetPodCgroupRoot_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetPodCgroupRoot_Call) Return(_a0 string) *MockContainerManager_GetPodCgroupRoot_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetPodCgroupRoot_Call) RunAndReturn(run func() string) *MockContainerManager_GetPodCgroupRoot_Call { + _c.Call.Return(run) + return _c +} + +// GetQOSContainersInfo provides a mock function with given fields: +func (_m *MockContainerManager) GetQOSContainersInfo() cm.QOSContainersInfo { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetQOSContainersInfo") + } + + var r0 cm.QOSContainersInfo + if rf, ok := ret.Get(0).(func() cm.QOSContainersInfo); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(cm.QOSContainersInfo) + } + + return r0 +} + +// MockContainerManager_GetQOSContainersInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetQOSContainersInfo' +type MockContainerManager_GetQOSContainersInfo_Call struct { + *mock.Call +} + +// GetQOSContainersInfo is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) GetQOSContainersInfo() *MockContainerManager_GetQOSContainersInfo_Call { + return &MockContainerManager_GetQOSContainersInfo_Call{Call: _e.mock.On("GetQOSContainersInfo")} +} + +func (_c *MockContainerManager_GetQOSContainersInfo_Call) Run(run func()) *MockContainerManager_GetQOSContainersInfo_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_GetQOSContainersInfo_Call) Return(_a0 cm.QOSContainersInfo) *MockContainerManager_GetQOSContainersInfo_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_GetQOSContainersInfo_Call) RunAndReturn(run func() cm.QOSContainersInfo) *MockContainerManager_GetQOSContainersInfo_Call { + _c.Call.Return(run) + return _c +} + +// GetResources provides a mock function with given fields: ctx, pod, _a2 +func (_m *MockContainerManager) GetResources(ctx context.Context, pod *corev1.Pod, _a2 *corev1.Container) (*container.RunContainerOptions, error) { + ret := _m.Called(ctx, pod, _a2) + + if len(ret) == 0 { + panic("no return value specified for GetResources") + } + + var r0 *container.RunContainerOptions + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *corev1.Pod, *corev1.Container) (*container.RunContainerOptions, error)); ok { + return rf(ctx, pod, _a2) + } + if rf, ok := ret.Get(0).(func(context.Context, *corev1.Pod, *corev1.Container) *container.RunContainerOptions); ok { + r0 = rf(ctx, pod, _a2) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*container.RunContainerOptions) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *corev1.Pod, *corev1.Container) error); ok { + r1 = rf(ctx, pod, _a2) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockContainerManager_GetResources_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetResources' +type MockContainerManager_GetResources_Call struct { + *mock.Call +} + +// GetResources is a helper method to define mock.On call +// - ctx context.Context +// - pod *corev1.Pod +// - _a2 *corev1.Container +func (_e *MockContainerManager_Expecter) GetResources(ctx interface{}, pod interface{}, _a2 interface{}) *MockContainerManager_GetResources_Call { + return &MockContainerManager_GetResources_Call{Call: _e.mock.On("GetResources", ctx, pod, _a2)} +} + +func (_c *MockContainerManager_GetResources_Call) Run(run func(ctx context.Context, pod *corev1.Pod, _a2 *corev1.Container)) *MockContainerManager_GetResources_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*corev1.Pod), args[2].(*corev1.Container)) + }) + return _c +} + +func (_c *MockContainerManager_GetResources_Call) Return(_a0 *container.RunContainerOptions, _a1 error) *MockContainerManager_GetResources_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockContainerManager_GetResources_Call) RunAndReturn(run func(context.Context, *corev1.Pod, *corev1.Container) (*container.RunContainerOptions, error)) *MockContainerManager_GetResources_Call { + _c.Call.Return(run) + return _c +} + +// InternalContainerLifecycle provides a mock function with given fields: +func (_m *MockContainerManager) InternalContainerLifecycle() cm.InternalContainerLifecycle { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for InternalContainerLifecycle") + } + + var r0 cm.InternalContainerLifecycle + if rf, ok := ret.Get(0).(func() cm.InternalContainerLifecycle); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(cm.InternalContainerLifecycle) + } + } + + return r0 +} + +// MockContainerManager_InternalContainerLifecycle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'InternalContainerLifecycle' +type MockContainerManager_InternalContainerLifecycle_Call struct { + *mock.Call +} + +// InternalContainerLifecycle is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) InternalContainerLifecycle() *MockContainerManager_InternalContainerLifecycle_Call { + return &MockContainerManager_InternalContainerLifecycle_Call{Call: _e.mock.On("InternalContainerLifecycle")} +} + +func (_c *MockContainerManager_InternalContainerLifecycle_Call) Run(run func()) *MockContainerManager_InternalContainerLifecycle_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_InternalContainerLifecycle_Call) Return(_a0 cm.InternalContainerLifecycle) *MockContainerManager_InternalContainerLifecycle_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_InternalContainerLifecycle_Call) RunAndReturn(run func() cm.InternalContainerLifecycle) *MockContainerManager_InternalContainerLifecycle_Call { + _c.Call.Return(run) + return _c +} + +// NewPodContainerManager provides a mock function with given fields: +func (_m *MockContainerManager) NewPodContainerManager() cm.PodContainerManager { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for NewPodContainerManager") + } + + var r0 cm.PodContainerManager + if rf, ok := ret.Get(0).(func() cm.PodContainerManager); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(cm.PodContainerManager) + } + } + + return r0 +} + +// MockContainerManager_NewPodContainerManager_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewPodContainerManager' +type MockContainerManager_NewPodContainerManager_Call struct { + *mock.Call +} + +// NewPodContainerManager is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) NewPodContainerManager() *MockContainerManager_NewPodContainerManager_Call { + return &MockContainerManager_NewPodContainerManager_Call{Call: _e.mock.On("NewPodContainerManager")} +} + +func (_c *MockContainerManager_NewPodContainerManager_Call) Run(run func()) *MockContainerManager_NewPodContainerManager_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_NewPodContainerManager_Call) Return(_a0 cm.PodContainerManager) *MockContainerManager_NewPodContainerManager_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_NewPodContainerManager_Call) RunAndReturn(run func() cm.PodContainerManager) *MockContainerManager_NewPodContainerManager_Call { + _c.Call.Return(run) + return _c +} + +// PodMightNeedToUnprepareResources provides a mock function with given fields: UID +func (_m *MockContainerManager) PodMightNeedToUnprepareResources(UID types.UID) bool { + ret := _m.Called(UID) + + if len(ret) == 0 { + panic("no return value specified for PodMightNeedToUnprepareResources") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(types.UID) bool); ok { + r0 = rf(UID) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// MockContainerManager_PodMightNeedToUnprepareResources_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PodMightNeedToUnprepareResources' +type MockContainerManager_PodMightNeedToUnprepareResources_Call struct { + *mock.Call +} + +// PodMightNeedToUnprepareResources is a helper method to define mock.On call +// - UID types.UID +func (_e *MockContainerManager_Expecter) PodMightNeedToUnprepareResources(UID interface{}) *MockContainerManager_PodMightNeedToUnprepareResources_Call { + return &MockContainerManager_PodMightNeedToUnprepareResources_Call{Call: _e.mock.On("PodMightNeedToUnprepareResources", UID)} +} + +func (_c *MockContainerManager_PodMightNeedToUnprepareResources_Call) Run(run func(UID types.UID)) *MockContainerManager_PodMightNeedToUnprepareResources_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(types.UID)) + }) + return _c +} + +func (_c *MockContainerManager_PodMightNeedToUnprepareResources_Call) Return(_a0 bool) *MockContainerManager_PodMightNeedToUnprepareResources_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_PodMightNeedToUnprepareResources_Call) RunAndReturn(run func(types.UID) bool) *MockContainerManager_PodMightNeedToUnprepareResources_Call { + _c.Call.Return(run) + return _c +} + +// PrepareDynamicResources provides a mock function with given fields: _a0, _a1 +func (_m *MockContainerManager) PrepareDynamicResources(_a0 context.Context, _a1 *corev1.Pod) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for PrepareDynamicResources") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *corev1.Pod) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockContainerManager_PrepareDynamicResources_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PrepareDynamicResources' +type MockContainerManager_PrepareDynamicResources_Call struct { + *mock.Call +} + +// PrepareDynamicResources is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 *corev1.Pod +func (_e *MockContainerManager_Expecter) PrepareDynamicResources(_a0 interface{}, _a1 interface{}) *MockContainerManager_PrepareDynamicResources_Call { + return &MockContainerManager_PrepareDynamicResources_Call{Call: _e.mock.On("PrepareDynamicResources", _a0, _a1)} +} + +func (_c *MockContainerManager_PrepareDynamicResources_Call) Run(run func(_a0 context.Context, _a1 *corev1.Pod)) *MockContainerManager_PrepareDynamicResources_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*corev1.Pod)) + }) + return _c +} + +func (_c *MockContainerManager_PrepareDynamicResources_Call) Return(_a0 error) *MockContainerManager_PrepareDynamicResources_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_PrepareDynamicResources_Call) RunAndReturn(run func(context.Context, *corev1.Pod) error) *MockContainerManager_PrepareDynamicResources_Call { + _c.Call.Return(run) + return _c +} + +// ShouldResetExtendedResourceCapacity provides a mock function with given fields: +func (_m *MockContainerManager) ShouldResetExtendedResourceCapacity() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ShouldResetExtendedResourceCapacity") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// MockContainerManager_ShouldResetExtendedResourceCapacity_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ShouldResetExtendedResourceCapacity' +type MockContainerManager_ShouldResetExtendedResourceCapacity_Call struct { + *mock.Call +} + +// ShouldResetExtendedResourceCapacity is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) ShouldResetExtendedResourceCapacity() *MockContainerManager_ShouldResetExtendedResourceCapacity_Call { + return &MockContainerManager_ShouldResetExtendedResourceCapacity_Call{Call: _e.mock.On("ShouldResetExtendedResourceCapacity")} +} + +func (_c *MockContainerManager_ShouldResetExtendedResourceCapacity_Call) Run(run func()) *MockContainerManager_ShouldResetExtendedResourceCapacity_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_ShouldResetExtendedResourceCapacity_Call) Return(_a0 bool) *MockContainerManager_ShouldResetExtendedResourceCapacity_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_ShouldResetExtendedResourceCapacity_Call) RunAndReturn(run func() bool) *MockContainerManager_ShouldResetExtendedResourceCapacity_Call { + _c.Call.Return(run) + return _c +} + +// Start provides a mock function with given fields: _a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7 +func (_m *MockContainerManager) Start(_a0 context.Context, _a1 *corev1.Node, _a2 cm.ActivePodsFunc, _a3 cm.GetNodeFunc, _a4 config.SourcesReady, _a5 status.PodStatusProvider, _a6 cri.RuntimeService, _a7 bool) error { + ret := _m.Called(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7) + + if len(ret) == 0 { + panic("no return value specified for Start") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *corev1.Node, cm.ActivePodsFunc, cm.GetNodeFunc, config.SourcesReady, status.PodStatusProvider, cri.RuntimeService, bool) error); ok { + r0 = rf(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockContainerManager_Start_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Start' +type MockContainerManager_Start_Call struct { + *mock.Call +} + +// Start is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 *corev1.Node +// - _a2 cm.ActivePodsFunc +// - _a3 cm.GetNodeFunc +// - _a4 config.SourcesReady +// - _a5 status.PodStatusProvider +// - _a6 cri.RuntimeService +// - _a7 bool +func (_e *MockContainerManager_Expecter) Start(_a0 interface{}, _a1 interface{}, _a2 interface{}, _a3 interface{}, _a4 interface{}, _a5 interface{}, _a6 interface{}, _a7 interface{}) *MockContainerManager_Start_Call { + return &MockContainerManager_Start_Call{Call: _e.mock.On("Start", _a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7)} +} + +func (_c *MockContainerManager_Start_Call) Run(run func(_a0 context.Context, _a1 *corev1.Node, _a2 cm.ActivePodsFunc, _a3 cm.GetNodeFunc, _a4 config.SourcesReady, _a5 status.PodStatusProvider, _a6 cri.RuntimeService, _a7 bool)) *MockContainerManager_Start_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*corev1.Node), args[2].(cm.ActivePodsFunc), args[3].(cm.GetNodeFunc), args[4].(config.SourcesReady), args[5].(status.PodStatusProvider), args[6].(cri.RuntimeService), args[7].(bool)) + }) + return _c +} + +func (_c *MockContainerManager_Start_Call) Return(_a0 error) *MockContainerManager_Start_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_Start_Call) RunAndReturn(run func(context.Context, *corev1.Node, cm.ActivePodsFunc, cm.GetNodeFunc, config.SourcesReady, status.PodStatusProvider, cri.RuntimeService, bool) error) *MockContainerManager_Start_Call { + _c.Call.Return(run) + return _c +} + +// Status provides a mock function with given fields: +func (_m *MockContainerManager) Status() cm.Status { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Status") + } + + var r0 cm.Status + if rf, ok := ret.Get(0).(func() cm.Status); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(cm.Status) + } + + return r0 +} + +// MockContainerManager_Status_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Status' +type MockContainerManager_Status_Call struct { + *mock.Call +} + +// Status is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) Status() *MockContainerManager_Status_Call { + return &MockContainerManager_Status_Call{Call: _e.mock.On("Status")} +} + +func (_c *MockContainerManager_Status_Call) Run(run func()) *MockContainerManager_Status_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_Status_Call) Return(_a0 cm.Status) *MockContainerManager_Status_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_Status_Call) RunAndReturn(run func() cm.Status) *MockContainerManager_Status_Call { + _c.Call.Return(run) + return _c +} + +// SystemCgroupsLimit provides a mock function with given fields: +func (_m *MockContainerManager) SystemCgroupsLimit() corev1.ResourceList { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for SystemCgroupsLimit") + } + + var r0 corev1.ResourceList + if rf, ok := ret.Get(0).(func() corev1.ResourceList); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(corev1.ResourceList) + } + } + + return r0 +} + +// MockContainerManager_SystemCgroupsLimit_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SystemCgroupsLimit' +type MockContainerManager_SystemCgroupsLimit_Call struct { + *mock.Call +} + +// SystemCgroupsLimit is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) SystemCgroupsLimit() *MockContainerManager_SystemCgroupsLimit_Call { + return &MockContainerManager_SystemCgroupsLimit_Call{Call: _e.mock.On("SystemCgroupsLimit")} +} + +func (_c *MockContainerManager_SystemCgroupsLimit_Call) Run(run func()) *MockContainerManager_SystemCgroupsLimit_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_SystemCgroupsLimit_Call) Return(_a0 corev1.ResourceList) *MockContainerManager_SystemCgroupsLimit_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_SystemCgroupsLimit_Call) RunAndReturn(run func() corev1.ResourceList) *MockContainerManager_SystemCgroupsLimit_Call { + _c.Call.Return(run) + return _c +} + +// UnprepareDynamicResources provides a mock function with given fields: _a0, _a1 +func (_m *MockContainerManager) UnprepareDynamicResources(_a0 context.Context, _a1 *corev1.Pod) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for UnprepareDynamicResources") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *corev1.Pod) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockContainerManager_UnprepareDynamicResources_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UnprepareDynamicResources' +type MockContainerManager_UnprepareDynamicResources_Call struct { + *mock.Call +} + +// UnprepareDynamicResources is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 *corev1.Pod +func (_e *MockContainerManager_Expecter) UnprepareDynamicResources(_a0 interface{}, _a1 interface{}) *MockContainerManager_UnprepareDynamicResources_Call { + return &MockContainerManager_UnprepareDynamicResources_Call{Call: _e.mock.On("UnprepareDynamicResources", _a0, _a1)} +} + +func (_c *MockContainerManager_UnprepareDynamicResources_Call) Run(run func(_a0 context.Context, _a1 *corev1.Pod)) *MockContainerManager_UnprepareDynamicResources_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*corev1.Pod)) + }) + return _c +} + +func (_c *MockContainerManager_UnprepareDynamicResources_Call) Return(_a0 error) *MockContainerManager_UnprepareDynamicResources_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_UnprepareDynamicResources_Call) RunAndReturn(run func(context.Context, *corev1.Pod) error) *MockContainerManager_UnprepareDynamicResources_Call { + _c.Call.Return(run) + return _c +} + +// UpdateAllocatedDevices provides a mock function with given fields: +func (_m *MockContainerManager) UpdateAllocatedDevices() { + _m.Called() +} + +// MockContainerManager_UpdateAllocatedDevices_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateAllocatedDevices' +type MockContainerManager_UpdateAllocatedDevices_Call struct { + *mock.Call +} + +// UpdateAllocatedDevices is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) UpdateAllocatedDevices() *MockContainerManager_UpdateAllocatedDevices_Call { + return &MockContainerManager_UpdateAllocatedDevices_Call{Call: _e.mock.On("UpdateAllocatedDevices")} +} + +func (_c *MockContainerManager_UpdateAllocatedDevices_Call) Run(run func()) *MockContainerManager_UpdateAllocatedDevices_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_UpdateAllocatedDevices_Call) Return() *MockContainerManager_UpdateAllocatedDevices_Call { + _c.Call.Return() + return _c +} + +func (_c *MockContainerManager_UpdateAllocatedDevices_Call) RunAndReturn(run func()) *MockContainerManager_UpdateAllocatedDevices_Call { + _c.Call.Return(run) + return _c +} + +// UpdateAllocatedResourcesStatus provides a mock function with given fields: pod, _a1 +func (_m *MockContainerManager) UpdateAllocatedResourcesStatus(pod *corev1.Pod, _a1 *corev1.PodStatus) { + _m.Called(pod, _a1) +} + +// MockContainerManager_UpdateAllocatedResourcesStatus_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateAllocatedResourcesStatus' +type MockContainerManager_UpdateAllocatedResourcesStatus_Call struct { + *mock.Call +} + +// UpdateAllocatedResourcesStatus is a helper method to define mock.On call +// - pod *corev1.Pod +// - _a1 *corev1.PodStatus +func (_e *MockContainerManager_Expecter) UpdateAllocatedResourcesStatus(pod interface{}, _a1 interface{}) *MockContainerManager_UpdateAllocatedResourcesStatus_Call { + return &MockContainerManager_UpdateAllocatedResourcesStatus_Call{Call: _e.mock.On("UpdateAllocatedResourcesStatus", pod, _a1)} +} + +func (_c *MockContainerManager_UpdateAllocatedResourcesStatus_Call) Run(run func(pod *corev1.Pod, _a1 *corev1.PodStatus)) *MockContainerManager_UpdateAllocatedResourcesStatus_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*corev1.Pod), args[1].(*corev1.PodStatus)) + }) + return _c +} + +func (_c *MockContainerManager_UpdateAllocatedResourcesStatus_Call) Return() *MockContainerManager_UpdateAllocatedResourcesStatus_Call { + _c.Call.Return() + return _c +} + +func (_c *MockContainerManager_UpdateAllocatedResourcesStatus_Call) RunAndReturn(run func(*corev1.Pod, *corev1.PodStatus)) *MockContainerManager_UpdateAllocatedResourcesStatus_Call { + _c.Call.Return(run) + return _c +} + +// UpdatePluginResources provides a mock function with given fields: _a0, _a1 +func (_m *MockContainerManager) UpdatePluginResources(_a0 *framework.NodeInfo, _a1 *lifecycle.PodAdmitAttributes) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for UpdatePluginResources") + } + + var r0 error + if rf, ok := ret.Get(0).(func(*framework.NodeInfo, *lifecycle.PodAdmitAttributes) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockContainerManager_UpdatePluginResources_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdatePluginResources' +type MockContainerManager_UpdatePluginResources_Call struct { + *mock.Call +} + +// UpdatePluginResources is a helper method to define mock.On call +// - _a0 *framework.NodeInfo +// - _a1 *lifecycle.PodAdmitAttributes +func (_e *MockContainerManager_Expecter) UpdatePluginResources(_a0 interface{}, _a1 interface{}) *MockContainerManager_UpdatePluginResources_Call { + return &MockContainerManager_UpdatePluginResources_Call{Call: _e.mock.On("UpdatePluginResources", _a0, _a1)} +} + +func (_c *MockContainerManager_UpdatePluginResources_Call) Run(run func(_a0 *framework.NodeInfo, _a1 *lifecycle.PodAdmitAttributes)) *MockContainerManager_UpdatePluginResources_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*framework.NodeInfo), args[1].(*lifecycle.PodAdmitAttributes)) + }) + return _c +} + +func (_c *MockContainerManager_UpdatePluginResources_Call) Return(_a0 error) *MockContainerManager_UpdatePluginResources_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_UpdatePluginResources_Call) RunAndReturn(run func(*framework.NodeInfo, *lifecycle.PodAdmitAttributes) error) *MockContainerManager_UpdatePluginResources_Call { + _c.Call.Return(run) + return _c +} + +// UpdateQOSCgroups provides a mock function with given fields: +func (_m *MockContainerManager) UpdateQOSCgroups() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for UpdateQOSCgroups") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockContainerManager_UpdateQOSCgroups_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateQOSCgroups' +type MockContainerManager_UpdateQOSCgroups_Call struct { + *mock.Call +} + +// UpdateQOSCgroups is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) UpdateQOSCgroups() *MockContainerManager_UpdateQOSCgroups_Call { + return &MockContainerManager_UpdateQOSCgroups_Call{Call: _e.mock.On("UpdateQOSCgroups")} +} + +func (_c *MockContainerManager_UpdateQOSCgroups_Call) Run(run func()) *MockContainerManager_UpdateQOSCgroups_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_UpdateQOSCgroups_Call) Return(_a0 error) *MockContainerManager_UpdateQOSCgroups_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_UpdateQOSCgroups_Call) RunAndReturn(run func() error) *MockContainerManager_UpdateQOSCgroups_Call { + _c.Call.Return(run) + return _c +} + +// Updates provides a mock function with given fields: +func (_m *MockContainerManager) Updates() <-chan resourceupdates.Update { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Updates") + } + + var r0 <-chan resourceupdates.Update + if rf, ok := ret.Get(0).(func() <-chan resourceupdates.Update); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(<-chan resourceupdates.Update) + } + } + + return r0 +} + +// MockContainerManager_Updates_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Updates' +type MockContainerManager_Updates_Call struct { + *mock.Call +} + +// Updates is a helper method to define mock.On call +func (_e *MockContainerManager_Expecter) Updates() *MockContainerManager_Updates_Call { + return &MockContainerManager_Updates_Call{Call: _e.mock.On("Updates")} +} + +func (_c *MockContainerManager_Updates_Call) Run(run func()) *MockContainerManager_Updates_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockContainerManager_Updates_Call) Return(_a0 <-chan resourceupdates.Update) *MockContainerManager_Updates_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockContainerManager_Updates_Call) RunAndReturn(run func() <-chan resourceupdates.Update) *MockContainerManager_Updates_Call { + _c.Call.Return(run) + return _c +} + +// NewMockContainerManager creates a new instance of MockContainerManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockContainerManager(t interface { + mock.TestingT + Cleanup(func()) +}) *MockContainerManager { + mock := &MockContainerManager{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/kubelet/cm/testing/mock_pod_container_manager.go b/pkg/kubelet/cm/testing/mock_pod_container_manager.go new file mode 100644 index 00000000000..a32b9b5c99f --- /dev/null +++ b/pkg/kubelet/cm/testing/mock_pod_container_manager.go @@ -0,0 +1,572 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by mockery v2.40.3. DO NOT EDIT. + +package testing + +import ( + mock "github.com/stretchr/testify/mock" + cm "k8s.io/kubernetes/pkg/kubelet/cm" + + types "k8s.io/apimachinery/pkg/types" + + v1 "k8s.io/api/core/v1" +) + +// MockPodContainerManager is an autogenerated mock type for the PodContainerManager type +type MockPodContainerManager struct { + mock.Mock +} + +type MockPodContainerManager_Expecter struct { + mock *mock.Mock +} + +func (_m *MockPodContainerManager) EXPECT() *MockPodContainerManager_Expecter { + return &MockPodContainerManager_Expecter{mock: &_m.Mock} +} + +// Destroy provides a mock function with given fields: name +func (_m *MockPodContainerManager) Destroy(name cm.CgroupName) error { + ret := _m.Called(name) + + if len(ret) == 0 { + panic("no return value specified for Destroy") + } + + var r0 error + if rf, ok := ret.Get(0).(func(cm.CgroupName) error); ok { + r0 = rf(name) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockPodContainerManager_Destroy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Destroy' +type MockPodContainerManager_Destroy_Call struct { + *mock.Call +} + +// Destroy is a helper method to define mock.On call +// - name cm.CgroupName +func (_e *MockPodContainerManager_Expecter) Destroy(name interface{}) *MockPodContainerManager_Destroy_Call { + return &MockPodContainerManager_Destroy_Call{Call: _e.mock.On("Destroy", name)} +} + +func (_c *MockPodContainerManager_Destroy_Call) Run(run func(name cm.CgroupName)) *MockPodContainerManager_Destroy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(cm.CgroupName)) + }) + return _c +} + +func (_c *MockPodContainerManager_Destroy_Call) Return(_a0 error) *MockPodContainerManager_Destroy_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPodContainerManager_Destroy_Call) RunAndReturn(run func(cm.CgroupName) error) *MockPodContainerManager_Destroy_Call { + _c.Call.Return(run) + return _c +} + +// EnsureExists provides a mock function with given fields: _a0 +func (_m *MockPodContainerManager) EnsureExists(_a0 *v1.Pod) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for EnsureExists") + } + + var r0 error + if rf, ok := ret.Get(0).(func(*v1.Pod) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockPodContainerManager_EnsureExists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'EnsureExists' +type MockPodContainerManager_EnsureExists_Call struct { + *mock.Call +} + +// EnsureExists is a helper method to define mock.On call +// - _a0 *v1.Pod +func (_e *MockPodContainerManager_Expecter) EnsureExists(_a0 interface{}) *MockPodContainerManager_EnsureExists_Call { + return &MockPodContainerManager_EnsureExists_Call{Call: _e.mock.On("EnsureExists", _a0)} +} + +func (_c *MockPodContainerManager_EnsureExists_Call) Run(run func(_a0 *v1.Pod)) *MockPodContainerManager_EnsureExists_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*v1.Pod)) + }) + return _c +} + +func (_c *MockPodContainerManager_EnsureExists_Call) Return(_a0 error) *MockPodContainerManager_EnsureExists_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPodContainerManager_EnsureExists_Call) RunAndReturn(run func(*v1.Pod) error) *MockPodContainerManager_EnsureExists_Call { + _c.Call.Return(run) + return _c +} + +// Exists provides a mock function with given fields: _a0 +func (_m *MockPodContainerManager) Exists(_a0 *v1.Pod) bool { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Exists") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(*v1.Pod) bool); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// MockPodContainerManager_Exists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Exists' +type MockPodContainerManager_Exists_Call struct { + *mock.Call +} + +// Exists is a helper method to define mock.On call +// - _a0 *v1.Pod +func (_e *MockPodContainerManager_Expecter) Exists(_a0 interface{}) *MockPodContainerManager_Exists_Call { + return &MockPodContainerManager_Exists_Call{Call: _e.mock.On("Exists", _a0)} +} + +func (_c *MockPodContainerManager_Exists_Call) Run(run func(_a0 *v1.Pod)) *MockPodContainerManager_Exists_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*v1.Pod)) + }) + return _c +} + +func (_c *MockPodContainerManager_Exists_Call) Return(_a0 bool) *MockPodContainerManager_Exists_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPodContainerManager_Exists_Call) RunAndReturn(run func(*v1.Pod) bool) *MockPodContainerManager_Exists_Call { + _c.Call.Return(run) + return _c +} + +// GetAllPodsFromCgroups provides a mock function with given fields: +func (_m *MockPodContainerManager) GetAllPodsFromCgroups() (map[types.UID]cm.CgroupName, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetAllPodsFromCgroups") + } + + var r0 map[types.UID]cm.CgroupName + var r1 error + if rf, ok := ret.Get(0).(func() (map[types.UID]cm.CgroupName, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() map[types.UID]cm.CgroupName); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[types.UID]cm.CgroupName) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockPodContainerManager_GetAllPodsFromCgroups_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllPodsFromCgroups' +type MockPodContainerManager_GetAllPodsFromCgroups_Call struct { + *mock.Call +} + +// GetAllPodsFromCgroups is a helper method to define mock.On call +func (_e *MockPodContainerManager_Expecter) GetAllPodsFromCgroups() *MockPodContainerManager_GetAllPodsFromCgroups_Call { + return &MockPodContainerManager_GetAllPodsFromCgroups_Call{Call: _e.mock.On("GetAllPodsFromCgroups")} +} + +func (_c *MockPodContainerManager_GetAllPodsFromCgroups_Call) Run(run func()) *MockPodContainerManager_GetAllPodsFromCgroups_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockPodContainerManager_GetAllPodsFromCgroups_Call) Return(_a0 map[types.UID]cm.CgroupName, _a1 error) *MockPodContainerManager_GetAllPodsFromCgroups_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPodContainerManager_GetAllPodsFromCgroups_Call) RunAndReturn(run func() (map[types.UID]cm.CgroupName, error)) *MockPodContainerManager_GetAllPodsFromCgroups_Call { + _c.Call.Return(run) + return _c +} + +// GetPodCgroupConfig provides a mock function with given fields: pod, resource +func (_m *MockPodContainerManager) GetPodCgroupConfig(pod *v1.Pod, resource v1.ResourceName) (*cm.ResourceConfig, error) { + ret := _m.Called(pod, resource) + + if len(ret) == 0 { + panic("no return value specified for GetPodCgroupConfig") + } + + var r0 *cm.ResourceConfig + var r1 error + if rf, ok := ret.Get(0).(func(*v1.Pod, v1.ResourceName) (*cm.ResourceConfig, error)); ok { + return rf(pod, resource) + } + if rf, ok := ret.Get(0).(func(*v1.Pod, v1.ResourceName) *cm.ResourceConfig); ok { + r0 = rf(pod, resource) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*cm.ResourceConfig) + } + } + + if rf, ok := ret.Get(1).(func(*v1.Pod, v1.ResourceName) error); ok { + r1 = rf(pod, resource) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockPodContainerManager_GetPodCgroupConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodCgroupConfig' +type MockPodContainerManager_GetPodCgroupConfig_Call struct { + *mock.Call +} + +// GetPodCgroupConfig is a helper method to define mock.On call +// - pod *v1.Pod +// - resource v1.ResourceName +func (_e *MockPodContainerManager_Expecter) GetPodCgroupConfig(pod interface{}, resource interface{}) *MockPodContainerManager_GetPodCgroupConfig_Call { + return &MockPodContainerManager_GetPodCgroupConfig_Call{Call: _e.mock.On("GetPodCgroupConfig", pod, resource)} +} + +func (_c *MockPodContainerManager_GetPodCgroupConfig_Call) Run(run func(pod *v1.Pod, resource v1.ResourceName)) *MockPodContainerManager_GetPodCgroupConfig_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*v1.Pod), args[1].(v1.ResourceName)) + }) + return _c +} + +func (_c *MockPodContainerManager_GetPodCgroupConfig_Call) Return(_a0 *cm.ResourceConfig, _a1 error) *MockPodContainerManager_GetPodCgroupConfig_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPodContainerManager_GetPodCgroupConfig_Call) RunAndReturn(run func(*v1.Pod, v1.ResourceName) (*cm.ResourceConfig, error)) *MockPodContainerManager_GetPodCgroupConfig_Call { + _c.Call.Return(run) + return _c +} + +// GetPodCgroupMemoryUsage provides a mock function with given fields: pod +func (_m *MockPodContainerManager) GetPodCgroupMemoryUsage(pod *v1.Pod) (uint64, error) { + ret := _m.Called(pod) + + if len(ret) == 0 { + panic("no return value specified for GetPodCgroupMemoryUsage") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(*v1.Pod) (uint64, error)); ok { + return rf(pod) + } + if rf, ok := ret.Get(0).(func(*v1.Pod) uint64); ok { + r0 = rf(pod) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(*v1.Pod) error); ok { + r1 = rf(pod) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockPodContainerManager_GetPodCgroupMemoryUsage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodCgroupMemoryUsage' +type MockPodContainerManager_GetPodCgroupMemoryUsage_Call struct { + *mock.Call +} + +// GetPodCgroupMemoryUsage is a helper method to define mock.On call +// - pod *v1.Pod +func (_e *MockPodContainerManager_Expecter) GetPodCgroupMemoryUsage(pod interface{}) *MockPodContainerManager_GetPodCgroupMemoryUsage_Call { + return &MockPodContainerManager_GetPodCgroupMemoryUsage_Call{Call: _e.mock.On("GetPodCgroupMemoryUsage", pod)} +} + +func (_c *MockPodContainerManager_GetPodCgroupMemoryUsage_Call) Run(run func(pod *v1.Pod)) *MockPodContainerManager_GetPodCgroupMemoryUsage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*v1.Pod)) + }) + return _c +} + +func (_c *MockPodContainerManager_GetPodCgroupMemoryUsage_Call) Return(_a0 uint64, _a1 error) *MockPodContainerManager_GetPodCgroupMemoryUsage_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPodContainerManager_GetPodCgroupMemoryUsage_Call) RunAndReturn(run func(*v1.Pod) (uint64, error)) *MockPodContainerManager_GetPodCgroupMemoryUsage_Call { + _c.Call.Return(run) + return _c +} + +// GetPodContainerName provides a mock function with given fields: _a0 +func (_m *MockPodContainerManager) GetPodContainerName(_a0 *v1.Pod) (cm.CgroupName, string) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for GetPodContainerName") + } + + var r0 cm.CgroupName + var r1 string + if rf, ok := ret.Get(0).(func(*v1.Pod) (cm.CgroupName, string)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(*v1.Pod) cm.CgroupName); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(cm.CgroupName) + } + } + + if rf, ok := ret.Get(1).(func(*v1.Pod) string); ok { + r1 = rf(_a0) + } else { + r1 = ret.Get(1).(string) + } + + return r0, r1 +} + +// MockPodContainerManager_GetPodContainerName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPodContainerName' +type MockPodContainerManager_GetPodContainerName_Call struct { + *mock.Call +} + +// GetPodContainerName is a helper method to define mock.On call +// - _a0 *v1.Pod +func (_e *MockPodContainerManager_Expecter) GetPodContainerName(_a0 interface{}) *MockPodContainerManager_GetPodContainerName_Call { + return &MockPodContainerManager_GetPodContainerName_Call{Call: _e.mock.On("GetPodContainerName", _a0)} +} + +func (_c *MockPodContainerManager_GetPodContainerName_Call) Run(run func(_a0 *v1.Pod)) *MockPodContainerManager_GetPodContainerName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*v1.Pod)) + }) + return _c +} + +func (_c *MockPodContainerManager_GetPodContainerName_Call) Return(_a0 cm.CgroupName, _a1 string) *MockPodContainerManager_GetPodContainerName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPodContainerManager_GetPodContainerName_Call) RunAndReturn(run func(*v1.Pod) (cm.CgroupName, string)) *MockPodContainerManager_GetPodContainerName_Call { + _c.Call.Return(run) + return _c +} + +// IsPodCgroup provides a mock function with given fields: cgroupfs +func (_m *MockPodContainerManager) IsPodCgroup(cgroupfs string) (bool, types.UID) { + ret := _m.Called(cgroupfs) + + if len(ret) == 0 { + panic("no return value specified for IsPodCgroup") + } + + var r0 bool + var r1 types.UID + if rf, ok := ret.Get(0).(func(string) (bool, types.UID)); ok { + return rf(cgroupfs) + } + if rf, ok := ret.Get(0).(func(string) bool); ok { + r0 = rf(cgroupfs) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(string) types.UID); ok { + r1 = rf(cgroupfs) + } else { + r1 = ret.Get(1).(types.UID) + } + + return r0, r1 +} + +// MockPodContainerManager_IsPodCgroup_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsPodCgroup' +type MockPodContainerManager_IsPodCgroup_Call struct { + *mock.Call +} + +// IsPodCgroup is a helper method to define mock.On call +// - cgroupfs string +func (_e *MockPodContainerManager_Expecter) IsPodCgroup(cgroupfs interface{}) *MockPodContainerManager_IsPodCgroup_Call { + return &MockPodContainerManager_IsPodCgroup_Call{Call: _e.mock.On("IsPodCgroup", cgroupfs)} +} + +func (_c *MockPodContainerManager_IsPodCgroup_Call) Run(run func(cgroupfs string)) *MockPodContainerManager_IsPodCgroup_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockPodContainerManager_IsPodCgroup_Call) Return(_a0 bool, _a1 types.UID) *MockPodContainerManager_IsPodCgroup_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPodContainerManager_IsPodCgroup_Call) RunAndReturn(run func(string) (bool, types.UID)) *MockPodContainerManager_IsPodCgroup_Call { + _c.Call.Return(run) + return _c +} + +// ReduceCPULimits provides a mock function with given fields: name +func (_m *MockPodContainerManager) ReduceCPULimits(name cm.CgroupName) error { + ret := _m.Called(name) + + if len(ret) == 0 { + panic("no return value specified for ReduceCPULimits") + } + + var r0 error + if rf, ok := ret.Get(0).(func(cm.CgroupName) error); ok { + r0 = rf(name) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockPodContainerManager_ReduceCPULimits_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReduceCPULimits' +type MockPodContainerManager_ReduceCPULimits_Call struct { + *mock.Call +} + +// ReduceCPULimits is a helper method to define mock.On call +// - name cm.CgroupName +func (_e *MockPodContainerManager_Expecter) ReduceCPULimits(name interface{}) *MockPodContainerManager_ReduceCPULimits_Call { + return &MockPodContainerManager_ReduceCPULimits_Call{Call: _e.mock.On("ReduceCPULimits", name)} +} + +func (_c *MockPodContainerManager_ReduceCPULimits_Call) Run(run func(name cm.CgroupName)) *MockPodContainerManager_ReduceCPULimits_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(cm.CgroupName)) + }) + return _c +} + +func (_c *MockPodContainerManager_ReduceCPULimits_Call) Return(_a0 error) *MockPodContainerManager_ReduceCPULimits_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPodContainerManager_ReduceCPULimits_Call) RunAndReturn(run func(cm.CgroupName) error) *MockPodContainerManager_ReduceCPULimits_Call { + _c.Call.Return(run) + return _c +} + +// SetPodCgroupConfig provides a mock function with given fields: pod, resourceConfig +func (_m *MockPodContainerManager) SetPodCgroupConfig(pod *v1.Pod, resourceConfig *cm.ResourceConfig) error { + ret := _m.Called(pod, resourceConfig) + + if len(ret) == 0 { + panic("no return value specified for SetPodCgroupConfig") + } + + var r0 error + if rf, ok := ret.Get(0).(func(*v1.Pod, *cm.ResourceConfig) error); ok { + r0 = rf(pod, resourceConfig) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockPodContainerManager_SetPodCgroupConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetPodCgroupConfig' +type MockPodContainerManager_SetPodCgroupConfig_Call struct { + *mock.Call +} + +// SetPodCgroupConfig is a helper method to define mock.On call +// - pod *v1.Pod +// - resourceConfig *cm.ResourceConfig +func (_e *MockPodContainerManager_Expecter) SetPodCgroupConfig(pod interface{}, resourceConfig interface{}) *MockPodContainerManager_SetPodCgroupConfig_Call { + return &MockPodContainerManager_SetPodCgroupConfig_Call{Call: _e.mock.On("SetPodCgroupConfig", pod, resourceConfig)} +} + +func (_c *MockPodContainerManager_SetPodCgroupConfig_Call) Run(run func(pod *v1.Pod, resourceConfig *cm.ResourceConfig)) *MockPodContainerManager_SetPodCgroupConfig_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*v1.Pod), args[1].(*cm.ResourceConfig)) + }) + return _c +} + +func (_c *MockPodContainerManager_SetPodCgroupConfig_Call) Return(_a0 error) *MockPodContainerManager_SetPodCgroupConfig_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPodContainerManager_SetPodCgroupConfig_Call) RunAndReturn(run func(*v1.Pod, *cm.ResourceConfig) error) *MockPodContainerManager_SetPodCgroupConfig_Call { + _c.Call.Return(run) + return _c +} + +// NewMockPodContainerManager creates a new instance of MockPodContainerManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockPodContainerManager(t interface { + mock.TestingT + Cleanup(func()) +}) *MockPodContainerManager { + mock := &MockPodContainerManager{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/kubelet/kubelet_pods.go b/pkg/kubelet/kubelet_pods.go index c4861648f44..5dcc3c2085d 100644 --- a/pkg/kubelet/kubelet_pods.go +++ b/pkg/kubelet/kubelet_pods.go @@ -1791,19 +1791,31 @@ func allocatedResourcesMatchStatus(allocatedPod *v1.Pod, podStatus *kubecontaine // Only compare resizeable resources, and only compare resources that are explicitly configured. if hasCPUReq { - // If both allocated & status CPU requests are at or below MinShares then they are considered equal. - if !cpuReq.Equal(*cs.Resources.CPURequest) && + if cs.Resources.CPURequest == nil { + if !cpuReq.IsZero() { + return false + } + } else if !cpuReq.Equal(*cs.Resources.CPURequest) && (cpuReq.MilliValue() > cm.MinShares || cs.Resources.CPURequest.MilliValue() > cm.MinShares) { + // If both allocated & status CPU requests are at or below MinShares then they are considered equal. return false } } if hasCPULim { - if !cpuLim.Equal(*cs.Resources.CPULimit) { + if cs.Resources.CPULimit == nil { + if !cpuLim.IsZero() { + return false + } + } else if !cpuLim.Equal(*cs.Resources.CPULimit) { return false } } if hasMemLim { - if !memLim.Equal(*cs.Resources.MemoryLimit) { + if cs.Resources.MemoryLimit == nil { + if !memLim.IsZero() { + return false + } + } else if !memLim.Equal(*cs.Resources.MemoryLimit) { return false } } diff --git a/pkg/kubelet/kubelet_pods_test.go b/pkg/kubelet/kubelet_pods_test.go index c7dd26647e3..22e1a6ea61a 100644 --- a/pkg/kubelet/kubelet_pods_test.go +++ b/pkg/kubelet/kubelet_pods_test.go @@ -6797,6 +6797,38 @@ func TestAllocatedResourcesMatchStatus(t *testing.T) { CPURequest: resource.NewMilliQuantity(2, resource.DecimalSI), }, expectMatch: true, + }, { + name: "nil status resources: cpu request mismatch", + allocatedResources: v1.ResourceRequirements{ + Requests: v1.ResourceList{ + v1.ResourceCPU: resource.MustParse("100m"), + }, + }, + statusResources: &kubecontainer.ContainerResources{}, + expectMatch: false, + }, { + name: "nil status resources: cpu limit mismatch", + allocatedResources: v1.ResourceRequirements{ + Requests: v1.ResourceList{ + v1.ResourceCPU: resource.MustParse("100m"), + }, + Limits: v1.ResourceList{ + v1.ResourceCPU: resource.MustParse("100m"), + }, + }, + statusResources: &kubecontainer.ContainerResources{ + CPURequest: resource.NewMilliQuantity(2, resource.DecimalSI), + }, + expectMatch: false, + }, { + name: "nil status resources: memory limit mismatch", + allocatedResources: v1.ResourceRequirements{ + Limits: v1.ResourceList{ + v1.ResourceMemory: resource.MustParse("100M"), + }, + }, + statusResources: &kubecontainer.ContainerResources{}, + expectMatch: false, }} for _, test := range tests { diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager.go b/pkg/kubelet/kuberuntime/kuberuntime_manager.go index 6f96a3e2895..55b1fb04166 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager.go @@ -584,8 +584,10 @@ func (m *kubeGenericRuntimeManager) computePodResizeAction(pod *v1.Pod, containe cpuRequest: container.Resources.Requests.Cpu().MilliValue(), } - // Default current values to the desired values so that a resize isn't triggered for missing values. - currentResources := desiredResources + currentResources := containerResources{ + // memoryRequest isn't set by the runtime, so default it to the desired. + memoryRequest: desiredResources.memoryRequest, + } if kubeContainerStatus.Resources.MemoryLimit != nil { currentResources.memoryLimit = kubeContainerStatus.Resources.MemoryLimit.Value() } @@ -666,7 +668,7 @@ func (m *kubeGenericRuntimeManager) computePodResizeAction(pod *v1.Pod, containe return true } -func (m *kubeGenericRuntimeManager) doPodResizeAction(pod *v1.Pod, podStatus *kubecontainer.PodStatus, podContainerChanges podActions, result kubecontainer.PodSyncResult) { +func (m *kubeGenericRuntimeManager) doPodResizeAction(pod *v1.Pod, podContainerChanges podActions, result *kubecontainer.PodSyncResult) { pcm := m.containerManager.NewPodContainerManager() //TODO(vinaykul,InPlacePodVerticalScaling): Figure out best way to get enforceMemoryQoS value (parameter #4 below) in platform-agnostic way podResources := cm.ResourceConfigForPod(pod, m.cpuCFSQuota, uint64((m.cpuCFSQuotaPeriod.Duration)/time.Microsecond), false) @@ -688,7 +690,14 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(pod *v1.Pod, podStatus *ku } err = pcm.SetPodCgroupConfig(pod, podCPUResources) case v1.ResourceMemory: - err = pcm.SetPodCgroupConfig(pod, podResources) + if !setLimitValue { + // Memory requests aren't written to cgroups. + return nil + } + podMemoryResources := &cm.ResourceConfig{ + Memory: podResources.Memory, + } + err = pcm.SetPodCgroupConfig(pod, podMemoryResources) } if err != nil { klog.ErrorS(err, "Failed to set cgroup config", "resource", rName, "pod", pod.Name) @@ -732,27 +741,28 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(pod *v1.Pod, podStatus *ku return err } if len(podContainerChanges.ContainersToUpdate[v1.ResourceMemory]) > 0 || podContainerChanges.UpdatePodResources { - if podResources.Memory == nil { - klog.ErrorS(nil, "podResources.Memory is nil", "pod", pod.Name) - result.Fail(fmt.Errorf("podResources.Memory is nil for pod %s", pod.Name)) - return - } currentPodMemoryConfig, err := pcm.GetPodCgroupConfig(pod, v1.ResourceMemory) if err != nil { klog.ErrorS(err, "GetPodCgroupConfig for memory failed", "pod", pod.Name) result.Fail(err) return } - currentPodMemoryUsage, err := pcm.GetPodCgroupMemoryUsage(pod) - if err != nil { - klog.ErrorS(err, "GetPodCgroupMemoryUsage failed", "pod", pod.Name) - result.Fail(err) - return - } - if currentPodMemoryUsage >= uint64(*podResources.Memory) { - klog.ErrorS(nil, "Aborting attempt to set pod memory limit less than current memory usage", "pod", pod.Name) - result.Fail(fmt.Errorf("aborting attempt to set pod memory limit less than current memory usage for pod %s", pod.Name)) - return + if podResources.Memory != nil { + currentPodMemoryUsage, err := pcm.GetPodCgroupMemoryUsage(pod) + if err != nil { + klog.ErrorS(err, "GetPodCgroupMemoryUsage failed", "pod", pod.Name) + result.Fail(err) + return + } + if currentPodMemoryUsage >= uint64(*podResources.Memory) { + klog.ErrorS(nil, "Aborting attempt to set pod memory limit less than current memory usage", "pod", pod.Name) + result.Fail(fmt.Errorf("aborting attempt to set pod memory limit less than current memory usage for pod %s", pod.Name)) + return + } + } else { + // Default pod memory limit to the current memory limit if unset to prevent it from updating. + // TODO(#128675): This does not support removing limits. + podResources.Memory = currentPodMemoryConfig.Memory } if errResize := resizeContainers(v1.ResourceMemory, int64(*currentPodMemoryConfig.Memory), *podResources.Memory, 0, 0); errResize != nil { result.Fail(errResize) @@ -760,9 +770,10 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(pod *v1.Pod, podStatus *ku } } if len(podContainerChanges.ContainersToUpdate[v1.ResourceCPU]) > 0 || podContainerChanges.UpdatePodResources { - if podResources.CPUQuota == nil || podResources.CPUShares == nil { - klog.ErrorS(nil, "podResources.CPUQuota or podResources.CPUShares is nil", "pod", pod.Name) - result.Fail(fmt.Errorf("podResources.CPUQuota or podResources.CPUShares is nil for pod %s", pod.Name)) + if podResources.CPUShares == nil { + // This shouldn't happen: ResourceConfigForPod always returns a non-nil value for CPUShares. + klog.ErrorS(nil, "podResources.CPUShares is nil", "pod", pod.Name) + result.Fail(fmt.Errorf("podResources.CPUShares is nil for pod %s", pod.Name)) return } currentPodCpuConfig, err := pcm.GetPodCgroupConfig(pod, v1.ResourceCPU) @@ -771,6 +782,13 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(pod *v1.Pod, podStatus *ku result.Fail(err) return } + + // Default pod CPUQuota to the current CPUQuota if no limit is set to prevent the pod limit + // from updating. + // TODO(#128675): This does not support removing limits. + if podResources.CPUQuota == nil { + podResources.CPUQuota = currentPodCpuConfig.CPUQuota + } if errResize := resizeContainers(v1.ResourceCPU, *currentPodCpuConfig.CPUQuota, *podResources.CPUQuota, int64(*currentPodCpuConfig.CPUShares), int64(*podResources.CPUShares)); errResize != nil { result.Fail(errResize) @@ -823,16 +841,21 @@ func (m *kubeGenericRuntimeManager) updatePodContainerResources(pod *v1.Pod, res } switch resourceName { case v1.ResourceMemory: - return status.Resources.MemoryLimit.Equal(*container.Resources.Limits.Memory()) + actualLimit := nonNilQuantity(status.Resources.MemoryLimit) + return actualLimit.Equal(*container.Resources.Limits.Memory()) case v1.ResourceCPU: - if !status.Resources.CPULimit.Equal(*container.Resources.Limits.Cpu()) { + actualLimit := nonNilQuantity(status.Resources.CPULimit) + actualRequest := nonNilQuantity(status.Resources.CPURequest) + desiredLimit := container.Resources.Limits.Cpu() + desiredRequest := container.Resources.Requests.Cpu() + if !actualLimit.Equal(*desiredLimit) { return false // limits don't match - } else if status.Resources.CPURequest.Equal(*container.Resources.Requests.Cpu()) { + } else if actualRequest.Equal(*desiredRequest) { return true // requests & limits both match } // Consider requests equal if both are at or below MinShares. - return status.Resources.CPURequest.MilliValue() <= cm.MinShares && - container.Resources.Requests.Cpu().MilliValue() <= cm.MinShares + return actualRequest.MilliValue() <= cm.MinShares && + desiredRequest.MilliValue() <= cm.MinShares default: return true // Shouldn't happen. } @@ -854,6 +877,15 @@ func (m *kubeGenericRuntimeManager) updatePodContainerResources(pod *v1.Pod, res return nil } +// nonNilQuantity returns a non-nil quantity. If the input is non-nil, it is returned. Otherwise a +// pointer to the zero value is returned. +func nonNilQuantity(q *resource.Quantity) *resource.Quantity { + if q != nil { + return q + } + return &resource.Quantity{} +} + // computePodActions checks whether the pod spec has changed and returns the changes if true. func (m *kubeGenericRuntimeManager) computePodActions(ctx context.Context, pod *v1.Pod, podStatus *kubecontainer.PodStatus) podActions { klog.V(5).InfoS("Syncing Pod", "pod", klog.KObj(pod)) @@ -1351,7 +1383,7 @@ func (m *kubeGenericRuntimeManager) SyncPod(ctx context.Context, pod *v1.Pod, po // Step 7: For containers in podContainerChanges.ContainersToUpdate[CPU,Memory] list, invoke UpdateContainerResources if IsInPlacePodVerticalScalingAllowed(pod) { if len(podContainerChanges.ContainersToUpdate) > 0 || podContainerChanges.UpdatePodResources { - m.doPodResizeAction(pod, podStatus, podContainerChanges, result) + m.doPodResizeAction(pod, podContainerChanges, &result) } } diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager_test.go b/pkg/kubelet/kuberuntime/kuberuntime_manager_test.go index 9baaf1a3608..7bc23bfaf83 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager_test.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager_test.go @@ -22,6 +22,7 @@ import ( "fmt" "path/filepath" "reflect" + goruntime "runtime" "sort" "testing" "time" @@ -31,6 +32,7 @@ import ( cadvisorapi "github.com/google/cadvisor/info/v1" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" noopoteltrace "go.opentelemetry.io/otel/trace/noop" @@ -47,6 +49,8 @@ import ( podutil "k8s.io/kubernetes/pkg/api/v1/pod" "k8s.io/kubernetes/pkg/credentialprovider" "k8s.io/kubernetes/pkg/features" + "k8s.io/kubernetes/pkg/kubelet/cm" + cmtesting "k8s.io/kubernetes/pkg/kubelet/cm/testing" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" containertest "k8s.io/kubernetes/pkg/kubelet/container/testing" imagetypes "k8s.io/kubernetes/pkg/kubelet/images" @@ -2826,3 +2830,197 @@ func TestGetImageVolumes(t *testing.T) { assert.Equal(t, tc.expectedImageVolumePulls, imageVolumePulls) } } + +func TestDoPodResizeAction(t *testing.T) { + if goruntime.GOOS != "linux" { + t.Skip("unsupported OS") + } + + featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.InPlacePodVerticalScaling, true) + _, _, m, err := createTestRuntimeManager() + require.NoError(t, err) + m.cpuCFSQuota = true // Enforce CPU Limits + + for _, tc := range []struct { + testName string + currentResources containerResources + desiredResources containerResources + updatedResources []v1.ResourceName + otherContainersHaveLimits bool + expectedError string + expectPodCgroupUpdates int + }{ + { + testName: "Increase cpu and memory requests and limits, with computed pod limits", + currentResources: containerResources{ + cpuRequest: 100, cpuLimit: 100, + memoryRequest: 100, memoryLimit: 100, + }, + desiredResources: containerResources{ + cpuRequest: 200, cpuLimit: 200, + memoryRequest: 200, memoryLimit: 200, + }, + otherContainersHaveLimits: true, + updatedResources: []v1.ResourceName{v1.ResourceCPU, v1.ResourceMemory}, + expectPodCgroupUpdates: 3, // cpu req, cpu lim, mem lim + }, + { + testName: "Increase cpu and memory requests and limits, without computed pod limits", + currentResources: containerResources{ + cpuRequest: 100, cpuLimit: 100, + memoryRequest: 100, memoryLimit: 100, + }, + desiredResources: containerResources{ + cpuRequest: 200, cpuLimit: 200, + memoryRequest: 200, memoryLimit: 200, + }, + // If some containers don't have limits, pod level limits are not applied + otherContainersHaveLimits: false, + updatedResources: []v1.ResourceName{v1.ResourceCPU, v1.ResourceMemory}, + expectPodCgroupUpdates: 1, // cpu req, cpu lim, mem lim + }, + { + testName: "Increase cpu and memory requests only", + currentResources: containerResources{ + cpuRequest: 100, cpuLimit: 200, + memoryRequest: 100, memoryLimit: 200, + }, + desiredResources: containerResources{ + cpuRequest: 150, cpuLimit: 200, + memoryRequest: 150, memoryLimit: 200, + }, + updatedResources: []v1.ResourceName{v1.ResourceCPU}, + expectPodCgroupUpdates: 1, // cpu req + }, + { + testName: "Resize memory request no limits", + currentResources: containerResources{ + cpuRequest: 100, + memoryRequest: 100, + }, + desiredResources: containerResources{ + cpuRequest: 100, + memoryRequest: 200, + }, + // Memory request resize doesn't generate an update action. + updatedResources: []v1.ResourceName{}, + }, + { + testName: "Resize cpu request no limits", + currentResources: containerResources{ + cpuRequest: 100, + memoryRequest: 100, + }, + desiredResources: containerResources{ + cpuRequest: 200, + memoryRequest: 100, + }, + updatedResources: []v1.ResourceName{v1.ResourceCPU}, + expectPodCgroupUpdates: 1, // cpu req + }, + { + testName: "Add limits", + currentResources: containerResources{ + cpuRequest: 100, + memoryRequest: 100, + }, + desiredResources: containerResources{ + cpuRequest: 100, cpuLimit: 100, + memoryRequest: 100, memoryLimit: 100, + }, + updatedResources: []v1.ResourceName{v1.ResourceCPU, v1.ResourceMemory}, + expectPodCgroupUpdates: 0, + }, + { + testName: "Add limits and pod limits", + currentResources: containerResources{ + cpuRequest: 100, + memoryRequest: 100, + }, + desiredResources: containerResources{ + cpuRequest: 100, cpuLimit: 100, + memoryRequest: 100, memoryLimit: 100, + }, + otherContainersHaveLimits: true, + updatedResources: []v1.ResourceName{v1.ResourceCPU, v1.ResourceMemory}, + expectPodCgroupUpdates: 2, // cpu lim, memory lim + }, + } { + t.Run(tc.testName, func(t *testing.T) { + mockCM := cmtesting.NewMockContainerManager(t) + m.containerManager = mockCM + mockPCM := cmtesting.NewMockPodContainerManager(t) + mockCM.EXPECT().NewPodContainerManager().Return(mockPCM) + + mockPCM.EXPECT().GetPodCgroupConfig(mock.Anything, v1.ResourceMemory).Return(&cm.ResourceConfig{ + Memory: ptr.To(tc.currentResources.memoryLimit), + }, nil).Maybe() + mockPCM.EXPECT().GetPodCgroupMemoryUsage(mock.Anything).Return(0, nil).Maybe() + // Set up mock pod cgroup config + podCPURequest := tc.currentResources.cpuRequest + podCPULimit := tc.currentResources.cpuLimit + if tc.otherContainersHaveLimits { + podCPURequest += 200 + podCPULimit += 200 + } + mockPCM.EXPECT().GetPodCgroupConfig(mock.Anything, v1.ResourceCPU).Return(&cm.ResourceConfig{ + CPUShares: ptr.To(cm.MilliCPUToShares(podCPURequest)), + CPUQuota: ptr.To(cm.MilliCPUToQuota(podCPULimit, cm.QuotaPeriod)), + }, nil).Maybe() + if tc.expectPodCgroupUpdates > 0 { + mockPCM.EXPECT().SetPodCgroupConfig(mock.Anything, mock.Anything).Return(nil).Times(tc.expectPodCgroupUpdates) + } + + pod, kps := makeBasePodAndStatus() + // pod spec and allocated resources are already updated as desired when doPodResizeAction() is called. + pod.Spec.Containers[0].Resources = v1.ResourceRequirements{ + Requests: v1.ResourceList{ + v1.ResourceCPU: *resource.NewMilliQuantity(tc.desiredResources.cpuRequest, resource.DecimalSI), + v1.ResourceMemory: *resource.NewQuantity(tc.desiredResources.memoryRequest, resource.DecimalSI), + }, + Limits: v1.ResourceList{ + v1.ResourceCPU: *resource.NewMilliQuantity(tc.desiredResources.cpuLimit, resource.DecimalSI), + v1.ResourceMemory: *resource.NewQuantity(tc.desiredResources.memoryLimit, resource.DecimalSI), + }, + } + if tc.otherContainersHaveLimits { + resourceList := v1.ResourceList{ + v1.ResourceCPU: resource.MustParse("100m"), + v1.ResourceMemory: resource.MustParse("100M"), + } + resources := v1.ResourceRequirements{ + Requests: resourceList, + Limits: resourceList, + } + pod.Spec.Containers[1].Resources = resources + pod.Spec.Containers[2].Resources = resources + } + + updateInfo := containerToUpdateInfo{ + apiContainerIdx: 0, + kubeContainerID: kps.ContainerStatuses[0].ID, + desiredContainerResources: tc.desiredResources, + currentContainerResources: &tc.currentResources, + } + containersToUpdate := make(map[v1.ResourceName][]containerToUpdateInfo) + for _, r := range tc.updatedResources { + containersToUpdate[r] = []containerToUpdateInfo{updateInfo} + } + + syncResult := &kubecontainer.PodSyncResult{} + actions := podActions{ + ContainersToUpdate: containersToUpdate, + } + m.doPodResizeAction(pod, actions, syncResult) + + if tc.expectedError != "" { + require.Error(t, syncResult.Error()) + require.EqualError(t, syncResult.Error(), tc.expectedError) + } else { + require.NoError(t, syncResult.Error()) + } + + mock.AssertExpectationsForObjects(t, mockPCM) + }) + } +} diff --git a/test/e2e/common/node/pod_resize.go b/test/e2e/common/node/pod_resize.go index 347def6f339..27c14f729c6 100644 --- a/test/e2e/common/node/pod_resize.go +++ b/test/e2e/common/node/pod_resize.go @@ -566,6 +566,24 @@ func doPodResizeTests(f *framework.Framework) { }, }, }, + { + name: "Burstable QoS pod, one container with cpu & memory requests - increase cpu request", + containers: []e2epod.ResizableContainerInfo{ + { + Name: "c1", + Resources: &e2epod.ContainerResources{CPUReq: "200m", MemReq: "500Mi"}, + }, + }, + patchString: `{"spec":{"containers":[ + {"name":"c1", "resources":{"requests":{"cpu":"300m"}}} + ]}}`, + expected: []e2epod.ResizableContainerInfo{ + { + Name: "c1", + Resources: &e2epod.ContainerResources{CPUReq: "300m", MemReq: "500Mi"}, + }, + }, + }, { name: "Burstable QoS pod, one container with cpu requests - resize with equivalent request", containers: []e2epod.ResizableContainerInfo{ @@ -776,6 +794,102 @@ func doPodResizeTests(f *framework.Framework) { }, }, }, + { + name: "Burstable QoS pod, mixed containers - scale up cpu and memory", + containers: []e2epod.ResizableContainerInfo{ + { + Name: "c1", + Resources: &e2epod.ContainerResources{CPUReq: "100m", CPULim: "100m", MemReq: "100Mi", MemLim: "100Mi"}, + CPUPolicy: &noRestart, + MemPolicy: &noRestart, + }, + { + Name: "c2", + Resources: &e2epod.ContainerResources{}, + }, + }, + patchString: `{"spec":{"containers":[ + {"name":"c1", "resources":{"requests":{"cpu":"200m","memory":"200Mi"},"limits":{"cpu":"200m","memory":"200Mi"}}} + ]}}`, + expected: []e2epod.ResizableContainerInfo{ + { + Name: "c1", + Resources: &e2epod.ContainerResources{CPUReq: "200m", CPULim: "200m", MemReq: "200Mi", MemLim: "200Mi"}, + CPUPolicy: &noRestart, + MemPolicy: &noRestart, + }, + { + Name: "c2", + Resources: &e2epod.ContainerResources{}, + }, + }, + }, + { + name: "Burstable QoS pod, mixed containers - add requests", + containers: []e2epod.ResizableContainerInfo{ + { + Name: "c1", + Resources: &e2epod.ContainerResources{CPUReq: "100m", CPULim: "100m", MemReq: "100Mi", MemLim: "100Mi"}, + CPUPolicy: &noRestart, + MemPolicy: &noRestart, + }, + { + Name: "c2", + Resources: &e2epod.ContainerResources{}, + }, + }, + patchString: `{"spec":{"containers":[ + {"name":"c2", "resources":{"requests":{"cpu":"100m","memory":"100Mi"}}} + ]}}`, + expected: []e2epod.ResizableContainerInfo{ + { + Name: "c1", + Resources: &e2epod.ContainerResources{CPUReq: "100m", CPULim: "100m", MemReq: "100Mi", MemLim: "100Mi"}, + CPUPolicy: &noRestart, + MemPolicy: &noRestart, + }, + { + Name: "c2", + Resources: &e2epod.ContainerResources{CPUReq: "100m", MemReq: "100Mi"}, + CPUPolicy: &noRestart, + MemPolicy: &noRestart, + }, + }, + }, + { + name: "Burstable QoS pod, mixed containers - add limits", + containers: []e2epod.ResizableContainerInfo{ + { + Name: "c1", + Resources: &e2epod.ContainerResources{CPUReq: "100m", CPULim: "100m", MemReq: "100Mi", MemLim: "100Mi"}, + CPUPolicy: &noRestart, + MemPolicy: &noRestart, + }, + { + Name: "c2", + Resources: &e2epod.ContainerResources{CPUReq: "100m", MemReq: "100Mi"}, + CPUPolicy: &noRestart, + MemPolicy: &noRestart, + }, + }, + patchString: `{"spec":{"containers":[ + {"name":"c2", "resources":{"limits":{"cpu":"200m","memory":"200Mi"}}} + ]}}`, + expected: []e2epod.ResizableContainerInfo{ + { + Name: "c1", + Resources: &e2epod.ContainerResources{CPUReq: "100m", CPULim: "100m", MemReq: "100Mi", MemLim: "100Mi"}, + CPUPolicy: &noRestart, + MemPolicy: &noRestart, + }, + { + Name: "c2", + Resources: &e2epod.ContainerResources{CPUReq: "100m", CPULim: "200m", MemReq: "100Mi", MemLim: "200Mi"}, + CPUPolicy: &noRestart, + MemPolicy: &noRestart, + }, + }, + }, { name: "Guaranteed QoS pod, one container - increase CPU & memory with an extended resource", containers: []e2epod.ResizableContainerInfo{