@@ -15,6 +15,7 @@ import (
15
15
"k8s.io/apimachinery/pkg/util/intstr"
16
16
applyappsv1 "k8s.io/client-go/applyconfigurations/apps/v1"
17
17
applycorev1 "k8s.io/client-go/applyconfigurations/core/v1"
18
+ applyrbacv1 "k8s.io/client-go/applyconfigurations/rbac/v1"
18
19
)
19
20
20
21
// ContrastRuntimeClass creates a new RuntimeClassConfig.
@@ -39,6 +40,9 @@ func ContrastRuntimeClass(platform platforms.Platform) (*RuntimeClassConfig, err
39
40
// NodeInstallerConfig wraps a DaemonSetApplyConfiguration for a node installer.
40
41
type NodeInstallerConfig struct {
41
42
* applyappsv1.DaemonSetApplyConfiguration
43
+ * applycorev1.ServiceAccountApplyConfiguration
44
+ * applyrbacv1.ClusterRoleApplyConfiguration
45
+ * applyrbacv1.ClusterRoleBindingApplyConfiguration
42
46
}
43
47
44
48
// NodeInstaller constructs a node installer daemon set.
@@ -118,33 +122,70 @@ func NodeInstaller(namespace string, platform platforms.Platform) (*NodeInstalle
118
122
),
119
123
}
120
124
125
+ nydusPull := Container ().
126
+ WithName ("nydus-pull" ).
127
+ WithImage ("ghcr.io/edgelesssys/contrast/nydus-pull:latest" ).
128
+ WithArgs (runtimeHandler ).
129
+ WithEnv (
130
+ EnvVar ().
131
+ WithName ("NODE_NAME" ).
132
+ WithValueFrom (
133
+ applycorev1 .EnvVarSource ().
134
+ WithFieldRef (
135
+ applycorev1 .ObjectFieldSelector ().
136
+ WithFieldPath ("spec.nodeName" ),
137
+ ),
138
+ ),
139
+ ).
140
+ WithVolumeMounts (
141
+ VolumeMount ().
142
+ WithName ("containerd-socket" ).
143
+ WithMountPath ("/run/containerd/containerd.sock" ),
144
+ )
145
+
121
146
var nodeInstallerImageURL string
122
- var snapshotter * applycorev1.ContainerApplyConfiguration
147
+ var containers [] * applycorev1.ContainerApplyConfiguration
123
148
var snapshotterVolumes []* applycorev1.VolumeApplyConfiguration
124
149
switch platform {
125
150
case platforms .AKSCloudHypervisorSNP :
126
151
nodeInstallerImageURL = "ghcr.io/edgelesssys/contrast/node-installer-microsoft:latest"
127
- snapshotter = tardevSnapshotter
152
+ containers = append ( containers , tardevSnapshotter )
128
153
snapshotterVolumes = tardevSnapshotterVolumes
129
154
case platforms .MetalQEMUSNP , platforms .MetalQEMUTDX , platforms .MetalQEMUSNPGPU :
130
155
nodeInstallerImageURL = "ghcr.io/edgelesssys/contrast/node-installer-kata:latest"
131
- snapshotter = nydusSnapshotter
132
- nydusSnapshotterVolumes = append (nydusSnapshotterVolumes , Volume ().
133
- WithName ("var-lib-containerd" ).
134
- WithHostPath (HostPathVolumeSource ().
135
- WithPath ("/var/lib/containerd" ).
136
- WithType (corev1 .HostPathDirectory ),
137
- ))
156
+ containers = append (containers , nydusSnapshotter , nydusPull )
157
+ nydusSnapshotterVolumes = append (nydusSnapshotterVolumes ,
158
+ Volume ().
159
+ WithName ("var-lib-containerd" ).
160
+ WithHostPath (HostPathVolumeSource ().
161
+ WithPath ("/var/lib/containerd" ).
162
+ WithType (corev1 .HostPathDirectory ),
163
+ ),
164
+ Volume ().
165
+ WithName ("containerd-socket" ).
166
+ WithHostPath (HostPathVolumeSource ().
167
+ WithPath ("/run/containerd/containerd.sock" ).
168
+ WithType (corev1 .HostPathSocket ),
169
+ ),
170
+ )
138
171
snapshotterVolumes = nydusSnapshotterVolumes
139
172
case platforms .K3sQEMUTDX , platforms .K3sQEMUSNP , platforms .K3sQEMUSNPGPU , platforms .RKE2QEMUTDX :
140
173
nodeInstallerImageURL = "ghcr.io/edgelesssys/contrast/node-installer-kata:latest"
141
- snapshotter = nydusSnapshotter
142
- nydusSnapshotterVolumes = append (nydusSnapshotterVolumes , Volume ().
143
- WithName ("var-lib-containerd" ).
144
- WithHostPath (HostPathVolumeSource ().
145
- WithPath ("/var/lib/rancher/k3s/agent/containerd" ).
146
- WithType (corev1 .HostPathDirectory ),
147
- ))
174
+ containers = append (containers , nydusSnapshotter , nydusPull )
175
+ nydusSnapshotterVolumes = append (nydusSnapshotterVolumes ,
176
+ Volume ().
177
+ WithName ("var-lib-containerd" ).
178
+ WithHostPath (HostPathVolumeSource ().
179
+ WithPath ("/var/lib/rancher/k3s/agent/containerd" ).
180
+ WithType (corev1 .HostPathDirectory ),
181
+ ),
182
+ Volume ().
183
+ WithName ("containerd-socket" ).
184
+ WithHostPath (HostPathVolumeSource ().
185
+ WithPath ("/run/k3s/containerd/containerd.sock" ).
186
+ WithType (corev1 .HostPathSocket ),
187
+ ),
188
+ )
148
189
snapshotterVolumes = nydusSnapshotterVolumes
149
190
default :
150
191
return nil , fmt .Errorf ("unsupported platform %q" , platform )
@@ -163,6 +204,7 @@ func NodeInstaller(namespace string, platform platforms.Platform) (*NodeInstalle
163
204
"contrast.edgeless.systems/platform" : platform .String (),
164
205
}).
165
206
WithSpec (PodSpec ().
207
+ WithServiceAccountName ("nodeinstaller-serviceaccount" ).
166
208
WithHostPID (true ).
167
209
WithInitContainers (Container ().
168
210
WithName ("installer" ).
@@ -177,7 +219,7 @@ func NodeInstaller(namespace string, platform platforms.Platform) (*NodeInstalle
177
219
WithCommand ("/bin/node-installer" , platform .String ()),
178
220
).
179
221
WithContainers (
180
- snapshotter ,
222
+ containers ... ,
181
223
).
182
224
WithVolumes (append (
183
225
snapshotterVolumes ,
@@ -193,7 +235,36 @@ func NodeInstaller(namespace string, platform platforms.Platform) (*NodeInstalle
193
235
),
194
236
)
195
237
196
- return & NodeInstallerConfig {d }, nil
238
+ serviceAccount := applycorev1 .ServiceAccount ("nodeinstaller-serviceaccount" , "" )
239
+
240
+ clusterRole := applyrbacv1 .ClusterRole ("nodeinstaller-clusterrole" ).
241
+ WithRules (
242
+ applyrbacv1 .PolicyRule ().
243
+ WithAPIGroups ("" ).
244
+ WithResources ("pods" ).
245
+ WithVerbs ("watch" ),
246
+ )
247
+
248
+ clusterRoleBinding := applyrbacv1 .ClusterRoleBinding ("nodeinstaller-clusterrole-binding" ).
249
+ WithSubjects (
250
+ applyrbacv1 .Subject ().
251
+ WithKind ("ServiceAccount" ).
252
+ WithName ("nodeinstaller-serviceaccount" ).
253
+ WithNamespace (namespace ),
254
+ ).
255
+ WithRoleRef (
256
+ applyrbacv1 .RoleRef ().
257
+ WithKind ("ClusterRole" ).
258
+ WithName ("nodeinstaller-clusterrole" ).
259
+ WithAPIGroup ("rbac.authorization.k8s.io" ),
260
+ )
261
+
262
+ return & NodeInstallerConfig {
263
+ DaemonSetApplyConfiguration : d ,
264
+ ServiceAccountApplyConfiguration : serviceAccount ,
265
+ ClusterRoleApplyConfiguration : clusterRole ,
266
+ ClusterRoleBindingApplyConfiguration : clusterRoleBinding ,
267
+ }, nil
197
268
}
198
269
199
270
// PortForwarderConfig wraps a PodApplyConfiguration for a port forwarder.
0 commit comments