@@ -12,6 +12,8 @@ import (
1212 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/clients"
1313 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/options/builder"
1414 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/types"
15+ clientsv2 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/v2/clients"
16+ builderv2 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/v2/options/builder"
1517)
1618
1719type GenericClientOptions [T generic.ResourceObject ] struct {
@@ -23,6 +25,7 @@ type GenericClientOptions[T generic.ResourceObject] struct {
2325 clusterName string
2426 subscription bool
2527 resync bool
28+ v2 bool
2629}
2730
2831// NewGenericClientOptions create a GenericClientOptions
@@ -86,6 +89,11 @@ func (o *GenericClientOptions[T]) WithResyncEnabled(resync bool) *GenericClientO
8689 return o
8790}
8891
92+ func (o * GenericClientOptions [T ]) EnableV2 () * GenericClientOptions [T ] {
93+ o .v2 = true
94+ return o
95+ }
96+
8997func (o * GenericClientOptions [T ]) ClusterName () string {
9098 return o .clusterName
9199}
@@ -111,20 +119,39 @@ func (o *GenericClientOptions[T]) AgentClient(ctx context.Context) (generic.Clou
111119 o .watcherStore = store .NewAgentInformerWatcherStore [T ]()
112120 }
113121
114- options , err := builder .BuildCloudEventsAgentOptions (o .config , o .clusterName , o .clientID )
115- if err != nil {
116- return nil , err
117- }
122+ var cloudEventsClient generic.CloudEventsClient [T ]
123+ if o .v2 {
124+ options , err := builderv2 .BuildCloudEventsAgentOptions (o .config , o .clusterName , o .clientID )
125+ if err != nil {
126+ return nil , err
127+ }
128+
129+ cloudEventsClient , err = clientsv2 .NewCloudEventAgentClient (
130+ ctx ,
131+ options ,
132+ store .NewAgentWatcherStoreLister (o .watcherStore ),
133+ statushash .StatusHash ,
134+ o .codec ,
135+ )
136+ if err != nil {
137+ return nil , err
138+ }
139+ } else {
140+ options , err := builder .BuildCloudEventsAgentOptions (o .config , o .clusterName , o .clientID )
141+ if err != nil {
142+ return nil , err
143+ }
118144
119- cloudEventsClient , err := clients .NewCloudEventAgentClient (
120- ctx ,
121- options ,
122- store .NewAgentWatcherStoreLister (o .watcherStore ),
123- statushash .StatusHash ,
124- o .codec ,
125- )
126- if err != nil {
127- return nil , err
145+ cloudEventsClient , err = clients .NewCloudEventAgentClient (
146+ ctx ,
147+ options ,
148+ store .NewAgentWatcherStoreLister (o .watcherStore ),
149+ statushash .StatusHash ,
150+ o .codec ,
151+ )
152+ if err != nil {
153+ return nil , err
154+ }
128155 }
129156
130157 if o .subscription {
@@ -182,20 +209,39 @@ func (o *GenericClientOptions[T]) SourceClient(ctx context.Context) (generic.Clo
182209 return nil , fmt .Errorf ("a watcher store is required" )
183210 }
184211
185- options , err := builder .BuildCloudEventsSourceOptions (o .config , o .clientID , o .sourceID )
186- if err != nil {
187- return nil , err
188- }
212+ var cloudEventsClient generic.CloudEventsClient [T ]
213+ if o .v2 {
214+ options , err := builderv2 .BuildCloudEventsSourceOptions (o .config , o .clientID , o .sourceID )
215+ if err != nil {
216+ return nil , err
217+ }
189218
190- cloudEventsClient , err := clients .NewCloudEventSourceClient (
191- ctx ,
192- options ,
193- store .NewSourceWatcherStoreLister (o .watcherStore ),
194- statushash .StatusHash ,
195- o .codec ,
196- )
197- if err != nil {
198- return nil , err
219+ cloudEventsClient , err = clientsv2 .NewCloudEventSourceClient (
220+ ctx ,
221+ options ,
222+ store .NewSourceWatcherStoreLister (o .watcherStore ),
223+ statushash .StatusHash ,
224+ o .codec ,
225+ )
226+ if err != nil {
227+ return nil , err
228+ }
229+ } else {
230+ options , err := builder .BuildCloudEventsSourceOptions (o .config , o .clientID , o .sourceID )
231+ if err != nil {
232+ return nil , err
233+ }
234+
235+ cloudEventsClient , err = clients .NewCloudEventSourceClient (
236+ ctx ,
237+ options ,
238+ store .NewSourceWatcherStoreLister (o .watcherStore ),
239+ statushash .StatusHash ,
240+ o .codec ,
241+ )
242+ if err != nil {
243+ return nil , err
244+ }
199245 }
200246
201247 if o .subscription {
0 commit comments