@@ -56,6 +56,14 @@ type ShimReconciler struct {
5656 Scheme * runtime.Scheme
5757}
5858
59+ // configuration for INSTALL or UNINSTALL jobs
60+ type opConfig struct {
61+ operation string
62+ privileged bool
63+ initContainer []corev1.Container
64+ args []string
65+ }
66+
5967//+kubebuilder:rbac:groups=runtime.kwasm.sh,resources=shims,verbs=get;list;watch;create;update;patch;delete
6068//+kubebuilder:rbac:groups=runtime.kwasm.sh,resources=shims/status,verbs=get;update;patch
6169//+kubebuilder:rbac:groups=runtime.kwasm.sh,resources=shims/finalizers,verbs=update
@@ -301,7 +309,7 @@ func (sr *ShimReconciler) deployJobOnNode(ctx context.Context, shim *rcmv1.Shim,
301309
302310 // We rely on controller-runtime to rate limit us.
303311 if err := sr .Client .Patch (ctx , job , patchMethod , patchOptions ); err != nil {
304- log .Error ().Msgf ("Unable to reconcile Job %s" , err )
312+ log .Error ().Msgf ("Unable to reconcile Job: %s" , err )
305313 if err := sr .updateNodeLabels (ctx , & node , shim , "failed" ); err != nil {
306314 log .Error ().Msgf ("Unable to update node label %s: %s" , shim .Name , err )
307315 }
@@ -321,13 +329,69 @@ func (sr *ShimReconciler) updateNodeLabels(ctx context.Context, node *corev1.Nod
321329 return nil
322330}
323331
332+ // setOperationConfiguration sets operation specific configuration for the job manifest
333+ func (sr * ShimReconciler ) setOperationConfiguration (shim * rcmv1.Shim , opConfig * opConfig ) {
334+ if opConfig .operation == INSTALL {
335+ opConfig .initContainer = []corev1.Container {{
336+ Image : os .Getenv ("SHIM_DOWNLOADER_IMAGE" ),
337+ Name : "downloader" ,
338+ SecurityContext : & corev1.SecurityContext {
339+ Privileged : & opConfig .privileged ,
340+ },
341+ Env : []corev1.EnvVar {
342+ {
343+ Name : "SHIM_NAME" ,
344+ Value : shim .Name ,
345+ },
346+ {
347+ Name : "SHIM_LOCATION" ,
348+ Value : shim .Spec .FetchStrategy .AnonHTTP .Location ,
349+ },
350+ },
351+ VolumeMounts : []corev1.VolumeMount {
352+ {
353+ Name : "shim-download" ,
354+ MountPath : "/assets" ,
355+ },
356+ },
357+ }}
358+ opConfig .args = []string {
359+ "install" ,
360+ "-H" ,
361+ "/mnt/node-root" ,
362+ "-r" ,
363+ shim .Name ,
364+ }
365+ }
366+
367+ if opConfig .operation == UNINSTALL {
368+ opConfig .initContainer = nil
369+ opConfig .args = []string {
370+ "uninstall" ,
371+ "-H" ,
372+ "/mnt/node-root" ,
373+ "-r" ,
374+ shim .Name ,
375+ }
376+ }
377+ }
378+
324379// createJobManifest creates a Job manifest for a Shim.
325380func (sr * ShimReconciler ) createJobManifest (shim * rcmv1.Shim , node * corev1.Node , operation string ) (* batchv1.Job , error ) {
326- priv := true
381+ opConfig := opConfig {
382+ operation : operation ,
383+ privileged : true ,
384+ }
385+ sr .setOperationConfiguration (shim , & opConfig )
386+
327387 name := node .Name + "-" + shim .Name + "-" + operation
328388 nameMax := int (math .Min (float64 (len (name )), 63 ))
329389
330390 job := & batchv1.Job {
391+ TypeMeta : metav1.TypeMeta {
392+ APIVersion : "batch/v1" ,
393+ Kind : "Job" ,
394+ },
331395 ObjectMeta : metav1.ObjectMeta {
332396 Name : name [:nameMax ],
333397 Namespace : os .Getenv ("CONTROLLER_NAMESPACE" ),
@@ -348,37 +412,32 @@ func (sr *ShimReconciler) createJobManifest(shim *rcmv1.Shim, node *corev1.Node,
348412 Spec : corev1.PodSpec {
349413 NodeName : node .Name ,
350414 HostPID : true ,
351- Volumes : []corev1.Volume {{
352- Name : "root-mount" ,
353- VolumeSource : corev1.VolumeSource {
354- HostPath : & corev1.HostPathVolumeSource {
355- Path : "/" ,
415+ Volumes : []corev1.Volume {
416+ {
417+ Name : "shim-download" ,
418+ },
419+ {
420+ Name : "root-mount" ,
421+ VolumeSource : corev1.VolumeSource {
422+ HostPath : & corev1.HostPathVolumeSource {
423+ Path : "/" ,
424+ },
356425 },
357426 },
358- }},
427+ },
428+ InitContainers : opConfig .initContainer ,
359429 Containers : []corev1.Container {{
360- Image : "voigt/kwasm-node-installer:" + operation ,
430+ Image : os .Getenv ("SHIM_NODE_INSTALLER_IMAGE" ),
431+ Args : opConfig .args ,
361432 Name : "provisioner" ,
362433 SecurityContext : & corev1.SecurityContext {
363- Privileged : & priv ,
434+ Privileged : & opConfig . privileged ,
364435 },
365436 Env : []corev1.EnvVar {
366437 {
367- Name : "NODE_ROOT " ,
438+ Name : "HOST_ROOT " ,
368439 Value : "/mnt/node-root" ,
369440 },
370- {
371- Name : "SHIM_LOCATION" ,
372- Value : shim .Spec .FetchStrategy .AnonHTTP .Location ,
373- },
374- {
375- Name : "RUNTIMECLASS_NAME" ,
376- Value : shim .Spec .RuntimeClass .Name ,
377- },
378- {
379- Name : "RUNTIMECLASS_HANDLER" ,
380- Value : shim .Spec .RuntimeClass .Handler ,
381- },
382441 {
383442 Name : "SHIM_FETCH_STRATEGY" ,
384443 Value : "/mnt/node-root" ,
@@ -389,6 +448,10 @@ func (sr *ShimReconciler) createJobManifest(shim *rcmv1.Shim, node *corev1.Node,
389448 Name : "root-mount" ,
390449 MountPath : "/mnt/node-root" ,
391450 },
451+ {
452+ Name : "shim-download" ,
453+ MountPath : "/assets" ,
454+ },
392455 },
393456 }},
394457 RestartPolicy : corev1 .RestartPolicyNever ,
@@ -443,6 +506,10 @@ func (sr *ShimReconciler) createRuntimeClassManifest(shim *rcmv1.Shim) (*nodev1.
443506 }
444507
445508 runtimeClass := & nodev1.RuntimeClass {
509+ TypeMeta : metav1.TypeMeta {
510+ APIVersion : "node.k8s.io/v1" ,
511+ Kind : "RuntimeClass" ,
512+ },
446513 ObjectMeta : metav1.ObjectMeta {
447514 Name : name [:nameMax ],
448515 Labels : map [string ]string {name [:nameMax ]: "true" },
0 commit comments