@@ -388,14 +388,22 @@ func (b *buildReconciler) updateMachineOSConfigStatus(ctx context.Context, mosc
388388 return nil
389389 }
390390
391- // skip the status update if the current image pullspec equals the digest image pushspec.
392- if mosc .Status .CurrentImagePullSpec == mosb .Status .DigestedImagePushSpec {
393- klog .Infof ("MachineOSConfig %q already has final image pushspec for MachineOSBuild %q" , mosc .Name , mosb .Name )
391+ // Check if the machineOSBuild reference matches
392+ machineOSBuildRefMatches := mosc .Status .MachineOSBuild != nil && mosc .Status .MachineOSBuild .Name == mosb .Name
393+
394+ // skip the status update if both the current image pullspec and machineOSBuild reference are already correct.
395+ if mosc .Status .CurrentImagePullSpec == mosb .Status .DigestedImagePushSpec && machineOSBuildRefMatches {
396+ klog .Infof ("MachineOSConfig %q already has final image pushspec and machineOSBuild reference for MachineOSBuild %q" , mosc .Name , mosb .Name )
394397 return nil
395398 }
396399
397400 mosc .Status .CurrentImagePullSpec = mosb .Status .DigestedImagePushSpec
398401 mosc .Status .ObservedGeneration = mosc .GetGeneration ()
402+ mosc .Status .MachineOSBuild = & mcfgv1.ObjectReference {
403+ Name : mosb .Name ,
404+ Group : mcfgv1 .SchemeGroupVersion .Group ,
405+ Resource : "machineosbuilds" ,
406+ }
399407
400408 _ , err = b .mcfgclient .MachineconfigurationV1 ().MachineOSConfigs ().UpdateStatus (ctx , mosc , metav1.UpdateOptions {})
401409 if err == nil {
@@ -1245,6 +1253,19 @@ func (b *buildReconciler) syncMachineOSConfigs(ctx context.Context) error {
12451253// should be created.
12461254func (b * buildReconciler ) syncMachineOSConfig (ctx context.Context , mosc * mcfgv1.MachineOSConfig ) error {
12471255 return b .timeObjectOperation (mosc , syncingVerb , func () error {
1256+ // Check if we need to clean up the pre-built image annotation after successful seeding
1257+ // This happens in a separate reconciliation to ensure status is persisted before removing annotation
1258+ if needsPreBuiltImageAnnotationCleanup (mosc ) {
1259+ klog .Infof ("MachineOSConfig %q seeding complete and status populated, removing pre-built image annotation" , mosc .Name )
1260+ delete (mosc .Annotations , constants .PreBuiltImageAnnotationKey )
1261+ if _ , err := b .mcfgclient .MachineconfigurationV1 ().MachineOSConfigs ().Update (ctx , mosc , metav1.UpdateOptions {}); err != nil {
1262+ return fmt .Errorf ("could not remove pre-built image annotation from MachineOSConfig %q: %w" , mosc .Name , err )
1263+ }
1264+ klog .Infof ("Successfully removed pre-built image annotation from MachineOSConfig %q" , mosc .Name )
1265+ // Trigger another sync to handle any pending work now that annotation is removed
1266+ return nil
1267+ }
1268+
12481269 mosbs , err := b .getMachineOSBuildsForMachineOSConfig (mosc )
12491270 if err != nil {
12501271 return fmt .Errorf ("could not list MachineOSBuilds for MachineOSConfig %q: %w" , mosc .Name , err )
@@ -1331,8 +1352,9 @@ func (b *buildReconciler) reconcilePoolChange(ctx context.Context, mcp *mcfgv1.M
13311352
13321353 // If the MachineOSConfig has a pre-built image annotation AND hasn't been seeded yet,
13331354 // the seeding workflow should handle creating the synthetic build. Don't proceed with normal build workflow.
1355+ // Seeding is considered complete once the currentBuild annotation is set.
13341356 firstOptIn := mosc .Annotations [constants .CurrentMachineOSBuildAnnotationKey ]
1335- if hasPreBuiltImageAnnotation (mosc ) && ! hasPreBuiltImageSeededAnnotation ( mosc ) && firstOptIn == "" {
1357+ if hasPreBuiltImageAnnotation (mosc ) && firstOptIn == "" {
13361358 klog .Infof ("MachineOSConfig %q has pre-built image annotation but hasn't been seeded yet, skipping pool change reconciliation (seeding workflow should handle this)" , mosc .Name )
13371359 return nil
13381360 }
@@ -1861,9 +1883,9 @@ func (b *buildReconciler) createSyntheticMachineOSBuild(ctx context.Context, mos
18611883
18621884// updateMachineOSConfigForSeeding updates MachineOSConfig for seeded state
18631885func (b * buildReconciler ) updateMachineOSConfigForSeeding (ctx context.Context , mosc * mcfgv1.MachineOSConfig , mosb * mcfgv1.MachineOSBuild , imageSpec string ) error {
1864- // Update annotations - add both current build and seeded marker
1886+ // Update annotations - set current build annotation to mark seeding as complete
1887+ // The currentBuild annotation serves as the marker that seeding has occurred
18651888 metav1 .SetMetaDataAnnotation (& mosc .ObjectMeta , constants .CurrentMachineOSBuildAnnotationKey , mosb .Name )
1866- metav1 .SetMetaDataAnnotation (& mosc .ObjectMeta , constants .PreBuiltImageSeededAnnotationKey , "true" )
18671889
18681890 // Update the MachineOSConfig object
18691891 updatedMOSC , err := b .mcfgclient .MachineconfigurationV1 ().MachineOSConfigs ().Update (ctx , mosc , metav1.UpdateOptions {})
0 commit comments