@@ -40,26 +40,28 @@ type WorkerPodManager interface {
4040 IsUnloaderPod (p * v1.Pod ) bool
4141 GetConfigAnnotation (p * v1.Pod ) string
4242 HashAnnotationDiffer (p1 , p2 * v1.Pod ) bool
43+ GetTolerationsAnnotation (p * v1.Pod ) string
4344}
4445
4546const (
4647 NodeModulesConfigFinalizer = "kmm.node.kubernetes.io/nodemodulesconfig-reconciler"
4748 WorkerContainerName = "worker"
4849
49- volMountPointConfig = "/etc/kmm-worker"
50- configFileName = "config.yaml"
51- configFullPath = volMountPointConfig + "/" + configFileName
52- volNameConfig = "config"
53- sharedFilesDir = "/tmp"
54- volNameTmp = "tmp"
55- volumeNameConfig = "config"
56- initContainerName = "image-extractor"
57- modulesOrderKey = "kmm.node.kubernetes.io/modules-order"
58- workerActionLoad = "Load"
59- workerActionUnload = "Unload"
60- actionLabelKey = "kmm.node.kubernetes.io/worker-action"
61- configAnnotationKey = "kmm.node.kubernetes.io/worker-config"
62- hashAnnotationKey = "kmm.node.kubernetes.io/worker-hash"
50+ volMountPointConfig = "/etc/kmm-worker"
51+ configFileName = "config.yaml"
52+ configFullPath = volMountPointConfig + "/" + configFileName
53+ volNameConfig = "config"
54+ sharedFilesDir = "/tmp"
55+ volNameTmp = "tmp"
56+ volumeNameConfig = "config"
57+ initContainerName = "image-extractor"
58+ modulesOrderKey = "kmm.node.kubernetes.io/modules-order"
59+ workerActionLoad = "Load"
60+ workerActionUnload = "Unload"
61+ actionLabelKey = "kmm.node.kubernetes.io/worker-action"
62+ configAnnotationKey = "kmm.node.kubernetes.io/worker-config"
63+ hashAnnotationKey = "kmm.node.kubernetes.io/worker-hash"
64+ tolerationsAnnotationKey = "kmm.node.kubernetes.io/worker-tolerations"
6365)
6466
6567var (
@@ -195,6 +197,9 @@ func (wpmi *workerPodManagerImpl) LoaderPodTemplate(ctx context.Context, nmc cli
195197 if err = setWorkerConfigAnnotation (pod , nms .Config ); err != nil {
196198 return nil , fmt .Errorf ("could not set worker config: %v" , err )
197199 }
200+ if err = setWorkerTolerationsAnnotation (pod , nms .Tolerations ); err != nil {
201+ return nil , fmt .Errorf ("could not set worker tolerations: %v" , err )
202+ }
198203
199204 if err = setWorkerSecurityContext (pod , wpmi .workerCfg , privileged ); err != nil {
200205 return nil , fmt .Errorf ("could not set the worker Pod as privileged: %v" , err )
@@ -220,6 +225,9 @@ func (wpmi *workerPodManagerImpl) UnloaderPodTemplate(ctx context.Context, nmc c
220225 if err = setWorkerConfigAnnotation (pod , nms .Config ); err != nil {
221226 return nil , fmt .Errorf ("could not set worker config: %v" , err )
222227 }
228+ if err = setWorkerTolerationsAnnotation (pod , nms .Tolerations ); err != nil {
229+ return nil , fmt .Errorf ("could not set worker tolerations: %v" , err )
230+ }
223231
224232 if err = setWorkerSecurityContext (pod , wpmi .workerCfg , false ); err != nil {
225233 return nil , fmt .Errorf ("could not set the worker Pod's security context: %v" , err )
@@ -284,6 +292,14 @@ func (wpmi *workerPodManagerImpl) GetConfigAnnotation(p *v1.Pod) string {
284292
285293 return p .Annotations [configAnnotationKey ]
286294}
295+ func (wpmi * workerPodManagerImpl ) GetTolerationsAnnotation (p * v1.Pod ) string {
296+
297+ if p == nil {
298+ return ""
299+ }
300+
301+ return p .Annotations [tolerationsAnnotationKey ]
302+ }
287303
288304func (wpmi * workerPodManagerImpl ) HashAnnotationDiffer (p1 , p2 * v1.Pod ) bool {
289305
@@ -455,6 +471,15 @@ func setWorkerConfigAnnotation(pod *v1.Pod, cfg kmmv1beta1.ModuleConfig) error {
455471 return nil
456472}
457473
474+ func setWorkerTolerationsAnnotation (pod * v1.Pod , tolerations []v1.Toleration ) error {
475+ b , err := yaml .Marshal (tolerations )
476+ if err != nil {
477+ return fmt .Errorf ("could not marshal the Tolerations to YAML: %v" , err )
478+ }
479+ meta .SetAnnotation (pod , tolerationsAnnotationKey , string (b ))
480+ return nil
481+ }
482+
458483func setWorkerSofdepConfig (pod * v1.Pod , modulesLoadingOrder []string ) error {
459484 softdepAnnotationValue := getModulesOrderAnnotationValue (modulesLoadingOrder )
460485 meta .SetAnnotation (pod , modulesOrderKey , softdepAnnotationValue )
0 commit comments