Skip to content

Commit f3f63fb

Browse files
aaronschweigturkenh
authored andcommitted
feat: add NewClusterAwareClientWithWatch convinience wrapper to kcp package
Signed-off-by: aaronschweig <[email protected]>
1 parent 15fe9ff commit f3f63fb

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

pkg/kcp/wrappers.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,27 @@ func NewClusterAwareAPIReader(config *rest.Config, opts client.Options) (client.
127127
// ...
128128
// }
129129
func NewClusterAwareClient(config *rest.Config, opts client.Options) (client.Client, error) {
130+
opts, err := applyClientOptions(config, opts)
131+
if err != nil {
132+
return nil, err
133+
}
134+
135+
return client.New(config, opts)
136+
}
137+
138+
func applyClientOptions(config *rest.Config, opts client.Options) (client.Options, error) {
130139
if opts.HTTPClient == nil {
131140
httpClient, err := NewClusterAwareHTTPClient(config)
132141
if err != nil {
133-
return nil, err
142+
return opts, err
134143
}
135144
opts.HTTPClient = httpClient
136145
}
137146
if opts.Mapper == nil && opts.MapperWithContext == nil {
138147
opts.MapperWithContext = NewClusterAwareMapperProvider(config, opts.HTTPClient)
139148
}
140-
return client.New(config, opts)
149+
150+
return opts, nil
141151
}
142152

143153
// NewClusterAwareHTTPClient returns an http.Client with a cluster aware round tripper.
@@ -151,6 +161,15 @@ func NewClusterAwareHTTPClient(config *rest.Config) (*http.Client, error) {
151161
return httpClient, nil
152162
}
153163

164+
func NewClusterAwareClientWithWatch(config *rest.Config, options client.Options) (client.WithWatch, error) {
165+
opts, err := applyClientOptions(config, options)
166+
if err != nil {
167+
return nil, err
168+
}
169+
170+
return client.NewWithWatch(config, opts)
171+
}
172+
154173
// NewClusterAwareMapperProvider returns a function producing RESTMapper for the
155174
// cluster specified in the context.
156175
func NewClusterAwareMapperProvider(c *rest.Config, httpClient *http.Client) func(ctx context.Context) (meta.RESTMapper, error) {

0 commit comments

Comments
 (0)