Skip to content

Commit a626721

Browse files
committed
stop using factory.OpenshiftClientConfig
1 parent 8cab39d commit a626721

16 files changed

+48
-75
lines changed

pkg/oc/admin/diagnostics/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
// use the base factory to return a raw config (not specific to a context)
1717
func (o DiagnosticsOptions) buildRawConfig() (*clientcmdapi.Config, error) {
18-
kubeConfig, configErr := o.Factory.OpenShiftClientConfig().RawConfig()
18+
kubeConfig, configErr := o.Factory.RawConfig()
1919
if configErr != nil {
2020
return nil, configErr
2121
}

pkg/oc/admin/image/verify-signature.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/spf13/cobra"
1919

2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21-
kclientcmd "k8s.io/client-go/tools/clientcmd"
2221
kapi "k8s.io/kubernetes/pkg/apis/core"
2322
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
2423
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
@@ -84,8 +83,6 @@ type VerifyImageSignatureOptions struct {
8483

8584
ImageClient imageclient.ImageInterface
8685

87-
clientConfig kclientcmd.ClientConfig
88-
8986
Out io.Writer
9087
ErrOut io.Writer
9188
}
@@ -96,9 +93,8 @@ const (
9693

9794
func NewCmdVerifyImageSignature(name, fullName string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command {
9895
opts := &VerifyImageSignatureOptions{
99-
ErrOut: errOut,
100-
Out: out,
101-
clientConfig: f.OpenShiftClientConfig(),
96+
ErrOut: errOut,
97+
Out: out,
10298
// TODO: This improves the error message users get when containers/image is not able
10399
// to locate the pubring.gpg file (which is default).
104100
// This should be improved/fixed in containers/image.
@@ -169,7 +165,8 @@ func (o *VerifyImageSignatureOptions) Complete(f *clientcmd.Factory, cmd *cobra.
169165
return err
170166
} else {
171167
o.CurrentUser = me.Name
172-
if config, err := o.clientConfig.ClientConfig(); err != nil {
168+
169+
if config, err := f.ClientConfig(); err != nil {
173170
return err
174171
} else {
175172
if o.CurrentUserToken = config.BearerToken; len(o.CurrentUserToken) == 0 {

pkg/oc/cli/cmd/login/login.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func NewCmdLogin(fullName string, f *osclientcmd.Factory, reader io.Reader, out,
9797
}
9898

9999
func (o *LoginOptions) Complete(f *osclientcmd.Factory, cmd *cobra.Command, args []string, commandName string) error {
100-
kubeconfig, err := f.OpenShiftClientConfig().RawConfig()
100+
kubeconfig, err := f.RawConfig()
101101
o.StartingKubeConfig = &kubeconfig
102102
if err != nil {
103103
if !os.IsNotExist(err) {

pkg/oc/cli/cmd/login/logout.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ func NewCmdLogout(name, fullName, ocLoginFullCommand string, f *osclientcmd.Fact
8080
}
8181

8282
func (o *LogoutOptions) Complete(f *osclientcmd.Factory, cmd *cobra.Command, args []string) error {
83-
kubeconfig, err := f.OpenShiftClientConfig().RawConfig()
83+
kubeconfig, err := f.RawConfig()
8484
o.StartingKubeConfig = &kubeconfig
8585
if err != nil {
8686
return err
8787
}
8888

89-
o.Config, err = f.OpenShiftClientConfig().ClientConfig()
89+
o.Config, err = f.ClientConfig()
9090
if err != nil {
9191
return err
9292
}

pkg/oc/cli/cmd/project.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (o *ProjectOptions) Complete(f *clientcmd.Factory, args []string, out io.Wr
100100
o.ProjectName = args[0]
101101
}
102102

103-
o.Config, err = f.OpenShiftClientConfig().RawConfig()
103+
o.Config, err = f.RawConfig()
104104
if err != nil {
105105
return err
106106
}
@@ -126,7 +126,7 @@ func (o *ProjectOptions) Complete(f *clientcmd.Factory, args []string, out io.Wr
126126

127127
// since we failed to retrieve ClientConfig for the current server,
128128
// fetch local OpenShift client config
129-
o.ClientConfig, err = f.OpenShiftClientConfig().ClientConfig()
129+
o.ClientConfig, err = f.ClientConfig()
130130
if err != nil {
131131
return err
132132
}

pkg/oc/cli/cmd/projects.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ func (o *ProjectsOptions) Complete(f *clientcmd.Factory, args []string, commandN
9292
o.CommandName = commandName
9393

9494
var err error
95-
o.Config, err = f.OpenShiftClientConfig().RawConfig()
95+
o.Config, err = f.RawConfig()
9696
if err != nil {
9797
return err
9898
}
9999

100-
o.ClientConfig, err = f.OpenShiftClientConfig().ClientConfig()
100+
o.ClientConfig, err = f.ClientConfig()
101101
if err != nil {
102102
return err
103103
}

pkg/oc/cli/cmd/request_project.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (o *NewProjectOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, a
115115
return err
116116
}
117117
} else {
118-
clientConfig, err := f.OpenShiftClientConfig().ClientConfig()
118+
clientConfig, err := f.ClientConfig()
119119
if err != nil {
120120
return err
121121
}

pkg/oc/cli/cmd/startbuild.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"k8s.io/apimachinery/pkg/runtime/schema"
3030
"k8s.io/apimachinery/third_party/forked/golang/netutil"
3131
restclient "k8s.io/client-go/rest"
32-
kclientcmd "k8s.io/client-go/tools/clientcmd"
3332
"k8s.io/kubernetes/pkg/api/legacyscheme"
3433
kapi "k8s.io/kubernetes/pkg/apis/core"
3534
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
@@ -158,7 +157,7 @@ type StartBuildOptions struct {
158157

159158
Mapper meta.RESTMapper
160159
BuildClient buildclient.BuildInterface
161-
ClientConfig kclientcmd.ClientConfig
160+
ClientConfig *restclient.Config
162161

163162
AsBinary bool
164163
ShortOutput bool
@@ -169,11 +168,15 @@ type StartBuildOptions struct {
169168
}
170169

171170
func (o *StartBuildOptions) Complete(f *clientcmd.Factory, in io.Reader, out, errout io.Writer, cmd *cobra.Command, cmdFullName string, args []string) error {
171+
var err error
172172
o.In = in
173173
o.Out = out
174174
o.ErrOut = errout
175175
o.Git = git.NewRepository()
176-
o.ClientConfig = f.OpenShiftClientConfig()
176+
o.ClientConfig, err = f.ClientConfig()
177+
if err != nil {
178+
return err
179+
}
177180
o.Mapper, _ = f.Object()
178181

179182
o.IncrementalOverride = cmd.Flags().Lookup("incremental").Changed
@@ -716,13 +719,10 @@ func (o *StartBuildOptions) RunStartBuildWebHook() error {
716719
// when using HTTPS, try to reuse the local config transport if possible to get a client cert
717720
// TODO: search all configs
718721
if hook.Scheme == "https" {
719-
config, err := o.ClientConfig.ClientConfig()
720-
if err == nil {
721-
if url, _, err := restclient.DefaultServerURL(config.Host, "", schema.GroupVersion{}, true); err == nil {
722-
if netutil.CanonicalAddr(url) == netutil.CanonicalAddr(hook) && url.Scheme == hook.Scheme {
723-
if rt, err := restclient.TransportFor(config); err == nil {
724-
httpClient = &http.Client{Transport: rt}
725-
}
722+
if url, _, err := restclient.DefaultServerURL(o.ClientConfig.Host, "", schema.GroupVersion{}, true); err == nil {
723+
if netutil.CanonicalAddr(url) == netutil.CanonicalAddr(hook) && url.Scheme == hook.Scheme {
724+
if rt, err := restclient.TransportFor(o.ClientConfig); err == nil {
725+
httpClient = &http.Client{Transport: rt}
726726
}
727727
}
728728
}

pkg/oc/cli/cmd/startbuild_test.go

+2-26
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestStartBuildWebHook(t *testing.T) {
6060
buf := &bytes.Buffer{}
6161
o := &StartBuildOptions{
6262
Out: buf,
63-
ClientConfig: cfg,
63+
ClientConfig: cfg.Client,
6464
FromWebhook: server.URL + "/webhook",
6565
Mapper: legacyscheme.Registry.RESTMapper(),
6666
}
@@ -79,30 +79,6 @@ func TestStartBuildWebHook(t *testing.T) {
7979
}
8080
}
8181

82-
func TestStartBuildWebHookHTTPS(t *testing.T) {
83-
invoked := make(chan struct{}, 1)
84-
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
85-
invoked <- struct{}{}
86-
w.WriteHeader(http.StatusOK)
87-
}))
88-
defer server.Close()
89-
90-
testErr := errors.New("not enabled")
91-
cfg := &FakeClientConfig{
92-
Err: testErr,
93-
}
94-
buf := &bytes.Buffer{}
95-
o := &StartBuildOptions{
96-
Out: buf,
97-
ClientConfig: cfg,
98-
FromWebhook: server.URL + "/webhook",
99-
Mapper: legacyscheme.Registry.RESTMapper(),
100-
}
101-
if err := o.Run(); err == nil || !strings.Contains(err.Error(), "certificate signed by unknown authority") {
102-
t.Fatalf("unexpected non-error: %v", err)
103-
}
104-
}
105-
10682
func TestStartBuildHookPostReceive(t *testing.T) {
10783
invoked := make(chan *buildapi.GenericWebHookEvent, 1)
10884
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -129,7 +105,7 @@ func TestStartBuildHookPostReceive(t *testing.T) {
129105
buf := &bytes.Buffer{}
130106
o := &StartBuildOptions{
131107
Out: buf,
132-
ClientConfig: cfg,
108+
ClientConfig: cfg.Client,
133109
FromWebhook: server.URL + "/webhook",
134110
GitPostReceive: f.Name(),
135111
Mapper: legacyscheme.Registry.RESTMapper(),

pkg/oc/cli/cmd/status.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ func (o *StatusOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, baseC
130130
return err
131131
}
132132

133-
config, err := f.OpenShiftClientConfig().ClientConfig()
133+
config, err := f.ClientConfig()
134134
if err != nil {
135135
return err
136136
}
137137

138-
rawConfig, err := f.OpenShiftClientConfig().RawConfig()
138+
rawConfig, err := f.RawConfig()
139139
if err != nil {
140140
return err
141141
}

pkg/oc/cli/cmd/version.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
etcdversion "github.com/coreos/etcd/version"
11+
"k8s.io/client-go/rest"
1112

1213
kapierrors "k8s.io/apimachinery/pkg/api/errors"
1314
kubeversiontypes "k8s.io/apimachinery/pkg/version"
@@ -32,7 +33,7 @@ type VersionOptions struct {
3233
BaseName string
3334
Out io.Writer
3435

35-
ClientConfig kclientcmd.ClientConfig
36+
ClientConfig *rest.Config
3637
Clients func() (kclientset.Interface, error)
3738

3839
Timeout time.Duration
@@ -72,15 +73,19 @@ func (o *VersionOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, out
7273
}
7374

7475
o.Clients = f.ClientSet
75-
o.ClientConfig = f.OpenShiftClientConfig()
76+
var err error
77+
o.ClientConfig, err = f.ClientConfig()
78+
if err != nil {
79+
return err
80+
}
7681

7782
if !o.IsServer {
7883
// retrieve config timeout and set cmd option
7984
// use this instead of getting value from global
8085
// flag, as flag value would have to be parsed
8186
// from a string potentially not formatted as
8287
// a valid time.Duration value
83-
config, err := o.ClientConfig.ClientConfig()
88+
config, err := f.ClientConfig()
8489
if err == nil {
8590
o.Timeout = config.Timeout
8691
}
@@ -129,12 +134,7 @@ func (o VersionOptions) RunVersion() error {
129134

130135
// confirm config exists before making request to server
131136
var err error
132-
clientConfig, err := o.ClientConfig.ClientConfig()
133-
if err != nil {
134-
done <- err
135-
return
136-
}
137-
versionHost = clientConfig.Host
137+
versionHost = o.ClientConfig.Host
138138

139139
kClient, err := o.Clients()
140140
if err != nil {

pkg/oc/cli/cmd/whoami.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (o WhoAmIOptions) WhoAmI() (*userapi.User, error) {
6161

6262
func RunWhoAmI(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []string, o *WhoAmIOptions) error {
6363
if kcmdutil.GetFlagBool(cmd, "show-token") {
64-
cfg, err := f.OpenShiftClientConfig().ClientConfig()
64+
cfg, err := f.ClientConfig()
6565
if err != nil {
6666
return err
6767
}
@@ -72,7 +72,7 @@ func RunWhoAmI(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []s
7272
return nil
7373
}
7474
if kcmdutil.GetFlagBool(cmd, "show-context") {
75-
cfg, err := f.OpenShiftClientConfig().RawConfig()
75+
cfg, err := f.RawConfig()
7676
if err != nil {
7777
return err
7878
}
@@ -83,7 +83,7 @@ func RunWhoAmI(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []s
8383
return nil
8484
}
8585
if kcmdutil.GetFlagBool(cmd, "show-server") {
86-
cfg, err := f.OpenShiftClientConfig().ClientConfig()
86+
cfg, err := f.ClientConfig()
8787
if err != nil {
8888
return err
8989
}

pkg/oc/cli/sa/create_kubeconfig.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (o *CreateKubeconfigOptions) Complete(args []string, f *clientcmd.Factory,
9494
return err
9595
}
9696

97-
o.RawConfig, err = f.OpenShiftClientConfig().RawConfig()
97+
o.RawConfig, err = f.RawConfig()
9898
if err != nil {
9999
return err
100100
}

pkg/oc/cli/util/clientcmd/factory_builder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (f *ring2Factory) Reaper(mapping *meta.RESTMapping) (kubectl.Reaper, error)
6868
if err != nil {
6969
return nil, err
7070
}
71-
config, err := f.clientAccessFactory.OpenShiftClientConfig().ClientConfig()
71+
config, err := f.clientAccessFactory.ClientConfig()
7272
if err != nil {
7373
return nil, err
7474
}
@@ -134,7 +134,7 @@ func (f *ring2Factory) Reaper(mapping *meta.RESTMapping) (kubectl.Reaper, error)
134134
securityClient.Security().SecurityContextConstraints(),
135135
), nil
136136
case buildapi.IsKindOrLegacy("BuildConfig", gk):
137-
config, err := f.clientAccessFactory.OpenShiftClientConfig().ClientConfig()
137+
config, err := f.clientAccessFactory.ClientConfig()
138138
if err != nil {
139139
return nil, err
140140
}

pkg/oc/cli/util/clientcmd/factory_client_access.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"k8s.io/client-go/kubernetes"
2727
restclient "k8s.io/client-go/rest"
2828
kclientcmd "k8s.io/client-go/tools/clientcmd"
29+
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
2930
kclientcmdapi "k8s.io/client-go/tools/clientcmd/api"
3031
"k8s.io/client-go/util/homedir"
3132
kapi "k8s.io/kubernetes/pkg/apis/core"
@@ -54,7 +55,6 @@ type ClientAccessFactory interface {
5455
kcmdutil.ClientAccessFactory
5556
CLIClientBuilder
5657

57-
OpenShiftClientConfig() kclientcmd.ClientConfig
5858
ImageResolutionOptions() FlagBinder
5959
}
6060

@@ -122,8 +122,8 @@ func (f *discoveryFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface
122122
return kcmdutil.NewCachedDiscoveryClient(newLegacyDiscoveryClient(kubeClient.Discovery().RESTClient()), cacheDir, time.Duration(10*time.Minute)), nil
123123
}
124124

125-
func (f *ring0Factory) OpenShiftClientConfig() kclientcmd.ClientConfig {
126-
return f.clientConfig
125+
func (f *ring0Factory) RawConfig() (clientcmdapi.Config, error) {
126+
return f.kubeClientAccessFactory.RawConfig()
127127
}
128128

129129
func (f *ring0Factory) DiscoveryClient() (discovery.CachedDiscoveryInterface, error) {
@@ -310,7 +310,7 @@ func (f *ring0Factory) ResolveImage(image string) (string, error) {
310310
if isDockerImageSource(options.Source) {
311311
return f.kubeClientAccessFactory.ResolveImage(image)
312312
}
313-
config, err := f.OpenShiftClientConfig().ClientConfig()
313+
config, err := f.kubeClientAccessFactory.ClientConfig()
314314
if err != nil {
315315
return "", err
316316
}

pkg/oc/cli/util/clientcmd/factory_object_mapping.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (f *ring1Factory) HistoryViewer(mapping *meta.RESTMapping) (kubectl.History
192192

193193
func (f *ring1Factory) Rollbacker(mapping *meta.RESTMapping) (kubectl.Rollbacker, error) {
194194
if appsapi.IsKindOrLegacy("DeploymentConfig", mapping.GroupVersionKind.GroupKind()) {
195-
config, err := f.clientAccessFactory.OpenShiftClientConfig().ClientConfig()
195+
config, err := f.clientAccessFactory.ClientConfig()
196196
if err != nil {
197197
return nil, err
198198
}
@@ -202,7 +202,7 @@ func (f *ring1Factory) Rollbacker(mapping *meta.RESTMapping) (kubectl.Rollbacker
202202
}
203203

204204
func (f *ring1Factory) StatusViewer(mapping *meta.RESTMapping) (kubectl.StatusViewer, error) {
205-
config, err := f.clientAccessFactory.OpenShiftClientConfig().ClientConfig()
205+
config, err := f.clientAccessFactory.ClientConfig()
206206
if err != nil {
207207
return nil, err
208208
}

0 commit comments

Comments
 (0)