Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/oc/admin/diagnostics/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// use the base factory to return a raw config (not specific to a context)
func (o DiagnosticsOptions) buildRawConfig() (*clientcmdapi.Config, error) {
kubeConfig, configErr := o.Factory.OpenShiftClientConfig().RawConfig()
kubeConfig, configErr := o.Factory.RawConfig()
if configErr != nil {
return nil, configErr
}
Expand Down
11 changes: 4 additions & 7 deletions pkg/oc/admin/image/verify-signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/spf13/cobra"

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

ImageClient imageclient.ImageInterface

clientConfig kclientcmd.ClientConfig

Out io.Writer
ErrOut io.Writer
}
Expand All @@ -96,9 +93,8 @@ const (

func NewCmdVerifyImageSignature(name, fullName string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command {
opts := &VerifyImageSignatureOptions{
ErrOut: errOut,
Out: out,
clientConfig: f.OpenShiftClientConfig(),
ErrOut: errOut,
Out: out,
// TODO: This improves the error message users get when containers/image is not able
// to locate the pubring.gpg file (which is default).
// This should be improved/fixed in containers/image.
Expand Down Expand Up @@ -169,7 +165,8 @@ func (o *VerifyImageSignatureOptions) Complete(f *clientcmd.Factory, cmd *cobra.
return err
} else {
o.CurrentUser = me.Name
if config, err := o.clientConfig.ClientConfig(); err != nil {

if config, err := f.ClientConfig(); err != nil {
return err
} else {
if o.CurrentUserToken = config.BearerToken; len(o.CurrentUserToken) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func NewCmdLogin(fullName string, f *osclientcmd.Factory, reader io.Reader, out,
}

func (o *LoginOptions) Complete(f *osclientcmd.Factory, cmd *cobra.Command, args []string, commandName string) error {
kubeconfig, err := f.OpenShiftClientConfig().RawConfig()
kubeconfig, err := f.RawConfig()
o.StartingKubeConfig = &kubeconfig
if err != nil {
if !os.IsNotExist(err) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/oc/cli/cmd/login/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func NewCmdLogout(name, fullName, ocLoginFullCommand string, f *osclientcmd.Fact
}

func (o *LogoutOptions) Complete(f *osclientcmd.Factory, cmd *cobra.Command, args []string) error {
kubeconfig, err := f.OpenShiftClientConfig().RawConfig()
kubeconfig, err := f.RawConfig()
o.StartingKubeConfig = &kubeconfig
if err != nil {
return err
}

o.Config, err = f.OpenShiftClientConfig().ClientConfig()
o.Config, err = f.ClientConfig()
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/oc/cli/cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (o *ProjectOptions) Complete(f *clientcmd.Factory, args []string, out io.Wr
o.ProjectName = args[0]
}

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

// since we failed to retrieve ClientConfig for the current server,
// fetch local OpenShift client config
o.ClientConfig, err = f.OpenShiftClientConfig().ClientConfig()
o.ClientConfig, err = f.ClientConfig()
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/oc/cli/cmd/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ func (o *ProjectsOptions) Complete(f *clientcmd.Factory, args []string, commandN
o.CommandName = commandName

var err error
o.Config, err = f.OpenShiftClientConfig().RawConfig()
o.Config, err = f.RawConfig()
if err != nil {
return err
}

o.ClientConfig, err = f.OpenShiftClientConfig().ClientConfig()
o.ClientConfig, err = f.ClientConfig()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/request_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (o *NewProjectOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, a
return err
}
} else {
clientConfig, err := f.OpenShiftClientConfig().ClientConfig()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/oc/cli/cmd/startbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/third_party/forked/golang/netutil"
restclient "k8s.io/client-go/rest"
kclientcmd "k8s.io/client-go/tools/clientcmd"
"k8s.io/kubernetes/pkg/api/legacyscheme"
kapi "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
Expand Down Expand Up @@ -158,7 +157,7 @@ type StartBuildOptions struct {

Mapper meta.RESTMapper
BuildClient buildclient.BuildInterface
ClientConfig kclientcmd.ClientConfig
ClientConfig *restclient.Config

AsBinary bool
ShortOutput bool
Expand All @@ -169,11 +168,15 @@ type StartBuildOptions struct {
}

func (o *StartBuildOptions) Complete(f *clientcmd.Factory, in io.Reader, out, errout io.Writer, cmd *cobra.Command, cmdFullName string, args []string) error {
var err error
o.In = in
o.Out = out
o.ErrOut = errout
o.Git = git.NewRepository()
o.ClientConfig = f.OpenShiftClientConfig()
o.ClientConfig, err = f.ClientConfig()
if err != nil {
return err
}
o.Mapper, _ = f.Object()

o.IncrementalOverride = cmd.Flags().Lookup("incremental").Changed
Expand Down Expand Up @@ -716,13 +719,10 @@ func (o *StartBuildOptions) RunStartBuildWebHook() error {
// when using HTTPS, try to reuse the local config transport if possible to get a client cert
// TODO: search all configs
if hook.Scheme == "https" {
config, err := o.ClientConfig.ClientConfig()
if err == nil {
if url, _, err := restclient.DefaultServerURL(config.Host, "", schema.GroupVersion{}, true); err == nil {
if netutil.CanonicalAddr(url) == netutil.CanonicalAddr(hook) && url.Scheme == hook.Scheme {
if rt, err := restclient.TransportFor(config); err == nil {
httpClient = &http.Client{Transport: rt}
}
if url, _, err := restclient.DefaultServerURL(o.ClientConfig.Host, "", schema.GroupVersion{}, true); err == nil {
if netutil.CanonicalAddr(url) == netutil.CanonicalAddr(hook) && url.Scheme == hook.Scheme {
if rt, err := restclient.TransportFor(o.ClientConfig); err == nil {
httpClient = &http.Client{Transport: rt}
}
}
}
Expand Down
28 changes: 2 additions & 26 deletions pkg/oc/cli/cmd/startbuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestStartBuildWebHook(t *testing.T) {
buf := &bytes.Buffer{}
o := &StartBuildOptions{
Out: buf,
ClientConfig: cfg,
ClientConfig: cfg.Client,
FromWebhook: server.URL + "/webhook",
Mapper: legacyscheme.Registry.RESTMapper(),
}
Expand All @@ -79,30 +79,6 @@ func TestStartBuildWebHook(t *testing.T) {
}
}

func TestStartBuildWebHookHTTPS(t *testing.T) {
invoked := make(chan struct{}, 1)
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
invoked <- struct{}{}
w.WriteHeader(http.StatusOK)
}))
defer server.Close()

testErr := errors.New("not enabled")
cfg := &FakeClientConfig{
Err: testErr,
}
buf := &bytes.Buffer{}
o := &StartBuildOptions{
Out: buf,
ClientConfig: cfg,
FromWebhook: server.URL + "/webhook",
Mapper: legacyscheme.Registry.RESTMapper(),
}
if err := o.Run(); err == nil || !strings.Contains(err.Error(), "certificate signed by unknown authority") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test never actually tested what it claimed to test. It mocked an error from the wrong point to indicate a failure during actual communication. That hook point no longer exists since this was actually a failure during client construction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bparees fyi, your team will need to update it to do what it should be doing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this test ever had any real value (even if it had been implemented correctly). I'm fine w/ losing it.

t.Fatalf("unexpected non-error: %v", err)
}
}

func TestStartBuildHookPostReceive(t *testing.T) {
invoked := make(chan *buildapi.GenericWebHookEvent, 1)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -129,7 +105,7 @@ func TestStartBuildHookPostReceive(t *testing.T) {
buf := &bytes.Buffer{}
o := &StartBuildOptions{
Out: buf,
ClientConfig: cfg,
ClientConfig: cfg.Client,
FromWebhook: server.URL + "/webhook",
GitPostReceive: f.Name(),
Mapper: legacyscheme.Registry.RESTMapper(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/oc/cli/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ func (o *StatusOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, baseC
return err
}

config, err := f.OpenShiftClientConfig().ClientConfig()
config, err := f.ClientConfig()
if err != nil {
return err
}

rawConfig, err := f.OpenShiftClientConfig().RawConfig()
rawConfig, err := f.RawConfig()
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/oc/cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

etcdversion "github.com/coreos/etcd/version"
"k8s.io/client-go/rest"

kapierrors "k8s.io/apimachinery/pkg/api/errors"
kubeversiontypes "k8s.io/apimachinery/pkg/version"
Expand All @@ -32,7 +33,7 @@ type VersionOptions struct {
BaseName string
Out io.Writer

ClientConfig kclientcmd.ClientConfig
ClientConfig *rest.Config
Clients func() (kclientset.Interface, error)

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

o.Clients = f.ClientSet
o.ClientConfig = f.OpenShiftClientConfig()
var err error
o.ClientConfig, err = f.ClientConfig()
if err != nil && !kclientcmd.IsEmptyConfig(err) {
return err
}

if !o.IsServer {
// retrieve config timeout and set cmd option
// use this instead of getting value from global
// flag, as flag value would have to be parsed
// from a string potentially not formatted as
// a valid time.Duration value
config, err := o.ClientConfig.ClientConfig()
config, err := f.ClientConfig()
if err == nil {
o.Timeout = config.Timeout
}
Expand Down Expand Up @@ -129,12 +134,7 @@ func (o VersionOptions) RunVersion() error {

// confirm config exists before making request to server
var err error
clientConfig, err := o.ClientConfig.ClientConfig()
if err != nil {
done <- err
return
}
versionHost = clientConfig.Host
versionHost = o.ClientConfig.Host

kClient, err := o.Clients()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/oc/cli/cmd/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (o WhoAmIOptions) WhoAmI() (*userapi.User, error) {

func RunWhoAmI(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []string, o *WhoAmIOptions) error {
if kcmdutil.GetFlagBool(cmd, "show-token") {
cfg, err := f.OpenShiftClientConfig().ClientConfig()
cfg, err := f.ClientConfig()
if err != nil {
return err
}
Expand All @@ -72,7 +72,7 @@ func RunWhoAmI(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []s
return nil
}
if kcmdutil.GetFlagBool(cmd, "show-context") {
cfg, err := f.OpenShiftClientConfig().RawConfig()
cfg, err := f.RawConfig()
if err != nil {
return err
}
Expand All @@ -83,7 +83,7 @@ func RunWhoAmI(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []s
return nil
}
if kcmdutil.GetFlagBool(cmd, "show-server") {
cfg, err := f.OpenShiftClientConfig().ClientConfig()
cfg, err := f.ClientConfig()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/sa/create_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (o *CreateKubeconfigOptions) Complete(args []string, f *clientcmd.Factory,
return err
}

o.RawConfig, err = f.OpenShiftClientConfig().RawConfig()
o.RawConfig, err = f.RawConfig()
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/oc/cli/util/clientcmd/factory_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (f *ring2Factory) Reaper(mapping *meta.RESTMapping) (kubectl.Reaper, error)
if err != nil {
return nil, err
}
config, err := f.clientAccessFactory.OpenShiftClientConfig().ClientConfig()
config, err := f.clientAccessFactory.ClientConfig()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func (f *ring2Factory) Reaper(mapping *meta.RESTMapping) (kubectl.Reaper, error)
securityClient.Security().SecurityContextConstraints(),
), nil
case buildapi.IsKindOrLegacy("BuildConfig", gk):
config, err := f.clientAccessFactory.OpenShiftClientConfig().ClientConfig()
config, err := f.clientAccessFactory.ClientConfig()
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/oc/cli/util/clientcmd/factory_client_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
kclientcmd "k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/util/homedir"
kapi "k8s.io/kubernetes/pkg/apis/core"
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
Expand Down Expand Up @@ -47,7 +48,6 @@ type ClientAccessFactory interface {
kcmdutil.ClientAccessFactory
CLIClientBuilder

OpenShiftClientConfig() kclientcmd.ClientConfig
ImageResolutionOptions() FlagBinder
}

Expand Down Expand Up @@ -117,8 +117,8 @@ func (f *discoveryFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface
return kcmdutil.NewCachedDiscoveryClient(newLegacyDiscoveryClient(kubeClient.Discovery().RESTClient()), cacheDir, time.Duration(10*time.Minute)), nil
}

func (f *ring0Factory) OpenShiftClientConfig() kclientcmd.ClientConfig {
return f.clientConfig
func (f *ring0Factory) RawConfig() (clientcmdapi.Config, error) {
return f.kubeClientAccessFactory.RawConfig()
}

func (f *ring0Factory) DiscoveryClient() (discovery.CachedDiscoveryInterface, error) {
Expand Down Expand Up @@ -305,7 +305,7 @@ func (f *ring0Factory) ResolveImage(image string) (string, error) {
if isDockerImageSource(options.Source) {
return f.kubeClientAccessFactory.ResolveImage(image)
}
config, err := f.OpenShiftClientConfig().ClientConfig()
config, err := f.kubeClientAccessFactory.ClientConfig()
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/oc/cli/util/clientcmd/factory_object_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (f *ring1Factory) HistoryViewer(mapping *meta.RESTMapping) (kubectl.History

func (f *ring1Factory) Rollbacker(mapping *meta.RESTMapping) (kubectl.Rollbacker, error) {
if appsapi.IsKindOrLegacy("DeploymentConfig", mapping.GroupVersionKind.GroupKind()) {
config, err := f.clientAccessFactory.OpenShiftClientConfig().ClientConfig()
config, err := f.clientAccessFactory.ClientConfig()
if err != nil {
return nil, err
}
Expand All @@ -202,7 +202,7 @@ func (f *ring1Factory) Rollbacker(mapping *meta.RESTMapping) (kubectl.Rollbacker
}

func (f *ring1Factory) StatusViewer(mapping *meta.RESTMapping) (kubectl.StatusViewer, error) {
config, err := f.clientAccessFactory.OpenShiftClientConfig().ClientConfig()
config, err := f.clientAccessFactory.ClientConfig()
if err != nil {
return nil, err
}
Expand Down
Loading