@@ -126,7 +126,11 @@ func (o *Options) FromConfigFlags(configFlags *genericclioptions.ConfigFlags) *O
126
126
return nil , nil , fmt .Errorf ("unable to load kube REST config: %w" , err )
127
127
}
128
128
129
- return restConfig , restConfig .WrapTransport (http .DefaultTransport ), nil
129
+ transport , err := rest .TransportFor (restConfig )
130
+ if err != nil {
131
+ return nil , nil , fmt .Errorf ("unable to create transport: %w" , err )
132
+ }
133
+ return restConfig , transport , nil
130
134
}
131
135
return o
132
136
}
@@ -144,9 +148,13 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
144
148
fs .StringVar (& o .RuleConfigFile , "rule-config" , "" , "The path to a file containing proxy rule configuration" )
145
149
}
146
150
147
- func (o * Options ) Complete (ctx context.Context ) error {
151
+ type CompletedConfig struct {
152
+ config * Options
153
+ }
154
+
155
+ func (o * Options ) Complete (ctx context.Context ) (* CompletedConfig , error ) {
148
156
if err := logsv1 .ValidateAndApply (o .Logs , utilfeature .DefaultFeatureGate ); err != nil {
149
- return err
157
+ return nil , err
150
158
}
151
159
152
160
var err error
@@ -171,7 +179,7 @@ func (o *Options) Complete(ctx context.Context) error {
171
179
default :
172
180
backendConfig , err := o .configFromPath ()
173
181
if err != nil {
174
- return fmt .Errorf ("couldn't load kubeconfig from path: %w" , err )
182
+ return nil , fmt .Errorf ("couldn't load kubeconfig from path: %w" , err )
175
183
}
176
184
177
185
o .RestConfigFunc = func () (* rest.Config , http.RoundTripper , error ) {
@@ -195,15 +203,15 @@ func (o *Options) Complete(ctx context.Context) error {
195
203
if o .Matcher == nil {
196
204
ruleFile , err := os .Open (o .RuleConfigFile )
197
205
if err != nil {
198
- return fmt .Errorf ("couldn't open rule config file: %w" , err )
206
+ return nil , fmt .Errorf ("couldn't open rule config file: %w" , err )
199
207
}
200
208
ruleConfigs , err := proxyrule .Parse (ruleFile )
201
209
if err != nil {
202
- return fmt .Errorf ("couldn't parse rule config file: %w" , err )
210
+ return nil , fmt .Errorf ("couldn't parse rule config file: %w" , err )
203
211
}
204
212
o .Matcher , err = rules .NewMapMatcher (ruleConfigs )
205
213
if err != nil {
206
- return fmt .Errorf ("couldn't compile rule configs: %w" , err )
214
+ return nil , fmt .Errorf ("couldn't compile rule configs: %w" , err )
207
215
}
208
216
}
209
217
if o .InputExtractor == nil {
@@ -215,35 +223,35 @@ func (o *Options) Complete(ctx context.Context) error {
215
223
}
216
224
217
225
if err := o .SecureServing .MaybeDefaultWithSelfSignedCerts ("localhost" , []string {"kubernetes.default.svc" , "kubernetes.default" , "kubernetes" }, nil ); err != nil {
218
- return err
226
+ return nil , err
219
227
}
220
228
221
229
var loopbackClientConfig * rest.Config
222
230
if err := o .SecureServing .ApplyTo (& o .ServingInfo , & loopbackClientConfig ); err != nil {
223
- return err
231
+ return nil , err
224
232
}
225
233
if err := o .Authentication .ApplyTo (ctx , & o .AuthenticationInfo , o .ServingInfo ); err != nil {
226
- return err
234
+ return nil , err
227
235
}
228
236
229
237
o .AdditionalAuthEnabled = o .Authentication .AdditionalAuthEnabled ()
230
238
231
239
spicedbURl , err := url .Parse (o .SpiceDBOptions .SpiceDBEndpoint )
232
240
if err != nil {
233
- return fmt .Errorf ("unable to parse SpiceDB endpoint URL: %w" , err )
241
+ return nil , fmt .Errorf ("unable to parse SpiceDB endpoint URL: %w" , err )
234
242
}
235
243
236
244
var conn * grpc.ClientConn
237
245
if spicedbURl .Scheme == "embedded" {
238
246
klog .FromContext (ctx ).WithValues ("spicedb-endpoint" , spicedbURl ).Info ("using embedded SpiceDB" )
239
247
o .SpiceDBOptions .EmbeddedSpiceDB , err = spicedb .NewServer (ctx , spicedbURl .Path )
240
248
if err != nil {
241
- return fmt .Errorf ("unable to stand up embedded SpiceDB: %w" , err )
249
+ return nil , fmt .Errorf ("unable to stand up embedded SpiceDB: %w" , err )
242
250
}
243
251
244
252
conn , err = o .SpiceDBOptions .EmbeddedSpiceDB .GRPCDialContext (ctx , grpc .WithTransportCredentials (insecure .NewCredentials ()))
245
253
if err != nil {
246
- return fmt .Errorf ("unable to open gRPC connection with embedded SpiceDB: %w" , err )
254
+ return nil , fmt .Errorf ("unable to open gRPC connection with embedded SpiceDB: %w" , err )
247
255
}
248
256
} else {
249
257
klog .FromContext (ctx ).WithValues ("spicedb-endpoint" , o .SpiceDBOptions .SpiceDBEndpoint ).
@@ -255,7 +263,7 @@ func (o *Options) Complete(ctx context.Context) error {
255
263
256
264
tokens := strings .Split (o .SpiceDBOptions .SecureSpiceDBTokensBySpace , "," )
257
265
if len (tokens ) == 0 {
258
- return fmt .Errorf ("no SpiceDB token defined" )
266
+ return nil , fmt .Errorf ("no SpiceDB token defined" )
259
267
}
260
268
261
269
token := strings .TrimSpace (tokens [0 ])
@@ -272,12 +280,12 @@ func (o *Options) Complete(ctx context.Context) error {
272
280
if len (o .SpiceDBOptions .SpicedbCAPath ) > 0 {
273
281
certs , err = grpcutil .WithCustomCerts (verification , o .SpiceDBOptions .SpicedbCAPath )
274
282
if err != nil {
275
- return fmt .Errorf ("unable to load custom certificates: %w" , err )
283
+ return nil , fmt .Errorf ("unable to load custom certificates: %w" , err )
276
284
}
277
285
} else {
278
286
certs , err = grpcutil .WithSystemCerts (verification )
279
287
if err != nil {
280
- return fmt .Errorf ("unable to load system certificates: %w" , err )
288
+ return nil , fmt .Errorf ("unable to load system certificates: %w" , err )
281
289
}
282
290
}
283
291
@@ -289,7 +297,7 @@ func (o *Options) Complete(ctx context.Context) error {
289
297
defer cancel ()
290
298
conn , err = grpc .DialContext (timeoutCtx , o .SpiceDBOptions .SpiceDBEndpoint , opts ... )
291
299
if err != nil {
292
- return fmt .Errorf ("unable to open gRPC connection to remote SpiceDB at %s: %w" , o .SpiceDBOptions .SpiceDBEndpoint , err )
300
+ return nil , fmt .Errorf ("unable to open gRPC connection to remote SpiceDB at %s: %w" , o .SpiceDBOptions .SpiceDBEndpoint , err )
293
301
}
294
302
}
295
303
@@ -301,7 +309,7 @@ func (o *Options) Complete(ctx context.Context) error {
301
309
o .WatchClient = v1 .NewWatchServiceClient (conn )
302
310
}
303
311
304
- return nil
312
+ return & CompletedConfig { o }, nil
305
313
}
306
314
307
315
func (o * Options ) configFromPath () (* clientcmdapi.Config , error ) {
0 commit comments