6
6
"fmt"
7
7
"path/filepath"
8
8
"reflect"
9
+ "strings"
9
10
10
11
kmmv1beta1 "github.com/kubernetes-sigs/kernel-module-management/api/v1beta1"
11
12
"github.com/kubernetes-sigs/kernel-module-management/internal/config"
@@ -267,7 +268,7 @@ func (w *workerHelperImpl) ProcessModuleSpec(
267
268
}
268
269
269
270
if readyCondition .Status == v1 .ConditionTrue && status .LastTransitionTime .Before (& readyCondition .LastTransitionTime ) {
270
- logger .Info ("Outdated last transition time status; creating unloader Pod" )
271
+ logger .Info ("Outdated last transition time status; creating loader Pod" )
271
272
272
273
return w .pm .CreateLoaderPod (ctx , nmc , spec )
273
274
}
@@ -497,6 +498,12 @@ func (p *podManagerImpl) CreateLoaderPod(ctx context.Context, nmc client.Object,
497
498
return fmt .Errorf ("could not set worker config: %v" , err )
498
499
}
499
500
501
+ if nms .Config .Modprobe .ModulesLoadingOrder != nil {
502
+ if err = setWorkerSofdepConfig (pod , nms .Config .Modprobe .ModulesLoadingOrder ); err != nil {
503
+ return fmt .Errorf ("could not set software dependency for mulitple modules: %v" , err )
504
+ }
505
+ }
506
+
500
507
setWorkerActionLabel (pod , WorkerActionLoad )
501
508
pod .Spec .RestartPolicy = v1 .RestartPolicyNever
502
509
@@ -517,6 +524,12 @@ func (p *podManagerImpl) CreateUnloaderPod(ctx context.Context, nmc client.Objec
517
524
return fmt .Errorf ("could not set worker config: %v" , err )
518
525
}
519
526
527
+ if nms .Config .Modprobe .ModulesLoadingOrder != nil {
528
+ if err = setWorkerSofdepConfig (pod , nms .Config .Modprobe .ModulesLoadingOrder ); err != nil {
529
+ return fmt .Errorf ("could not set software dependency for mulitple modules: %v" , err )
530
+ }
531
+ }
532
+
520
533
setWorkerActionLabel (pod , WorkerActionUnload )
521
534
522
535
return p .client .Create (ctx , pod )
@@ -725,29 +738,68 @@ func setWorkerConfigAnnotation(pod *v1.Pod, cfg kmmv1beta1.ModuleConfig) error {
725
738
if err != nil {
726
739
return fmt .Errorf ("could not marshal the ModuleConfig to YAML: %v" , err )
727
740
}
741
+ setWorkerPodAnnotation (pod , configAnnotationKey , string (b ))
728
742
729
- annotations := pod .GetAnnotations ()
743
+ return nil
744
+ }
730
745
731
- if annotations == nil {
732
- annotations = make (map [string ]string )
746
+ func setWorkerContainerArgs (pod * v1.Pod , args []string ) error {
747
+ container , _ := podcmd .FindContainerByName (pod , workerContainerName )
748
+ if container == nil {
749
+ return errors .New ("could not find the worker container" )
733
750
}
734
751
735
- annotations [configAnnotationKey ] = string (b )
736
-
737
- pod .SetAnnotations (annotations )
752
+ container .Args = args
738
753
739
754
return nil
740
755
}
741
756
742
- func setWorkerContainerArgs (pod * v1.Pod , args []string ) error {
757
+ func setWorkerSofdepConfig (pod * v1.Pod , modulesLoadingOrder []string ) error {
758
+ softdepAnnotationValue := getModulesOrderAnnotationValue (modulesLoadingOrder )
759
+ setWorkerPodAnnotation (pod , "modules-order" , softdepAnnotationValue )
760
+
761
+ softdepVolume := v1.Volume {
762
+ Name : "modules-order" ,
763
+ VolumeSource : v1.VolumeSource {
764
+ DownwardAPI : & v1.DownwardAPIVolumeSource {
765
+ Items : []v1.DownwardAPIVolumeFile {
766
+ {
767
+ Path : "softdep.conf" ,
768
+ FieldRef : & v1.ObjectFieldSelector {FieldPath : "metadata.annotations['modules-order']" },
769
+ },
770
+ },
771
+ },
772
+ },
773
+ }
774
+ softDepVolumeMount := v1.VolumeMount {
775
+ Name : "modules-order" ,
776
+ ReadOnly : true ,
777
+ MountPath : "/etc/modprobe.d" ,
778
+ }
779
+ pod .Spec .Volumes = append (pod .Spec .Volumes , softdepVolume )
743
780
container , _ := podcmd .FindContainerByName (pod , workerContainerName )
744
781
if container == nil {
745
782
return errors .New ("could not find the worker container" )
746
783
}
784
+ container .VolumeMounts = append (pod .Spec .Containers [0 ].VolumeMounts , softDepVolumeMount )
785
+ return nil
786
+ }
747
787
748
- container .Args = args
788
+ func getModulesOrderAnnotationValue (modulesNames []string ) string {
789
+ var softDepData strings.Builder
790
+ for i := 0 ; i < len (modulesNames )- 1 ; i ++ {
791
+ fmt .Fprintf (& softDepData , "softdep %s pre: %s\n " , modulesNames [i ], modulesNames [i + 1 ])
792
+ }
793
+ return softDepData .String ()
794
+ }
749
795
750
- return nil
796
+ func setWorkerPodAnnotation (pod * v1.Pod , key , value string ) {
797
+ annotations := pod .GetAnnotations ()
798
+ if annotations == nil {
799
+ annotations = make (map [string ]string )
800
+ }
801
+ annotations [key ] = value
802
+ pod .SetAnnotations (annotations )
751
803
}
752
804
753
805
//go:generate mockgen -source=nmc_reconciler.go -package=controllers -destination=mock_nmc_reconciler.go pullSecretHelper
0 commit comments