Skip to content

Commit

Permalink
Enable placement syncers for global resouces (stolostron#876)
Browse files Browse the repository at this point in the history
* enable placement syncers for global resouces

Signed-off-by: Meng Yan <[email protected]>

* fix the ut

Signed-off-by: Meng Yan <[email protected]>

---------

Signed-off-by: Meng Yan <[email protected]>
  • Loading branch information
yanmxa authored Apr 12, 2024
1 parent 486c0f6 commit 374215a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions agent/pkg/status/controller/placement/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions agent/pkg/status/controller/placement/placement_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 374215a

Please sign in to comment.