@@ -14,14 +14,15 @@ import (
1414 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/options"
1515 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/payload"
1616 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/types"
17+ optionsv2 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/v2/options"
1718)
1819
1920// CloudEventAgentClient is a client for an agent to resync/send/receive its resources with cloud events.
2021//
2122// An agent is a component that handles the deployment of requested resources on the managed cluster and status report
2223// to the source.
2324type CloudEventAgentClient [T ResourceObject ] struct {
24- * baseClient
25+ baseClientInterface
2526 lister Lister [T ]
2627 codec Codec [T ]
2728 statusHashGetter StatusHashGetter [T ]
@@ -56,19 +57,48 @@ func NewCloudEventAgentClient[T ResourceObject](
5657 }
5758
5859 return & CloudEventAgentClient [T ]{
59- baseClient : baseClient ,
60- lister : lister ,
61- codec : codec ,
62- statusHashGetter : statusHashGetter ,
63- agentID : agentOptions .AgentID ,
64- clusterName : agentOptions .ClusterName ,
60+ baseClientInterface : baseClient ,
61+ lister : lister ,
62+ codec : codec ,
63+ statusHashGetter : statusHashGetter ,
64+ agentID : agentOptions .AgentID ,
65+ clusterName : agentOptions .ClusterName ,
66+ }, nil
67+ }
68+
69+ func NewCloudEventAgentClientV2 [T ResourceObject ](
70+ ctx context.Context ,
71+ agentOptions * optionsv2.CloudEventsAgentOptions ,
72+ lister Lister [T ],
73+ statusHashGetter StatusHashGetter [T ],
74+ codec Codec [T ],
75+ ) (* CloudEventAgentClient [T ], error ) {
76+ baseClient := & baseClientV2 {
77+ clientID : agentOptions .AgentID ,
78+ transport : agentOptions .EventTransport ,
79+ // TODO move the ratelimiter to a package
80+ cloudEventsRateLimiter : NewRateLimiter (options.EventRateLimit {}),
81+ reconnectedChan : make (chan struct {}),
82+ }
83+
84+ if err := baseClient .connect (ctx ); err != nil {
85+ return nil , err
86+ }
87+
88+ return & CloudEventAgentClient [T ]{
89+ baseClientInterface : baseClient ,
90+ lister : lister ,
91+ codec : codec ,
92+ statusHashGetter : statusHashGetter ,
93+ agentID : agentOptions .AgentID ,
94+ clusterName : agentOptions .ClusterName ,
6595 }, nil
6696}
6797
6898// ReconnectedChan returns a chan which indicates the source/agent client is reconnected.
6999// The source/agent client callers should consider sending a resync request when receiving this signal.
70100func (c * CloudEventAgentClient [T ]) ReconnectedChan () <- chan struct {} {
71- return c .reconnectedChan
101+ return c .getReconnectedChan ()
72102}
73103
74104// Resync the resources spec by sending a spec resync request from the current to the given source.
0 commit comments