@@ -250,31 +250,41 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
250
250
}
251
251
kScalerFunc := w .Factory .Scaler
252
252
w .Scaler = func (mapping * meta.RESTMapping ) (kubectl.Scaler , error ) {
253
- oc , kc , err := w .Clients ()
254
- if err != nil {
255
- return nil , err
256
- }
257
-
258
253
if mapping .GroupVersionKind .GroupKind () == deployapi .Kind ("DeploymentConfig" ) {
254
+ oc , kc , err := w .Clients ()
255
+ if err != nil {
256
+ return nil , err
257
+ }
259
258
return deploycmd .NewDeploymentConfigScaler (oc , kc ), nil
260
259
}
261
260
return kScalerFunc (mapping )
262
261
}
263
262
kReaperFunc := w .Factory .Reaper
264
263
w .Reaper = func (mapping * meta.RESTMapping ) (kubectl.Reaper , error ) {
265
- oc , kc , err := w .Clients ()
266
- if err != nil {
267
- return nil , err
268
- }
269
-
270
264
switch mapping .GroupVersionKind .GroupKind () {
271
265
case deployapi .Kind ("DeploymentConfig" ):
266
+ oc , kc , err := w .Clients ()
267
+ if err != nil {
268
+ return nil , err
269
+ }
272
270
return deploycmd .NewDeploymentConfigReaper (oc , kc ), nil
273
271
case authorizationapi .Kind ("Role" ):
272
+ oc , _ , err := w .Clients ()
273
+ if err != nil {
274
+ return nil , err
275
+ }
274
276
return authorizationreaper .NewRoleReaper (oc , oc ), nil
275
277
case authorizationapi .Kind ("ClusterRole" ):
278
+ oc , _ , err := w .Clients ()
279
+ if err != nil {
280
+ return nil , err
281
+ }
276
282
return authorizationreaper .NewClusterRoleReaper (oc , oc , oc ), nil
277
283
case userapi .Kind ("User" ):
284
+ oc , kc , err := w .Clients ()
285
+ if err != nil {
286
+ return nil , err
287
+ }
278
288
return authenticationreaper .NewUserReaper (
279
289
client .UsersInterface (oc ),
280
290
client .GroupsInterface (oc ),
@@ -283,13 +293,21 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
283
293
kclient .SecurityContextConstraintsInterface (kc ),
284
294
), nil
285
295
case userapi .Kind ("Group" ):
296
+ oc , kc , err := w .Clients ()
297
+ if err != nil {
298
+ return nil , err
299
+ }
286
300
return authenticationreaper .NewGroupReaper (
287
301
client .GroupsInterface (oc ),
288
302
client .ClusterRoleBindingsInterface (oc ),
289
303
client .RoleBindingsNamespacer (oc ),
290
304
kclient .SecurityContextConstraintsInterface (kc ),
291
305
), nil
292
306
case buildapi .Kind ("BuildConfig" ):
307
+ oc , _ , err := w .Clients ()
308
+ if err != nil {
309
+ return nil , err
310
+ }
293
311
return buildreaper .NewBuildConfigReaper (oc ), nil
294
312
}
295
313
return kReaperFunc (mapping )
@@ -328,17 +346,16 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
328
346
}
329
347
kLogsForObjectFunc := w .Factory .LogsForObject
330
348
w .LogsForObject = func (object , options runtime.Object ) (* restclient.Request , error ) {
331
- oc , _ , err := w .Clients ()
332
- if err != nil {
333
- return nil , err
334
- }
335
-
336
349
switch t := object .(type ) {
337
350
case * deployapi.DeploymentConfig :
338
351
dopts , ok := options .(* deployapi.DeploymentLogOptions )
339
352
if ! ok {
340
353
return nil , errors .New ("provided options object is not a DeploymentLogOptions" )
341
354
}
355
+ oc , _ , err := w .Clients ()
356
+ if err != nil {
357
+ return nil , err
358
+ }
342
359
return oc .DeploymentLogs (t .Namespace ).Get (t .Name , * dopts ), nil
343
360
case * buildapi.Build :
344
361
bopts , ok := options .(* buildapi.BuildLogOptions )
@@ -348,12 +365,20 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
348
365
if bopts .Version != nil {
349
366
return nil , errors .New ("cannot specify a version and a build" )
350
367
}
368
+ oc , _ , err := w .Clients ()
369
+ if err != nil {
370
+ return nil , err
371
+ }
351
372
return oc .BuildLogs (t .Namespace ).Get (t .Name , * bopts ), nil
352
373
case * buildapi.BuildConfig :
353
374
bopts , ok := options .(* buildapi.BuildLogOptions )
354
375
if ! ok {
355
376
return nil , errors .New ("provided options object is not a BuildLogOptions" )
356
377
}
378
+ oc , _ , err := w .Clients ()
379
+ if err != nil {
380
+ return nil , err
381
+ }
357
382
builds , err := oc .Builds (t .Namespace ).List (api.ListOptions {})
358
383
if err != nil {
359
384
return nil , err
@@ -444,18 +469,17 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
444
469
w .PrintObjectSpecificMessage = func (obj runtime.Object , out io.Writer ) {}
445
470
kPauseObjectFunc := w .Factory .PauseObject
446
471
w .Factory .PauseObject = func (object runtime.Object ) (bool , error ) {
447
- oc , _ , err := w .Clients ()
448
- if err != nil {
449
- return false , err
450
- }
451
-
452
472
switch t := object .(type ) {
453
473
case * deployapi.DeploymentConfig :
454
474
if t .Spec .Paused {
455
475
return true , nil
456
476
}
457
477
t .Spec .Paused = true
458
- _ , err := oc .DeploymentConfigs (t .Namespace ).Update (t )
478
+ oc , _ , err := w .Clients ()
479
+ if err != nil {
480
+ return false , err
481
+ }
482
+ _ , err = oc .DeploymentConfigs (t .Namespace ).Update (t )
459
483
// TODO: Pause the deployer containers.
460
484
return false , err
461
485
default :
@@ -464,18 +488,17 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
464
488
}
465
489
kResumeObjectFunc := w .Factory .ResumeObject
466
490
w .Factory .ResumeObject = func (object runtime.Object ) (bool , error ) {
467
- oc , _ , err := w .Clients ()
468
- if err != nil {
469
- return false , err
470
- }
471
-
472
491
switch t := object .(type ) {
473
492
case * deployapi.DeploymentConfig :
474
493
if ! t .Spec .Paused {
475
494
return true , nil
476
495
}
477
496
t .Spec .Paused = false
478
- _ , err := oc .DeploymentConfigs (t .Namespace ).Update (t )
497
+ oc , _ , err := w .Clients ()
498
+ if err != nil {
499
+ return false , err
500
+ }
501
+ _ , err = oc .DeploymentConfigs (t .Namespace ).Update (t )
479
502
// TODO: Resume the deployer containers.
480
503
return false , err
481
504
default :
@@ -484,26 +507,24 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
484
507
}
485
508
kHistoryViewerFunc := w .Factory .HistoryViewer
486
509
w .Factory .HistoryViewer = func (mapping * meta.RESTMapping ) (kubectl.HistoryViewer , error ) {
487
- oc , kc , err := w .Clients ()
488
- if err != nil {
489
- return nil , err
490
- }
491
-
492
510
switch mapping .GroupVersionKind .GroupKind () {
493
511
case deployapi .Kind ("DeploymentConfig" ):
512
+ oc , kc , err := w .Clients ()
513
+ if err != nil {
514
+ return nil , err
515
+ }
494
516
return deploycmd .NewDeploymentConfigHistoryViewer (oc , kc ), nil
495
517
}
496
518
return kHistoryViewerFunc (mapping )
497
519
}
498
520
kRollbackerFunc := w .Factory .Rollbacker
499
521
w .Factory .Rollbacker = func (mapping * meta.RESTMapping ) (kubectl.Rollbacker , error ) {
500
- oc , _ , err := w .Clients ()
501
- if err != nil {
502
- return nil , err
503
- }
504
-
505
522
switch mapping .GroupVersionKind .GroupKind () {
506
523
case deployapi .Kind ("DeploymentConfig" ):
524
+ oc , _ , err := w .Clients ()
525
+ if err != nil {
526
+ return nil , err
527
+ }
507
528
return deploycmd .NewDeploymentConfigRollbacker (oc ), nil
508
529
}
509
530
return kRollbackerFunc (mapping )
@@ -700,10 +721,6 @@ func (f *Factory) PodForResource(resource string, timeout time.Duration) (string
700
721
if err != nil {
701
722
return "" , err
702
723
}
703
- oc , kc , err := f .Clients ()
704
- if err != nil {
705
- return "" , err
706
- }
707
724
mapper , _ := f .Object (false )
708
725
resourceType , name , err := util .ResolveResource (api .Resource ("pods" ), resource , mapper )
709
726
if err != nil {
@@ -714,6 +731,10 @@ func (f *Factory) PodForResource(resource string, timeout time.Duration) (string
714
731
case api .Resource ("pods" ):
715
732
return name , nil
716
733
case api .Resource ("replicationcontrollers" ):
734
+ _ , kc , err := f .Clients ()
735
+ if err != nil {
736
+ return "" , err
737
+ }
717
738
rc , err := kc .ReplicationControllers (namespace ).Get (name )
718
739
if err != nil {
719
740
return "" , err
@@ -725,6 +746,10 @@ func (f *Factory) PodForResource(resource string, timeout time.Duration) (string
725
746
}
726
747
return pod .Name , nil
727
748
case deployapi .Resource ("deploymentconfigs" ):
749
+ oc , kc , err := f .Clients ()
750
+ if err != nil {
751
+ return "" , err
752
+ }
728
753
dc , err := oc .DeploymentConfigs (namespace ).Get (name )
729
754
if err != nil {
730
755
return "" , err
@@ -736,6 +761,10 @@ func (f *Factory) PodForResource(resource string, timeout time.Duration) (string
736
761
}
737
762
return pod .Name , nil
738
763
case extensions .Resource ("daemonsets" ):
764
+ _ , kc , err := f .Clients ()
765
+ if err != nil {
766
+ return "" , err
767
+ }
739
768
ds , err := kc .Extensions ().DaemonSets (namespace ).Get (name )
740
769
if err != nil {
741
770
return "" , err
@@ -750,12 +779,20 @@ func (f *Factory) PodForResource(resource string, timeout time.Duration) (string
750
779
}
751
780
return pod .Name , nil
752
781
case extensions .Resource ("jobs" ):
782
+ _ , kc , err := f .Clients ()
783
+ if err != nil {
784
+ return "" , err
785
+ }
753
786
job , err := kc .Extensions ().Jobs (namespace ).Get (name )
754
787
if err != nil {
755
788
return "" , err
756
789
}
757
790
return podNameForJob (job , kc , timeout , sortBy )
758
791
case batch .Resource ("jobs" ):
792
+ _ , kc , err := f .Clients ()
793
+ if err != nil {
794
+ return "" , err
795
+ }
759
796
job , err := kc .Batch ().Jobs (namespace ).Get (name )
760
797
if err != nil {
761
798
return "" , err
0 commit comments