From 374215acbd553125a9a7f072da151949c9ef9c4c Mon Sep 17 00:00:00 2001 From: Meng Yan Date: Fri, 12 Apr 2024 08:21:23 +0800 Subject: [PATCH] Enable placement syncers for global resouces (#876) * enable placement syncers for global resouces Signed-off-by: Meng Yan * fix the ut Signed-off-by: Meng Yan --------- Signed-off-by: Meng Yan --- agent/pkg/status/controller/placement/integration_test.go | 4 ++++ .../status/controller/placement/placement_decision_syncer.go | 4 +++- .../pkg/status/controller/placement/placement_rule_syncer.go | 5 ++--- agent/pkg/status/controller/placement/placement_syncer.go | 3 +-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/agent/pkg/status/controller/placement/integration_test.go b/agent/pkg/status/controller/placement/integration_test.go index 133eecbe5..9e8986d7c 100644 --- a/agent/pkg/status/controller/placement/integration_test.go +++ b/agent/pkg/status/controller/placement/integration_test.go @@ -60,10 +60,14 @@ var _ = Describe("Placement integration test", Ordered, func() { It("should be able to sync placement decision", func() { By("Create placementdecision") + testGlobalPlacementDecisionOriginUID := "test-globalplacement-decision-uid" testPlacementDecision := &clusterv1beta1.PlacementDecision{ ObjectMeta: metav1.ObjectMeta{ Name: "test-placementdecision-1", Namespace: "default", + Annotations: map[string]string{ + constants.OriginOwnerReferenceAnnotation: testGlobalPlacementDecisionOriginUID, + }, }, Status: clusterv1beta1.PlacementDecisionStatus{}, } diff --git a/agent/pkg/status/controller/placement/placement_decision_syncer.go b/agent/pkg/status/controller/placement/placement_decision_syncer.go index fff2b545d..3e769f8f8 100644 --- a/agent/pkg/status/controller/placement/placement_decision_syncer.go +++ b/agent/pkg/status/controller/placement/placement_decision_syncer.go @@ -11,8 +11,10 @@ import ( "github.com/stolostron/multicluster-global-hub/agent/pkg/config" statusconfig "github.com/stolostron/multicluster-global-hub/agent/pkg/status/controller/config" "github.com/stolostron/multicluster-global-hub/agent/pkg/status/controller/generic" + "github.com/stolostron/multicluster-global-hub/pkg/constants" "github.com/stolostron/multicluster-global-hub/pkg/enum" "github.com/stolostron/multicluster-global-hub/pkg/transport" + "github.com/stolostron/multicluster-global-hub/pkg/utils" ) func LaunchPlacementDecisionSyncer(ctx context.Context, mgr ctrl.Manager, agentConfig *config.AgentConfig, @@ -25,7 +27,7 @@ func LaunchPlacementDecisionSyncer(ctx context.Context, mgr ctrl.Manager, agentC // emitter config placementDecisionEmitter := generic.ObjectEmitterWrapper(enum.PlacementDecisionType, func(obj client.Object) bool { - return true // resource + return utils.HasAnnotation(obj, constants.OriginOwnerReferenceAnnotation) // global resource }, func(obj client.Object) { obj.SetManagedFields(nil) }, false) diff --git a/agent/pkg/status/controller/placement/placement_rule_syncer.go b/agent/pkg/status/controller/placement/placement_rule_syncer.go index d1a8606f7..ab6fb306e 100644 --- a/agent/pkg/status/controller/placement/placement_rule_syncer.go +++ b/agent/pkg/status/controller/placement/placement_rule_syncer.go @@ -31,8 +31,7 @@ func LaunchPlacementRuleSyncer(ctx context.Context, mgr ctrl.Manager, agentConfi } globalPlacementRuleEmitter := generic.ObjectEmitterWrapper(enum.PlacementRuleSpecType, func(obj client.Object) bool { - return agentConfig.EnableGlobalResource && - utils.HasAnnotation(obj, constants.OriginOwnerReferenceAnnotation) + return utils.HasAnnotation(obj, constants.OriginOwnerReferenceAnnotation) // global resource }, tweakFunc, false) localPlacementRuleEmitter := generic.ObjectEmitterWrapper(enum.LocalPlacementRuleSpecType, @@ -43,7 +42,7 @@ func LaunchPlacementRuleSyncer(ctx context.Context, mgr ctrl.Manager, agentConfi }, tweakFunc, false) // syncer - name := "status.placement_decision" + name := "status.placement_rule" syncInterval := statusconfig.GetPolicyDuration return generic.LaunchGenericObjectSyncer( diff --git a/agent/pkg/status/controller/placement/placement_syncer.go b/agent/pkg/status/controller/placement/placement_syncer.go index a75bf796b..62335048a 100644 --- a/agent/pkg/status/controller/placement/placement_syncer.go +++ b/agent/pkg/status/controller/placement/placement_syncer.go @@ -27,8 +27,7 @@ func LaunchPlacementSyncer(ctx context.Context, mgr ctrl.Manager, agentConfig *c // emitter config globalPlacementEmitter := generic.ObjectEmitterWrapper(enum.PlacementSpecType, func(obj client.Object) bool { - return agentConfig.EnableGlobalResource && - utils.HasAnnotation(obj, constants.OriginOwnerReferenceAnnotation) + return utils.HasAnnotation(obj, constants.OriginOwnerReferenceAnnotation) // global resource }, func(obj client.Object) { obj.SetManagedFields(nil)