@@ -37,9 +37,9 @@ import (
37
37
)
38
38
39
39
const (
40
- ownerKey = ".metadata.controller.gpu"
41
- serviceAccountPrefix = "gpu-manager-sa"
42
- roleBindingPrefix = "gpu-manager-rolebinding"
40
+ ownerKey = ".metadata.controller.gpu"
41
+ serviceAccountName = "gpu-manager-sa"
42
+ roleBindingName = "gpu-manager-rolebinding"
43
43
)
44
44
45
45
var defaultNodeSelector = deployments .GPUPluginDaemonSet ().Spec .Template .Spec .NodeSelector
@@ -76,48 +76,54 @@ func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
76
76
return controllers .UpgradeImages (ctx , & dp .Spec .Image , & dp .Spec .InitImage )
77
77
}
78
78
79
- func (c * controller ) NewServiceAccount (rawObj client.Object ) * v1.ServiceAccount {
80
- devicePlugin := rawObj .(* devicepluginv1.GpuDevicePlugin )
81
- if devicePlugin .Spec .ResourceManager {
82
- sa := v1.ServiceAccount {
83
- ObjectMeta : metav1.ObjectMeta {
84
- Name : prefixedName (serviceAccountPrefix , devicePlugin .Name ),
79
+ func (c * controller ) NewSharedServiceAccount () * v1.ServiceAccount {
80
+ return & v1.ServiceAccount {
81
+ ObjectMeta : metav1.ObjectMeta {
82
+ Name : serviceAccountName ,
83
+ Namespace : c .ns ,
84
+ },
85
+ }
86
+ }
87
+
88
+ func (c * controller ) NewSharedClusterRoleBinding () * rbacv1.ClusterRoleBinding {
89
+ return & rbacv1.ClusterRoleBinding {
90
+ ObjectMeta : metav1.ObjectMeta {
91
+ Name : roleBindingName ,
92
+ Namespace : c .ns ,
93
+ },
94
+ Subjects : []rbacv1.Subject {
95
+ {
96
+ Kind : "ServiceAccount" ,
97
+ Name : serviceAccountName ,
85
98
Namespace : c .ns ,
86
99
},
87
- }
88
-
89
- return & sa
100
+ },
101
+ RoleRef : rbacv1.RoleRef {
102
+ Kind : "ClusterRole" ,
103
+ Name : "inteldeviceplugins-gpu-manager-role" ,
104
+ APIGroup : "rbac.authorization.k8s.io" ,
105
+ },
90
106
}
107
+ }
91
108
92
- return nil
109
+ func (c * controller ) PluginMayRequireSharedObjects () bool {
110
+ return true
93
111
}
94
112
95
- func (c * controller ) NewClusterRoleBinding (rawObj client.Object ) * rbacv1.ClusterRoleBinding {
96
- devicePlugin := rawObj .(* devicepluginv1.GpuDevicePlugin )
97
- if devicePlugin .Spec .ResourceManager {
98
- rb := rbacv1.ClusterRoleBinding {
99
- ObjectMeta : metav1.ObjectMeta {
100
- Name : prefixedName (roleBindingPrefix , devicePlugin .Name ),
101
- Namespace : c .ns ,
102
- },
103
- Subjects : []rbacv1.Subject {
104
- {
105
- Kind : "ServiceAccount" ,
106
- Name : prefixedName (serviceAccountPrefix , devicePlugin .Name ),
107
- Namespace : c .ns ,
108
- },
109
- },
110
- RoleRef : rbacv1.RoleRef {
111
- Kind : "ClusterRole" ,
112
- Name : "inteldeviceplugins-gpu-manager-role" ,
113
- APIGroup : "rbac.authorization.k8s.io" ,
114
- },
115
- }
113
+ func (c * controller ) PluginRequiresSharedObjects (ctx context.Context , client client.Client ) bool {
114
+ var list devicepluginv1.GpuDevicePluginList
116
115
117
- return & rb
116
+ if err := client .List (ctx , & list ); err != nil {
117
+ return false
118
118
}
119
119
120
- return nil
120
+ for _ , cr := range list .Items {
121
+ if cr .Spec .ResourceManager {
122
+ return true
123
+ }
124
+ }
125
+
126
+ return false
121
127
}
122
128
123
129
func (c * controller ) NewDaemonSet (rawObj client.Object ) * apps.DaemonSet {
@@ -143,7 +149,7 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
143
149
144
150
// add service account if resource manager is enabled
145
151
if devicePlugin .Spec .ResourceManager {
146
- daemonSet .Spec .Template .Spec .ServiceAccountName = prefixedName ( serviceAccountPrefix , devicePlugin . Name )
152
+ daemonSet .Spec .Template .Spec .ServiceAccountName = serviceAccountName
147
153
addVolumeIfMissing (& daemonSet .Spec .Template .Spec , "podresources" , "/var/lib/kubelet/pod-resources" , v1 .HostPathDirectory )
148
154
addVolumeMountIfMissing (& daemonSet .Spec .Template .Spec , "podresources" , "/var/lib/kubelet/pod-resources" , false )
149
155
addVolumeIfMissing (& daemonSet .Spec .Template .Spec , "kubeletcrt" , "/var/lib/kubelet/pki/kubelet.crt" , v1 .HostPathFileOrCreate )
@@ -324,7 +330,7 @@ func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (
324
330
325
331
newServiceAccountName := "default"
326
332
if dp .Spec .ResourceManager {
327
- newServiceAccountName = prefixedName ( serviceAccountPrefix , dp . Name )
333
+ newServiceAccountName = serviceAccountName
328
334
}
329
335
330
336
if ds .Spec .Template .Spec .ServiceAccountName != newServiceAccountName {
0 commit comments