Skip to content

Commit 9bb7e72

Browse files
author
Ryan Zhang
committed
address comment
Signed-off-by: Ryan Zhang <[email protected]>
1 parent 9285e39 commit 9bb7e72

File tree

4 files changed

+4
-45
lines changed

4 files changed

+4
-45
lines changed

pkg/controllers/rollout/controller.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req runtime.Request) (runtim
153153
"placement", placementObjRef)
154154
return runtime.Result{}, err
155155
}
156-
if masterResourceSnapshot == nil {
157-
err := controller.NewUnexpectedBehaviorError(fmt.Errorf("no masterResourceSnapshot found for the placement %s", placementKey))
158-
return runtime.Result{}, err
159-
}
160156
klog.V(2).InfoS("Found the masterResourceSnapshot for the placement", "placement", placementObjRef, "masterResourceSnapshot", klog.KObj(masterResourceSnapshot))
161157

162158
// Note: there is a corner case that an override is in-between snapshots (the old one is marked as not the latest while the new one is not created yet)
@@ -701,16 +697,6 @@ func (r *Reconciler) SetupWithManager(mgr runtime.Manager) error {
701697
handleResourceSnapshot(e.Object, q)
702698
},
703699
}).
704-
Watches(&fleetv1beta1.ResourceSnapshot{}, handler.Funcs{
705-
CreateFunc: func(ctx context.Context, e event.CreateEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
706-
klog.V(2).InfoS("Handling a resource snapshot create event", "resourceSnapshot", klog.KObj(e.Object))
707-
handleResourceSnapshot(e.Object, q)
708-
},
709-
GenericFunc: func(ctx context.Context, e event.GenericEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
710-
klog.V(2).InfoS("Handling a resource snapshot generic event", "resourceSnapshot", klog.KObj(e.Object))
711-
handleResourceSnapshot(e.Object, q)
712-
},
713-
}).
714700
Watches(&fleetv1alpha1.ClusterResourceOverrideSnapshot{}, handler.Funcs{
715701
CreateFunc: func(ctx context.Context, e event.CreateEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
716702
klog.V(2).InfoS("Handling a clusterResourceOverrideSnapshot create event", "clusterResourceOverrideSnapshot", klog.KObj(e.Object))
@@ -778,19 +764,6 @@ func (r *Reconciler) SetupWithManager(mgr runtime.Manager) error {
778764
enqueueResourceBinding(e.Object, q)
779765
},
780766
}).
781-
Watches(&fleetv1beta1.ResourceBinding{}, handler.Funcs{
782-
CreateFunc: func(ctx context.Context, e event.CreateEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
783-
klog.V(2).InfoS("Handling a resource binding create event", "resourceBinding", klog.KObj(e.Object))
784-
enqueueResourceBinding(e.Object, q)
785-
},
786-
UpdateFunc: func(ctx context.Context, e event.UpdateEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
787-
handleResourceBindingUpdated(e.ObjectNew, e.ObjectOld, q)
788-
},
789-
GenericFunc: func(ctx context.Context, e event.GenericEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
790-
klog.V(2).InfoS("Handling a resource binding generic event", "resourceBinding", klog.KObj(e.Object))
791-
enqueueResourceBinding(e.Object, q)
792-
},
793-
}).
794767
// Aside from resource snapshot and binding objects, the rollout
795768
// controller also watches placement objects (ClusterResourcePlacement and ResourcePlacement),
796769
// so that it can push apply strategy updates to all bindings right away.
@@ -800,12 +773,6 @@ func (r *Reconciler) SetupWithManager(mgr runtime.Manager) error {
800773
handlePlacement(e.ObjectNew, e.ObjectOld, q)
801774
},
802775
}).
803-
Watches(&fleetv1beta1.ResourcePlacement{}, handler.Funcs{
804-
// Ignore all Create, Delete, and Generic events; these do not concern the rollout controller.
805-
UpdateFunc: func(ctx context.Context, e event.UpdateEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request]) {
806-
handlePlacement(e.ObjectNew, e.ObjectOld, q)
807-
},
808-
}).
809776
Complete(r)
810777
}
811778

pkg/utils/controller/controller.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,6 @@ func CollectResourceIdentifiersFromClusterResourceSnapshot(
410410
listOptions = append(listOptions, client.InNamespace(namespace))
411411
} else {
412412
resourceSnapshotList = &fleetv1beta1.ClusterResourceSnapshotList{}
413-
listOptions = append(listOptions, client.MatchingLabels{
414-
fleetv1beta1.CRPTrackingLabel: name,
415-
})
416413
}
417414
if err := k8Client.List(ctx, resourceSnapshotList, listOptions...); err != nil {
418415
klog.ErrorS(err, "Failed to list the clusterResourceSnapshots associated with the clusterResourcePlacement",

pkg/utils/controller/controller_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,6 @@ func TestFetchAllClusterResourceSnapshots(t *testing.T) {
490490
}
491491
options := []cmp.Option{
492492
cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion"),
493-
cmpopts.SortMaps(func(s1, s2 string) bool {
494-
return s1 < s2
495-
}),
496493
}
497494
theSortedKeys := slices.Sorted(maps.Keys(got))
498495
for i := range theSortedKeys {

pkg/utils/controller/resource_snapshot_resolver.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controller
1818

1919
import (
2020
"context"
21+
"fmt"
2122

2223
"k8s.io/klog/v2"
2324
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -46,9 +47,6 @@ func FetchMasterResourceSnapshot(ctx context.Context, k8Client client.Reader, pl
4647
listOptions = append(listOptions, client.InNamespace(namespace))
4748
} else {
4849
resourceSnapshotList = &fleetv1beta1.ClusterResourceSnapshotList{}
49-
listOptions = append(listOptions, client.MatchingLabels{
50-
fleetv1beta1.CRPTrackingLabel: name,
51-
})
5250
}
5351
if err := k8Client.List(ctx, resourceSnapshotList, listOptions...); err != nil {
5452
klog.ErrorS(err, "Failed to list the resourceSnapshots associated with the placement", "placement", placementKey)
@@ -70,10 +68,10 @@ func FetchMasterResourceSnapshot(ctx context.Context, k8Client client.Reader, pl
7068
break
7169
}
7270
}
71+
// It is possible that no master resourceSnapshot is found, e.g., when the new resourceSnapshot is created but not yet marked as the latest.
7372
if masterResourceSnapshot == nil {
74-
klog.V(2).InfoS("Found resourceSnapshots without master snapshot", "placement", placementKey, "resourceSnapshotCount", len(items))
75-
} else {
76-
klog.V(2).InfoS("Found the latest associated clusterResourceSnapshot", "placement", placementKey, "masterResourceSnapshot", klog.KObj(masterResourceSnapshot))
73+
return nil, fmt.Errorf("no masterResourceSnapshot found for the placement %s", placementKey)
7774
}
75+
klog.V(2).InfoS("Found the latest associated masterResourceSnapshot", "placement", placementKey, "masterResourceSnapshot", klog.KObj(masterResourceSnapshot))
7876
return masterResourceSnapshot, nil
7977
}

0 commit comments

Comments
 (0)