Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
kubelet: remove DeviceManager leftovers
  • Loading branch information
bart0sh committed Aug 19, 2022
commit c09568802e99cd3b7517fe0fd3bf7a286ad4de82
5 changes: 0 additions & 5 deletions pkg/kubelet/cm/container_manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,6 @@ func (cm *containerManagerImpl) Start(node *v1.Node,
return err
}

// Starts DRA manager.
if cm.draManager != nil {
cm.draManager.Configure(dra.ActivePodsFunc(activePods), sourcesReady)
}

return nil
}

Expand Down
59 changes: 4 additions & 55 deletions pkg/kubelet/cm/dra/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,88 +30,37 @@ import (
clientset "k8s.io/client-go/kubernetes"
"k8s.io/component-helpers/dra/resourceclaim"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
dra "k8s.io/kubernetes/pkg/kubelet/cm/dra/plugin"
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
"k8s.io/kubernetes/pkg/kubelet/config"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
)

// ManagerImpl is the structure in charge of managing Device Plugins.
// ManagerImpl is the structure in charge of managing DRA resource Plugins.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"resource" seems redundant here. "DRA" already contains that word.

type ManagerImpl struct {
sync.Mutex

// List of NUMA Nodes available on the underlying machine
numaNodes []int

// Store of Topology Affinties that the Device Manager can query.
topologyAffinityStore topologymanager.Store

// resources contains resources referenced by pod containers
resources *claimedResources

// activePods is a method for listing active pods on the node
activePods ActivePodsFunc

// sourcesReady provides the readiness of kubelet configuration sources such as apiserver update readiness.
// We use it to determine when we can purge inactive pods from checkpointed state.
sourcesReady config.SourcesReady

// Checkpoint manager
checkpointdir string
checkpointManager checkpointmanager.CheckpointManager

// pendingAdmissionPod contain the pod during the admission phase
pendingAdmissionPod *v1.Pod

// KubeClient reference
kubeClient clientset.Interface
}

type sourcesReadyStub struct{}

func (s *sourcesReadyStub) AddSource(source string) {}
func (s *sourcesReadyStub) AllReady() bool { return true }

// NewManagerImpl creates a new manager.
func NewManagerImpl(topology []cadvisorapi.Node, topologyAffinityStore topologymanager.Store, kubeClient clientset.Interface) (*ManagerImpl, error) {
klog.V(2).InfoS("Creating DRA manager")

var numaNodes []int
for _, node := range topology {
numaNodes = append(numaNodes, node.Id)
}

manager := &ManagerImpl{
resources: newClaimedResources(),
numaNodes: numaNodes,
topologyAffinityStore: topologyAffinityStore,
kubeClient: kubeClient,
}

// The following structures are populated with real implementations in manager.Start()
// Before that, initializes them to perform no-op operations.
manager.activePods = func() []*v1.Pod { return []*v1.Pod{} }
manager.sourcesReady = &sourcesReadyStub{}

// Initialize checkpoint manager
var err error
manager.checkpointdir = DRACheckpointDir
manager.checkpointManager, err = checkpointmanager.NewCheckpointManager(manager.checkpointdir)
if err != nil {
return nil, fmt.Errorf("failed to initialize checkpoint manager: %v", err)
resources: newClaimedResources(),
kubeClient: kubeClient,
}

return manager, nil
}

// Configure configures the DRA Manager and initializes
// podResources cache from checkpointed state
func (m *ManagerImpl) Configure(activePods ActivePodsFunc, sourcesReady config.SourcesReady) {
m.activePods = activePods
m.sourcesReady = sourcesReady
}

func (m *ManagerImpl) setPodPendingAdmission(pod *v1.Pod) {
m.Lock()
defer m.Unlock()
Expand Down Expand Up @@ -197,7 +146,7 @@ func (m *ManagerImpl) prepareContainerResources(pod *v1.Pod, container *v1.Conta
return nil
}

// Allocate calls plugin NodePrepareResource from the registered device plugins.
// Allocate calls plugin NodePrepareResource from the registered DRA resource plugins.
func (m *ManagerImpl) Allocate(pod *v1.Pod, container *v1.Container) error {
// The pod is during the admission phase. We need to save the pod to avoid it
// being cleaned before the admission ended
Expand Down
16 changes: 8 additions & 8 deletions pkg/kubelet/cm/dra/topology_hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ func (m *ManagerImpl) GetTopologyHints(pod *v1.Pod, container *v1.Container) map
// being cleaned before the admission ended
m.setPodPendingAdmission(pod)

// Loop through all device resources and generate TopologyHints for them..
deviceHints := make(map[string][]topologymanager.TopologyHint)
// Loop through all container resources and generate TopologyHints for them
resourceHints := make(map[string][]topologymanager.TopologyHint)
for resourceObj := range container.Resources.Limits {
deviceHints[string(resourceObj)] = nil // resource doesn't have a topology preference
resourceHints[string(resourceObj)] = nil // resource doesn't have a topology preference
}

return deviceHints
return resourceHints
}

// GetPodTopologyHints implements the topologymanager.HintProvider Interface which
// ensures the Device Manager is consulted when Topology Aware Hints for Pod are created.
// ensures the DRA Manager is consulted when Topology Aware Hints for Pod are created.
func (m *ManagerImpl) GetPodTopologyHints(pod *v1.Pod) map[string][]topologymanager.TopologyHint {
// The pod is during the admission phase. We need to save the pod to avoid it
// being cleaned before the admission ended
m.setPodPendingAdmission(pod)

deviceHints := make(map[string][]topologymanager.TopologyHint)
resourceHints := make(map[string][]topologymanager.TopologyHint)
for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
for resourceObj := range container.Resources.Limits {
deviceHints[string(resourceObj)] = nil // resource doesn't have a topology preference
resourceHints[string(resourceObj)] = nil // resource doesn't have a topology preference
}
}

return deviceHints
return resourceHints
}
14 changes: 5 additions & 9 deletions pkg/kubelet/cm/dra/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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,
Expand All @@ -18,28 +18,24 @@ package dra
import (
v1 "k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
"k8s.io/kubernetes/pkg/kubelet/config"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
)

// ActivePodsFunc is a function that returns a list of pods to reconcile.
type ActivePodsFunc func() []*v1.Pod

// Manager manages all the kubelet resource plugins running on a node.
// Manager manages all the DRA resource plugins running on a node.
type Manager interface {
// Configure configures DRA manager
Configure(activePods ActivePodsFunc, sourcesReady config.SourcesReady)

// Allocate prepares and assigns resources to a container in a pod. From
// the requested resources, Allocate will communicate with the
// kubelet resource plugin to prepare resources.
// DRA resource plugin to prepare resources.
Allocate(pod *v1.Pod, container *v1.Container) error

// TopologyManager HintProvider provider indicates the Device Manager implements the Topology Manager Interface
// TopologyManager HintProvider provider indicates the DRA Manager implements the Topology Manager Interface
// and is consulted to make Topology aware resource alignments
GetTopologyHints(pod *v1.Pod, container *v1.Container) map[string][]topologymanager.TopologyHint

// TopologyManager HintProvider provider indicates the Device Manager implements the Topology Manager Interface
// TopologyManager HintProvider provider indicates the DRA Manager implements the Topology Manager Interface
// and is consulted to make Topology aware resource alignments per Pod
GetPodTopologyHints(pod *v1.Pod) map[string][]topologymanager.TopologyHint

Expand Down