@@ -36,6 +36,7 @@ import (
36
36
podresourcesapi "k8s.io/kubernetes/pkg/kubelet/apis/podresources/v1alpha1"
37
37
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
38
38
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"
39
+ "k8s.io/kubernetes/pkg/kubelet/cm/devicemanager"
39
40
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
40
41
"k8s.io/kubernetes/pkg/kubelet/config"
41
42
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
@@ -52,6 +53,10 @@ type containerManagerImpl struct {
52
53
cadvisorInterface cadvisor.Interface
53
54
// Config of this node.
54
55
nodeConfig NodeConfig
56
+ // Interface for exporting and allocating devices reported by device plugins.
57
+ deviceManager devicemanager.Manager
58
+ // Interface for Topology resource co-ordination
59
+ topologyManager topologymanager.Manager
55
60
}
56
61
57
62
type noopWindowsResourceAllocator struct {}
@@ -79,6 +84,11 @@ func (cm *containerManagerImpl) Start(node *v1.Node,
79
84
}
80
85
}
81
86
87
+ // Starts device manager.
88
+ if err := cm .deviceManager .Start (devicemanager .ActivePodsFunc (activePods ), sourcesReady ); err != nil {
89
+ return err
90
+ }
91
+
82
92
return nil
83
93
}
84
94
@@ -93,11 +103,23 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
93
103
}
94
104
capacity := cadvisor .CapacityFromMachineInfo (machineInfo )
95
105
96
- return & containerManagerImpl {
106
+ cm := & containerManagerImpl {
97
107
capacity : capacity ,
98
108
nodeConfig : nodeConfig ,
99
109
cadvisorInterface : cadvisorInterface ,
100
- }, nil
110
+ }
111
+
112
+ klog .Infof ("Creating device plugin manager: %t" , devicePluginEnabled )
113
+ if devicePluginEnabled {
114
+ cm .deviceManager , err = devicemanager .NewManagerImpl (nil , cm .topologyManager )
115
+ } else {
116
+ cm .deviceManager , err = devicemanager .NewManagerStub ()
117
+ }
118
+ if err != nil {
119
+ return nil , err
120
+ }
121
+
122
+ return cm , nil
101
123
}
102
124
103
125
func (cm * containerManagerImpl ) SystemCgroupsLimit () v1.ResourceList {
@@ -150,23 +172,36 @@ func (cm *containerManagerImpl) GetCapacity() v1.ResourceList {
150
172
}
151
173
152
174
func (cm * containerManagerImpl ) GetPluginRegistrationHandler () cache.PluginHandler {
153
- return nil
175
+ return cm . deviceManager . GetWatcherHandler ()
154
176
}
155
177
156
178
func (cm * containerManagerImpl ) GetDevicePluginResourceCapacity () (v1.ResourceList , v1.ResourceList , []string ) {
157
- return nil , nil , [] string {}
179
+ return cm . deviceManager . GetCapacity ()
158
180
}
159
181
160
182
func (cm * containerManagerImpl ) NewPodContainerManager () PodContainerManager {
161
183
return & podContainerManagerStub {}
162
184
}
163
185
164
186
func (cm * containerManagerImpl ) GetResources (pod * v1.Pod , container * v1.Container ) (* kubecontainer.RunContainerOptions , error ) {
165
- return & kubecontainer.RunContainerOptions {}, nil
187
+ opts := & kubecontainer.RunContainerOptions {}
188
+ // Allocate should already be called during predicateAdmitHandler.Admit(),
189
+ // just try to fetch device runtime information from cached state here
190
+ devOpts , err := cm .deviceManager .GetDeviceRunContainerOptions (pod , container )
191
+ if err != nil {
192
+ return nil , err
193
+ } else if devOpts == nil {
194
+ return opts , nil
195
+ }
196
+ opts .Devices = append (opts .Devices , devOpts .Devices ... )
197
+ opts .Mounts = append (opts .Mounts , devOpts .Mounts ... )
198
+ opts .Envs = append (opts .Envs , devOpts .Envs ... )
199
+ opts .Annotations = append (opts .Annotations , devOpts .Annotations ... )
200
+ return opts , nil
166
201
}
167
202
168
- func (cm * containerManagerImpl ) UpdatePluginResources (* schedulerframework.NodeInfo , * lifecycle.PodAdmitAttributes ) error {
169
- return nil
203
+ func (cm * containerManagerImpl ) UpdatePluginResources (node * schedulerframework.NodeInfo , attrs * lifecycle.PodAdmitAttributes ) error {
204
+ return cm . deviceManager . UpdatePluginResources ( node , attrs )
170
205
}
171
206
172
207
func (cm * containerManagerImpl ) InternalContainerLifecycle () InternalContainerLifecycle {
@@ -177,12 +212,12 @@ func (cm *containerManagerImpl) GetPodCgroupRoot() string {
177
212
return ""
178
213
}
179
214
180
- func (cm * containerManagerImpl ) GetDevices (_ , _ string ) []* podresourcesapi.ContainerDevices {
181
- return nil
215
+ func (cm * containerManagerImpl ) GetDevices (podUID , containerName string ) []* podresourcesapi.ContainerDevices {
216
+ return cm . deviceManager . GetDevices ( podUID , containerName )
182
217
}
183
218
184
219
func (cm * containerManagerImpl ) ShouldResetExtendedResourceCapacity () bool {
185
- return false
220
+ return cm . deviceManager . ShouldResetExtendedResourceCapacity ()
186
221
}
187
222
188
223
func (cm * containerManagerImpl ) GetAllocateResourcesPodAdmitHandler () lifecycle.PodAdmitHandler {
0 commit comments