Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 46be4cf

Browse files
committedJul 27, 2016
Avoid to create an API client if not needed
1 parent bf6e9dd commit 46be4cf

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed
 

Diff for: ‎pkg/cmd/util/clientcmd/factory.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,16 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
328328
}
329329
kLogsForObjectFunc := w.Factory.LogsForObject
330330
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-
336331
switch t := object.(type) {
337332
case *deployapi.DeploymentConfig:
338333
dopts, ok := options.(*deployapi.DeploymentLogOptions)
339334
if !ok {
340335
return nil, errors.New("provided options object is not a DeploymentLogOptions")
341336
}
337+
oc, _, err := w.Clients()
338+
if err != nil {
339+
return nil, err
340+
}
342341
return oc.DeploymentLogs(t.Namespace).Get(t.Name, *dopts), nil
343342
case *buildapi.Build:
344343
bopts, ok := options.(*buildapi.BuildLogOptions)
@@ -348,12 +347,20 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
348347
if bopts.Version != nil {
349348
return nil, errors.New("cannot specify a version and a build")
350349
}
350+
oc, _, err := w.Clients()
351+
if err != nil {
352+
return nil, err
353+
}
351354
return oc.BuildLogs(t.Namespace).Get(t.Name, *bopts), nil
352355
case *buildapi.BuildConfig:
353356
bopts, ok := options.(*buildapi.BuildLogOptions)
354357
if !ok {
355358
return nil, errors.New("provided options object is not a BuildLogOptions")
356359
}
360+
oc, _, err := w.Clients()
361+
if err != nil {
362+
return nil, err
363+
}
357364
builds, err := oc.Builds(t.Namespace).List(api.ListOptions{})
358365
if err != nil {
359366
return nil, err

0 commit comments

Comments
 (0)
Please sign in to comment.