Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Apr 11, 2018
1 parent fbd4c32 commit 5042f9e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 138 deletions.
51 changes: 2 additions & 49 deletions pkg/oc/cli/util/clientcmd/factory_client_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"

"github.com/golang/glog"
"github.com/spf13/cobra"
Expand All @@ -27,13 +25,11 @@ import (
restclient "k8s.io/client-go/rest"
kclientcmd "k8s.io/client-go/tools/clientcmd"
kclientcmdapi "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"
"k8s.io/kubernetes/pkg/kubectl"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/util/transport"

appsapiv1 "github.com/openshift/api/apps/v1"
appsapi "github.com/openshift/origin/pkg/apps/apis/apps"
Expand Down Expand Up @@ -61,67 +57,24 @@ type ClientAccessFactory interface {
func NewClientAccessFactory(optionalClientConfig kclientcmd.ClientConfig) ClientAccessFactory {
flags := pflag.NewFlagSet("", pflag.ContinueOnError)
clientConfig := optionalClientConfig
// TODO find a different home for the --config instead of --kubeconfig hack we have and eliminate the special construction
if optionalClientConfig == nil {
// TODO: there should be two client configs, one for OpenShift, and one for Kubernetes
clientConfig = osclientcmd.DefaultClientConfig(flags)
clientConfig = defaultingClientConfig{clientConfig}
}
factory := &ring0Factory{
clientConfig: clientConfig,
imageResolutionOptions: &imageResolutionOptions{},
}
factory.kubeClientAccessFactory = kcmdutil.NewClientAccessFactoryFromDiscovery(
factory.kubeClientAccessFactory = kcmdutil.NewClientAccessFactoryFromFlags(
flags,
clientConfig,
&discoveryFactory{clientConfig: clientConfig},
)
factory.OpenshiftCLIClientBuilder = &OpenshiftCLIClientBuilder{config: clientConfig}

return factory
}

type discoveryFactory struct {
clientConfig kclientcmd.ClientConfig
cacheDir string
}

func (f *discoveryFactory) BindFlags(flags *pflag.FlagSet) {
defaultCacheDir := filepath.Join(homedir.HomeDir(), ".kube", "http-cache")
flags.StringVar(&f.cacheDir, kcmdutil.FlagHTTPCacheDir, defaultCacheDir, "Default HTTP cache directory")
}

func (f *discoveryFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface, error) {
// Output using whatever version was negotiated in the client cache. The
// version we decode with may not be the same as what the server requires.
cfg, err := f.clientConfig.ClientConfig()
if err != nil {
return nil, err
}
// given 25 groups with one-ish version each, discovery needs to make 50 requests
// double it just so we don't end up here again for a while. This config is only used for discovery.
cfg.Burst = 100

if f.cacheDir != "" {
wt := cfg.WrapTransport
cfg.WrapTransport = func(rt http.RoundTripper) http.RoundTripper {
if wt != nil {
rt = wt(rt)
}
return transport.NewCacheRoundTripper(f.cacheDir, rt)
}
}

// at this point we've negotiated and can get the client
kubeClient, err := kclientset.NewForConfig(cfg)
if err != nil {
return nil, err

}

cacheDir := computeDiscoverCacheDir(filepath.Join(homedir.HomeDir(), ".kube", "cache", "discovery"), cfg.Host)
return kcmdutil.NewCachedDiscoveryClient(newLegacyDiscoveryClient(kubeClient.Discovery().RESTClient()), cacheDir, time.Duration(10*time.Minute)), nil
}

func (f *ring0Factory) OpenShiftClientConfig() kclientcmd.ClientConfig {
return f.clientConfig
}
Expand Down
89 changes: 0 additions & 89 deletions pkg/oc/cli/util/clientcmd/legacy_discovery.go

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5042f9e

Please sign in to comment.