remove unnecessary factory delegation for RESTClientGetter method

This commit is contained in:
David Eads
2018-05-24 09:33:36 -04:00
committed by Maciej Szulik
parent 4da73a5f3d
commit c85e69aeb9
89 changed files with 228 additions and 360 deletions

View File

@@ -18,7 +18,6 @@ go_library(
"//pkg/kubectl/genericclioptions:go_default_library",
"//pkg/kubectl/genericclioptions/resource:go_default_library",
"//pkg/kubectl/validation:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta/testrestmapper:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",

View File

@@ -25,8 +25,6 @@ import (
"path/filepath"
"time"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta/testrestmapper"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -234,12 +232,12 @@ func (d *fakeCachedDiscoveryClient) ServerResources() ([]*metav1.APIResourceList
type TestFactory struct {
cmdutil.Factory
kubeConfigFlags *genericclioptions.TestConfigFlags
Client kubectl.RESTClient
ScaleGetter scaleclient.ScalesGetter
UnstructuredClient kubectl.RESTClient
Namespace string
ClientConfigVal *restclient.Config
CommandVal string
FakeDynamicClient *fakedynamic.FakeDynamicClient
tempConfigFile *os.File
@@ -276,6 +274,7 @@ func NewTestFactory() *TestFactory {
return &TestFactory{
Factory: cmdutil.NewFactory(configFlags),
kubeConfigFlags: configFlags,
FakeDynamicClient: fakedynamic.NewSimpleDynamicClient(legacyscheme.Scheme),
tempConfigFile: tmpFile,
@@ -283,6 +282,11 @@ func NewTestFactory() *TestFactory {
}
}
func (f *TestFactory) WithNamespace(ns string) *TestFactory {
f.kubeConfigFlags.WithNamespace(ns)
return f
}
func (f *TestFactory) Cleanup() {
if f.tempConfigFile == nil {
return
@@ -295,10 +299,6 @@ func (f *TestFactory) ToRESTConfig() (*restclient.Config, error) {
return f.ClientConfigVal, nil
}
func (f *TestFactory) BareClientConfig() (*restclient.Config, error) {
return f.ClientConfigVal, nil
}
func (f *TestFactory) ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) {
return f.Client, nil
}
@@ -314,10 +314,6 @@ func (f *TestFactory) Validator(validate bool) (validation.Schema, error) {
return validation.NullSchema{}, nil
}
func (f *TestFactory) DefaultNamespace() (string, bool, error) {
return f.Namespace, false, nil
}
func (f *TestFactory) OpenAPISchema() (openapi.Resources, error) {
if f.OpenAPISchemaFunc != nil {
return f.OpenAPISchemaFunc()
@@ -325,10 +321,6 @@ func (f *TestFactory) OpenAPISchema() (openapi.Resources, error) {
return openapitesting.EmptyResources{}, nil
}
func (f *TestFactory) Command(*cobra.Command, bool) string {
return f.CommandVal
}
func (f *TestFactory) NewBuilder() *resource.Builder {
mapper, err := f.ToRESTMapper()
@@ -425,10 +417,6 @@ func (f *TestFactory) DiscoveryClient() (discovery.CachedDiscoveryInterface, err
return cachedClient, nil
}
func (f *TestFactory) ClientSetForVersion(requiredVersion *schema.GroupVersion) (internalclientset.Interface, error) {
return f.ClientSet()
}
func testRESTMapper() meta.RESTMapper {
groupResources := testDynamicResources()
mapper := restmapper.NewDiscoveryRESTMapper(groupResources)