@@ -109,14 +109,34 @@ func (c *clusterClient) ObjectMover() ObjectMover {
109
109
return newObjectMover (c .proxy , log )
110
110
}
111
111
112
+ // NewOptions carries the options supported by New
113
+ type NewOptions struct {
114
+ injectProxy Proxy
115
+ }
116
+
117
+ // Option is a configuration option supplied to New
118
+ type Option func (* NewOptions )
119
+
120
+ // InjectProxy implements a New Option that allows to override the default proxy used by clusterctl.
121
+ func InjectProxy (proxy Proxy ) Option {
122
+ return func (c * NewOptions ) {
123
+ c .injectProxy = proxy
124
+ }
125
+ }
126
+
112
127
// New returns a cluster.Client.
113
- func New (kubeconfig string , options Options ) Client {
114
- return newClusterClient (kubeconfig , options )
128
+ func New (kubeconfig string , options ... Option ) Client {
129
+ return newClusterClient (kubeconfig , options ... )
115
130
}
116
131
117
- func newClusterClient (kubeconfig string , options Options ) * clusterClient {
118
- // if there is an injected proxy, use it, otherwise use the default one
119
- proxy := options .InjectProxy
132
+ func newClusterClient (kubeconfig string , options ... Option ) * clusterClient {
133
+ cfg := & NewOptions {}
134
+ for _ , o := range options {
135
+ o (cfg )
136
+ }
137
+
138
+ // if there is an injected proxy, use it, otherwise use a default one
139
+ proxy := cfg .injectProxy
120
140
if proxy == nil {
121
141
proxy = newProxy (kubeconfig )
122
142
}
@@ -127,11 +147,6 @@ func newClusterClient(kubeconfig string, options Options) *clusterClient {
127
147
}
128
148
}
129
149
130
- // Options allow to set ConfigClient options
131
- type Options struct {
132
- InjectProxy Proxy
133
- }
134
-
135
150
type Proxy interface {
136
151
// CurrentNamespace returns the namespace from the current context in the kubeconfig file
137
152
CurrentNamespace () (string , error )
0 commit comments