@@ -60,7 +60,9 @@ const (
6060 // 5ms, 10ms, 20ms, 40ms, 80ms, 160ms, 320ms, 640ms, 1.3s, 2.6s, 5.1s, 10.2s, 20.4s, 41s, 82s
6161 maxRetries = 15
6262
63- builtInLabelKey = "machineconfiguration.openshift.io/mco-built-in"
63+ builtInLabelKey = "machineconfiguration.openshift.io/mco-built-in"
64+ configMapName = "crio-default-container-runtime"
65+ forceSyncOnUpgrade = "force-sync-on-upgrade"
6466)
6567
6668var (
@@ -79,6 +81,7 @@ type Controller struct {
7981 templatesDir string
8082
8183 client mcfgclientset.Interface
84+ kubeClient clientset.Interface
8285 configClient configclientset.Interface
8386 eventRecorder record.EventRecorder
8487
@@ -148,6 +151,7 @@ func New(
148151 ctrl := & Controller {
149152 templatesDir : templatesDir ,
150153 client : mcfgClient ,
154+ kubeClient : kubeClient ,
151155 configClient : configClient ,
152156 eventRecorder : ctrlcommon .NamespacedEventRecorder (eventBroadcaster .NewRecorder (scheme .Scheme , corev1.EventSource {Component : "machineconfigcontroller-containerruntimeconfigcontroller" })),
153157 queue : workqueue .NewTypedRateLimitingQueueWithConfig (
@@ -213,6 +217,7 @@ func New(
213217
214218 ctrl .clusterVersionLister = clusterVersionInformer .Lister ()
215219 ctrl .clusterVersionListerSynced = clusterVersionInformer .Informer ().HasSynced
220+ ctrl .queue .Add (forceSyncOnUpgrade )
216221
217222 ctrl .fgHandler = fgHandler
218223
@@ -596,6 +601,60 @@ func (ctrl *Controller) addAnnotation(cfg *mcfgv1.ContainerRuntimeConfig, annota
596601 return annotationUpdateErr
597602}
598603
604+ // migrateRuncToCrun performs the upgrade migration from runc to crun as the default container runtime.
605+ // This function checks for the existence of the crio-default-container-runtime ConfigMap. If it exists,
606+ // it deletes the MachineConfigs for master and worker pools, then deletes the ConfigMap to prevent
607+ // re-running the migration.
608+ func (ctrl * Controller ) migrateRuncToCrun () error {
609+ // Check if the migration ConfigMap exists
610+ _ , err := ctrl .kubeClient .CoreV1 ().ConfigMaps (ctrlcommon .MCONamespace ).Get (context .TODO (), configMapName , metav1.GetOptions {})
611+ if errors .IsNotFound (err ) {
612+ // ConfigMap doesn't exist, no migration needed
613+ return nil
614+ }
615+ if err != nil {
616+ return fmt .Errorf ("error checking for crio-default-container-runtime configmap: %w" , err )
617+ }
618+
619+ klog .Info ("Found crio-default-container-runtime ConfigMap, starting migration from runc to crun" )
620+
621+ // Get all MachineConfigPools
622+ pools , err := ctrl .mcpLister .List (labels .Everything ())
623+ if err != nil {
624+ return fmt .Errorf ("error listing MachineConfigPools: %w" , err )
625+ }
626+
627+ // Only process master and worker pools for the migration
628+ for _ , pool := range pools {
629+ if pool .Name != ctrlcommon .MachineConfigPoolMaster && pool .Name != ctrlcommon .MachineConfigPoolWorker {
630+ continue
631+ }
632+
633+ // Get the MachineConfig name for this pool
634+ mcName := fmt .Sprintf ("00-override-%s-generated-crio-default-container-runtime" , pool .Name )
635+
636+ // Delete the existing MachineConfig
637+ err := ctrl .client .MachineconfigurationV1 ().MachineConfigs ().Delete (context .TODO (), mcName , metav1.DeleteOptions {})
638+ if errors .IsNotFound (err ) {
639+ klog .Infof ("MachineConfig %s not found, skipping migration for pool %s" , mcName , pool .Name )
640+ continue
641+ }
642+ if err != nil {
643+ return fmt .Errorf ("error deleting MachineConfig %s: %w" , mcName , err )
644+ }
645+
646+ klog .Infof ("Successfully deleted MachineConfig %s" , mcName )
647+ }
648+
649+ // Delete the ConfigMap after successful migration
650+ if err := ctrl .kubeClient .CoreV1 ().ConfigMaps (ctrlcommon .MCONamespace ).Delete (context .TODO (), configMapName , metav1.DeleteOptions {}); err != nil && ! errors .IsNotFound (err ) {
651+ return fmt .Errorf ("error deleting crio-default-container-runtime configmap: %w" , err )
652+ }
653+
654+ klog .Info ("Successfully completed migration from runc to crun and deleted migration ConfigMap" )
655+ return nil
656+ }
657+
599658// syncContainerRuntimeConfig will sync the ContainerRuntimeconfig with the given key.
600659// This function is not meant to be invoked concurrently with the same key.
601660// nolint: gocyclo
@@ -606,6 +665,17 @@ func (ctrl *Controller) syncContainerRuntimeConfig(key string) error {
606665 klog .V (4 ).Infof ("Finished syncing ContainerRuntimeconfig %q (%v)" , key , time .Since (startTime ))
607666 }()
608667
668+ // OKD only: Run the migration function at the start of sync
669+ if version .IsSCOS () {
670+ if err := ctrl .migrateRuncToCrun (); err != nil {
671+ return fmt .Errorf ("Error during runc to crun migration: %w" , err )
672+ }
673+ }
674+
675+ if key == forceSyncOnUpgrade {
676+ return nil
677+ }
678+
609679 _ , name , err := cache .SplitMetaNamespaceKey (key )
610680 if err != nil {
611681 return err
0 commit comments