@@ -1251,6 +1251,11 @@ func (optr *Operator) reconcileMachineOSBuilder(mob *appsv1.Deployment) error {
1251
1251
return fmt .Errorf ("could not reconcile etc-pki-entitlement secrets: %w" , err )
1252
1252
}
1253
1253
1254
+ // Create/Deletes the global pull secret copy in the MCO namespace, depending on layered pool count.
1255
+ if err := optr .reconcileGlobalPullSecretCopy (layeredMCPs ); err != nil {
1256
+ return fmt .Errorf ("could not reconcile global pull secret copy: %w" , err )
1257
+ }
1258
+
1254
1259
// If we have opted-in pools and the Machine OS Builder deployment is either
1255
1260
// not running or doesn't have the correct replica count, scale it up.
1256
1261
correctReplicaCount := optr .hasCorrectReplicaCount (mob )
@@ -1457,6 +1462,57 @@ func (optr *Operator) reconcileSimpleContentAccessSecrets(layeredMCPs []*mcfgv1.
1457
1462
return nil
1458
1463
}
1459
1464
1465
+ func (optr * Operator ) reconcileGlobalPullSecretCopy (layeredMCPs []* mcfgv1.MachineConfigPool ) error {
1466
+ secretCopyExists := true
1467
+ currentSecretCopy , err := optr .mcoSecretLister .Secrets (ctrlcommon .MCONamespace ).Get (ctrlcommon .GlobalPullSecretCopyName )
1468
+ if apierrors .IsNotFound (err ) {
1469
+ secretCopyExists = false
1470
+ } else if err != nil {
1471
+ return err
1472
+ }
1473
+
1474
+ if len (layeredMCPs ) == 0 {
1475
+ // If the secret copy doesn't exist, nothing to do here
1476
+ if ! secretCopyExists {
1477
+ return nil
1478
+ }
1479
+ klog .Infof ("deleting %s" , ctrlcommon .GlobalPullSecretCopyName )
1480
+ return optr .kubeClient .CoreV1 ().Secrets (ctrlcommon .MCONamespace ).Delete (context .TODO (), ctrlcommon .GlobalPullSecretCopyName , metav1.DeleteOptions {})
1481
+ }
1482
+
1483
+ // Atleast one pool is opted-in, let's create or update the copy if needed. First, grab the global pull secret.
1484
+ globalPullSecret , err := optr .ocSecretLister .Secrets (ctrlcommon .OpenshiftConfigNamespace ).Get ("pull-secret" )
1485
+ if err != nil {
1486
+ return fmt .Errorf ("error fetching cluster pull secret: %w" , err )
1487
+ }
1488
+
1489
+ // Create a clone of clusterPullSecret, and modify it to be in the MCO namespace.
1490
+ globalPullSecretCopy := & corev1.Secret {
1491
+ ObjectMeta : metav1.ObjectMeta {
1492
+ Name : ctrlcommon .GlobalPullSecretCopyName ,
1493
+ Namespace : ctrlcommon .MCONamespace ,
1494
+ },
1495
+ Data : globalPullSecret .Data ,
1496
+ Type : corev1 .SecretTypeDockerConfigJson ,
1497
+ }
1498
+
1499
+ // If the secret copy doesn't exist, create it.
1500
+ if ! secretCopyExists {
1501
+ klog .Infof ("creating %s" , ctrlcommon .GlobalPullSecretCopyName )
1502
+ _ , err := optr .kubeClient .CoreV1 ().Secrets (ctrlcommon .MCONamespace ).Create (context .TODO (), globalPullSecretCopy , metav1.CreateOptions {})
1503
+ return err
1504
+ }
1505
+
1506
+ // If it does exist, check if an update is required before making the update call.
1507
+ if ! reflect .DeepEqual (currentSecretCopy .Data , globalPullSecret .Data ) {
1508
+ klog .Infof ("updating %s" , ctrlcommon .GlobalPullSecretCopyName )
1509
+ _ , err := optr .kubeClient .CoreV1 ().Secrets (ctrlcommon .MCONamespace ).Update (context .TODO (), globalPullSecretCopy , metav1.UpdateOptions {})
1510
+ return err
1511
+ }
1512
+
1513
+ return nil
1514
+ }
1515
+
1460
1516
// Updates the Machine OS Builder Deployment, creating it if it does not exist.
1461
1517
func (optr * Operator ) startMachineOSBuilderDeployment (mob * appsv1.Deployment , layeredMCPs []* mcfgv1.MachineConfigPool ) error {
1462
1518
if err := build .ValidateOnClusterBuildConfig (optr .kubeClient , optr .client , layeredMCPs ); err != nil {
0 commit comments