From 8b29eded523e196a2f463ab7b50bbbe7bf19ee2e Mon Sep 17 00:00:00 2001 From: Swati Sehgal Date: Mon, 24 Oct 2022 23:05:21 +0100 Subject: [PATCH] node: devicemgr: Remove `devicePluginEnabled` field from container mgr With graduation of device plugins to GA in 1.26, the feature gate is enabled by default so `devicePluginEnabled` field no longer needs to be passed at the time of Container Manager creation. In addition to that, we remove the `ManagerStub` as it is no longer needed. Signed-off-by: Swati Sehgal --- cmd/kubelet/app/server.go | 3 - pkg/kubelet/cm/container_manager_linux.go | 12 +-- .../cm/container_manager_unsupported.go | 2 +- pkg/kubelet/cm/container_manager_windows.go | 12 +-- pkg/kubelet/cm/devicemanager/manager_stub.go | 99 ------------------- 5 files changed, 9 insertions(+), 119 deletions(-) delete mode 100644 pkg/kubelet/cm/devicemanager/manager_stub.go diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index 9e121f0b9fa..4d3bdb9a7ee 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -704,8 +704,6 @@ func run(ctx context.Context, s *options.KubeletServer, kubeDeps *kubelet.Depend return err } - devicePluginEnabled := utilfeature.DefaultFeatureGate.Enabled(features.DevicePlugins) - var cpuManagerPolicyOptions map[string]string if utilfeature.DefaultFeatureGate.Enabled(features.CPUManager) { if utilfeature.DefaultFeatureGate.Enabled(features.CPUManagerPolicyOptions) { @@ -751,7 +749,6 @@ func run(ctx context.Context, s *options.KubeletServer, kubeDeps *kubelet.Depend ExperimentalTopologyManagerScope: s.TopologyManagerScope, }, s.FailSwapOn, - devicePluginEnabled, kubeDeps.Recorder) if err != nil { diff --git a/pkg/kubelet/cm/container_manager_linux.go b/pkg/kubelet/cm/container_manager_linux.go index c7fcbaff8b0..0a3b3db7a48 100644 --- a/pkg/kubelet/cm/container_manager_linux.go +++ b/pkg/kubelet/cm/container_manager_linux.go @@ -194,7 +194,7 @@ func validateSystemRequirements(mountUtil mount.Interface) (features, error) { // TODO(vmarmol): Add limits to the system containers. // Takes the absolute name of the specified containers. // Empty container name disables use of the specified container. -func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.Interface, nodeConfig NodeConfig, failSwapOn bool, devicePluginEnabled bool, recorder record.EventRecorder) (ContainerManager, error) { +func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.Interface, nodeConfig NodeConfig, failSwapOn bool, recorder record.EventRecorder) (ContainerManager, error) { subsystems, err := GetCgroupSubsystems() if err != nil { return nil, fmt.Errorf("failed to get mounted cgroup subsystems: %v", err) @@ -298,16 +298,12 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I cm.topologyManager = topologymanager.NewFakeManager() } - klog.InfoS("Creating device plugin manager", "devicePluginEnabled", devicePluginEnabled) - if devicePluginEnabled { - cm.deviceManager, err = devicemanager.NewManagerImpl(machineInfo.Topology, cm.topologyManager) - cm.topologyManager.AddHintProvider(cm.deviceManager) - } else { - cm.deviceManager, err = devicemanager.NewManagerStub() - } + klog.InfoS("Creating device plugin manager") + cm.deviceManager, err = devicemanager.NewManagerImpl(machineInfo.Topology, cm.topologyManager) if err != nil { return nil, err } + cm.topologyManager.AddHintProvider(cm.deviceManager) // Initialize CPU manager if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.CPUManager) { diff --git a/pkg/kubelet/cm/container_manager_unsupported.go b/pkg/kubelet/cm/container_manager_unsupported.go index fb1c4a79dbf..e58c236b50f 100644 --- a/pkg/kubelet/cm/container_manager_unsupported.go +++ b/pkg/kubelet/cm/container_manager_unsupported.go @@ -42,6 +42,6 @@ func (unsupportedContainerManager) Start(_ *v1.Node, _ ActivePodsFunc, _ config. return fmt.Errorf("Container Manager is unsupported in this build") } -func NewContainerManager(_ mount.Interface, _ cadvisor.Interface, _ NodeConfig, failSwapOn bool, devicePluginEnabled bool, recorder record.EventRecorder) (ContainerManager, error) { +func NewContainerManager(_ mount.Interface, _ cadvisor.Interface, _ NodeConfig, failSwapOn bool, recorder record.EventRecorder) (ContainerManager, error) { return &unsupportedContainerManager{}, nil } diff --git a/pkg/kubelet/cm/container_manager_windows.go b/pkg/kubelet/cm/container_manager_windows.go index dc325a3a9f9..742506a78b4 100644 --- a/pkg/kubelet/cm/container_manager_windows.go +++ b/pkg/kubelet/cm/container_manager_windows.go @@ -93,7 +93,7 @@ func (cm *containerManagerImpl) Start(node *v1.Node, } // NewContainerManager creates windows container manager. -func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.Interface, nodeConfig NodeConfig, failSwapOn bool, devicePluginEnabled bool, recorder record.EventRecorder) (ContainerManager, error) { +func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.Interface, nodeConfig NodeConfig, failSwapOn bool, recorder record.EventRecorder) (ContainerManager, error) { // It is safe to invoke `MachineInfo` on cAdvisor before logically initializing cAdvisor here because // machine info is computed and cached once as part of cAdvisor object creation. // But `RootFsInfo` and `ImagesFsInfo` are not available at this moment so they will be called later during manager starts @@ -111,16 +111,12 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I cm.topologyManager = topologymanager.NewFakeManager() - klog.InfoS("Creating device plugin manager", "devicePluginEnabled", devicePluginEnabled) - if devicePluginEnabled { - cm.deviceManager, err = devicemanager.NewManagerImpl(nil, cm.topologyManager) - cm.topologyManager.AddHintProvider(cm.deviceManager) - } else { - cm.deviceManager, err = devicemanager.NewManagerStub() - } + klog.InfoS("Creating device plugin manager") + cm.deviceManager, err = devicemanager.NewManagerImpl(nil, cm.topologyManager) if err != nil { return nil, err } + cm.topologyManager.AddHintProvider(cm.deviceManager) return cm, nil } diff --git a/pkg/kubelet/cm/devicemanager/manager_stub.go b/pkg/kubelet/cm/devicemanager/manager_stub.go deleted file mode 100644 index e6874f88d8a..00000000000 --- a/pkg/kubelet/cm/devicemanager/manager_stub.go +++ /dev/null @@ -1,99 +0,0 @@ -/* -Copyright 2017 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. -*/ - -package devicemanager - -import ( - v1 "k8s.io/api/core/v1" - "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" - "k8s.io/kubernetes/pkg/kubelet/config" - "k8s.io/kubernetes/pkg/kubelet/lifecycle" - "k8s.io/kubernetes/pkg/kubelet/pluginmanager/cache" - schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework" -) - -// ManagerStub provides a simple stub implementation for the Device Manager. -type ManagerStub struct{} - -// NewManagerStub creates a ManagerStub. -func NewManagerStub() (*ManagerStub, error) { - return &ManagerStub{}, nil -} - -// Start simply returns nil. -func (h *ManagerStub) Start(activePods ActivePodsFunc, sourcesReady config.SourcesReady) error { - return nil -} - -// Stop simply returns nil. -func (h *ManagerStub) Stop() error { - return nil -} - -// Allocate simply returns nil. -func (h *ManagerStub) Allocate(pod *v1.Pod, container *v1.Container) error { - return nil -} - -// UpdatePluginResources simply returns nil. -func (h *ManagerStub) UpdatePluginResources(node *schedulerframework.NodeInfo, attrs *lifecycle.PodAdmitAttributes) error { - return nil -} - -// GetDeviceRunContainerOptions simply returns nil. -func (h *ManagerStub) GetDeviceRunContainerOptions(pod *v1.Pod, container *v1.Container) (*DeviceRunContainerOptions, error) { - return nil, nil -} - -// GetCapacity simply returns nil capacity and empty removed resource list. -func (h *ManagerStub) GetCapacity() (v1.ResourceList, v1.ResourceList, []string) { - return nil, nil, []string{} -} - -// GetWatcherHandler returns plugin watcher interface -func (h *ManagerStub) GetWatcherHandler() cache.PluginHandler { - return nil -} - -// GetTopologyHints returns an empty TopologyHint map -func (h *ManagerStub) GetTopologyHints(pod *v1.Pod, container *v1.Container) map[string][]topologymanager.TopologyHint { - return map[string][]topologymanager.TopologyHint{} -} - -// GetPodTopologyHints returns an empty TopologyHint map -func (h *ManagerStub) GetPodTopologyHints(pod *v1.Pod) map[string][]topologymanager.TopologyHint { - return map[string][]topologymanager.TopologyHint{} -} - -// GetDevices returns nil -func (h *ManagerStub) GetDevices(_, _ string) ResourceDeviceInstances { - return nil -} - -// GetAllocatableDevices returns nothing -func (h *ManagerStub) GetAllocatableDevices() ResourceDeviceInstances { - return nil -} - -// ShouldResetExtendedResourceCapacity returns false -func (h *ManagerStub) ShouldResetExtendedResourceCapacity() bool { - return false -} - -// UpdateAllocatedDevices returns nothing -func (h *ManagerStub) UpdateAllocatedDevices() { - return -}