@@ -626,6 +626,26 @@ func (r *Reconciler) SetupWithManager(mgr runtime.Manager) error {
626626 handleResourceSnapshot (e .Object , q )
627627 },
628628 }).
629+ Watches (& fleetv1alpha1.ClusterResourceOverrideSnapshot {}, handler.Funcs {
630+ CreateFunc : func (ctx context.Context , e event.CreateEvent , q workqueue.RateLimitingInterface ) {
631+ klog .V (2 ).InfoS ("Handling a clusterResourceOverrideSnapshot create event" , "clusterResourceOverrideSnapshot" , klog .KObj (e .Object ))
632+ handleClusterResourceOverrideSnapshot (e .Object , q )
633+ },
634+ GenericFunc : func (ctx context.Context , e event.GenericEvent , q workqueue.RateLimitingInterface ) {
635+ klog .V (2 ).InfoS ("Handling a clusterResourceOverrideSnapshot generic event" , "clusterResourceOverrideSnapshot" , klog .KObj (e .Object ))
636+ handleClusterResourceOverrideSnapshot (e .Object , q )
637+ },
638+ }).
639+ Watches (& fleetv1alpha1.ResourceOverrideSnapshot {}, handler.Funcs {
640+ CreateFunc : func (ctx context.Context , e event.CreateEvent , q workqueue.RateLimitingInterface ) {
641+ klog .V (2 ).InfoS ("Handling a resourceOverrideSnapshot create event" , "resourceOverrideSnapshot" , klog .KObj (e .Object ))
642+ handleResourceOverrideSnapshot (e .Object , q )
643+ },
644+ GenericFunc : func (ctx context.Context , e event.GenericEvent , q workqueue.RateLimitingInterface ) {
645+ klog .V (2 ).InfoS ("Handling a resourceOverrideSnapshot generic event" , "resourceOverrideSnapshot" , klog .KObj (e .Object ))
646+ handleResourceOverrideSnapshot (e .Object , q )
647+ },
648+ }).
629649 Watches (& fleetv1beta1.ClusterResourceBinding {}, handler.Funcs {
630650 CreateFunc : func (ctx context.Context , e event.CreateEvent , q workqueue.RateLimitingInterface ) {
631651 klog .V (2 ).InfoS ("Handling a resourceBinding create event" , "resourceBinding" , klog .KObj (e .Object ))
@@ -643,6 +663,72 @@ func (r *Reconciler) SetupWithManager(mgr runtime.Manager) error {
643663 Complete (r )
644664}
645665
666+ // handleClusterResourceOverrideSnapshot parse the clusterResourceOverrideSnapshot label and enqueue the CRP name associated
667+ // with the clusterResourceOverrideSnapshot if set.
668+ func handleClusterResourceOverrideSnapshot (o client.Object , q workqueue.RateLimitingInterface ) {
669+ snapshot , ok := o .(* fleetv1alpha1.ClusterResourceOverrideSnapshot )
670+ if ! ok {
671+ klog .ErrorS (controller .NewUnexpectedBehaviorError (fmt .Errorf ("non ClusterResourceOverrideSnapshot type resource: %+v" , o )),
672+ "Rollout controller received invalid ClusterResourceOverrideSnapshot event" , "object" , klog .KObj (o ))
673+ return
674+ }
675+
676+ snapshotKRef := klog .KObj (snapshot )
677+ // check if it is the latest resource resourceBinding
678+ isLatest , err := strconv .ParseBool (snapshot .GetLabels ()[fleetv1beta1 .IsLatestSnapshotLabel ])
679+ if err != nil {
680+ klog .ErrorS (controller .NewUnexpectedBehaviorError (fmt .Errorf ("invalid label value %s : %w" , fleetv1beta1 .IsLatestSnapshotLabel , err )),
681+ "Resource clusterResourceOverrideSnapshot has does not have a valid islatest label" , "clusterResourceOverrideSnapshot" , snapshotKRef )
682+ return
683+ }
684+ if ! isLatest {
685+ // All newly created resource snapshots should start with the latest label to be true.
686+ // However, this can happen if the label is removed fast by the time this reconcile loop is triggered.
687+ klog .V (2 ).InfoS ("Newly created resource clusterResourceOverrideSnapshot %s is not the latest" , "clusterResourceOverrideSnapshot" , snapshotKRef )
688+ return
689+ }
690+ if snapshot .Spec .OverrideSpec .Placement == nil {
691+ return
692+ }
693+ // enqueue the CRP to the rollout controller queue
694+ q .Add (reconcile.Request {
695+ NamespacedName : types.NamespacedName {Name : snapshot .Spec .OverrideSpec .Placement .Name },
696+ })
697+ }
698+
699+ // handleResourceOverrideSnapshot parse the resourceOverrideSnapshot label and enqueue the CRP name associated with the
700+ // resourceOverrideSnapshot if set.
701+ func handleResourceOverrideSnapshot (o client.Object , q workqueue.RateLimitingInterface ) {
702+ snapshot , ok := o .(* fleetv1alpha1.ResourceOverrideSnapshot )
703+ if ! ok {
704+ klog .ErrorS (controller .NewUnexpectedBehaviorError (fmt .Errorf ("non ResourceOverrideSnapshot type resource: %+v" , o )),
705+ "Rollout controller received invalid ResourceOverrideSnapshot event" , "object" , klog .KObj (o ))
706+ return
707+ }
708+
709+ snapshotKRef := klog .KObj (snapshot )
710+ // check if it is the latest resource resourceBinding
711+ isLatest , err := strconv .ParseBool (snapshot .GetLabels ()[fleetv1beta1 .IsLatestSnapshotLabel ])
712+ if err != nil {
713+ klog .ErrorS (controller .NewUnexpectedBehaviorError (fmt .Errorf ("invalid label value %s : %w" , fleetv1beta1 .IsLatestSnapshotLabel , err )),
714+ "Resource resourceOverrideSnapshot has does not have a valid islatest annotation" , "resourceOverrideSnapshot" , snapshotKRef )
715+ return
716+ }
717+ if ! isLatest {
718+ // All newly created resource snapshots should start with the latest label to be true.
719+ // However, this can happen if the label is removed fast by the time this reconcile loop is triggered.
720+ klog .V (2 ).InfoS ("Newly created resource resourceOverrideSnapshot %s is not the latest" , "resourceOverrideSnapshot" , snapshotKRef )
721+ return
722+ }
723+ if snapshot .Spec .OverrideSpec .Placement == nil {
724+ return
725+ }
726+ // enqueue the CRP to the rollout controller queue
727+ q .Add (reconcile.Request {
728+ NamespacedName : types.NamespacedName {Name : snapshot .Spec .OverrideSpec .Placement .Name },
729+ })
730+ }
731+
646732// handleResourceSnapshot parse the resourceBinding label and annotation and enqueue the CRP name associated with the resource resourceBinding
647733func handleResourceSnapshot (snapshot client.Object , q workqueue.RateLimitingInterface ) {
648734 snapshotKRef := klog .KObj (snapshot )
@@ -656,14 +742,14 @@ func handleResourceSnapshot(snapshot client.Object, q workqueue.RateLimitingInte
656742 // check if it is the latest resource resourceBinding
657743 isLatest , err := strconv .ParseBool (snapshot .GetLabels ()[fleetv1beta1 .IsLatestSnapshotLabel ])
658744 if err != nil {
659- klog .ErrorS (controller .NewUnexpectedBehaviorError (fmt .Errorf ("invalid annotation value %s : %w" , fleetv1beta1 .IsLatestSnapshotLabel , err )),
660- "Resource resourceBinding has does not have a valid islatest annotation" , "clusterResourceSnapshot" , snapshotKRef )
745+ klog .ErrorS (controller .NewUnexpectedBehaviorError (fmt .Errorf ("invalid label value %s : %w" , fleetv1beta1 .IsLatestSnapshotLabel , err )),
746+ "Resource clusterResourceSnapshot has does not have a valid islatest annotation" , "clusterResourceSnapshot" , snapshotKRef )
661747 return
662748 }
663749 if ! isLatest {
664750 // All newly created resource snapshots should start with the latest label to be true.
665751 // However, this can happen if the label is removed fast by the time this reconcile loop is triggered.
666- klog .V (2 ).InfoS ("Newly created resource resourceBinding %s is not the latest" , "clusterResourceSnapshot" , snapshotKRef )
752+ klog .V (2 ).InfoS ("Newly created resource clusterResourceSnapshot %s is not the latest" , "clusterResourceSnapshot" , snapshotKRef )
667753 return
668754 }
669755 // get the CRP name from the label
0 commit comments