19
vendor/k8s.io/cli-runtime/pkg/genericclioptions/config_flags_fake.go
generated
vendored
19
vendor/k8s.io/cli-runtime/pkg/genericclioptions/config_flags_fake.go
generated
vendored
@@ -27,12 +27,16 @@ import (
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
)
|
||||
|
||||
// TestConfigFlags contains clientConfig struct
|
||||
// and interfaces that implements RESTClientGetter
|
||||
type TestConfigFlags struct {
|
||||
clientConfig clientcmd.ClientConfig
|
||||
discoveryClient discovery.CachedDiscoveryInterface
|
||||
restMapper meta.RESTMapper
|
||||
}
|
||||
|
||||
// ToRawKubeConfigLoader implements RESTClientGetter
|
||||
// Returns a clientconfig if it's set
|
||||
func (f *TestConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig {
|
||||
if f.clientConfig == nil {
|
||||
panic("attempt to obtain a test RawKubeConfigLoader with no clientConfig specified")
|
||||
@@ -40,14 +44,22 @@ func (f *TestConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig {
|
||||
return f.clientConfig
|
||||
}
|
||||
|
||||
// ToRESTConfig implements RESTClientGetter.
|
||||
// Returns a REST client configuration based on a provided path
|
||||
// to a .kubeconfig file, loading rules, and config flag overrides.
|
||||
// Expects the AddFlags method to have been called.
|
||||
func (f *TestConfigFlags) ToRESTConfig() (*rest.Config, error) {
|
||||
return f.ToRawKubeConfigLoader().ClientConfig()
|
||||
}
|
||||
|
||||
// ToDiscoveryClient implements RESTClientGetter.
|
||||
// Returns a CachedDiscoveryInterface
|
||||
func (f *TestConfigFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) {
|
||||
return f.discoveryClient, nil
|
||||
}
|
||||
|
||||
// ToRESTMapper implements RESTClientGetter.
|
||||
// Returns a mapper.
|
||||
func (f *TestConfigFlags) ToRESTMapper() (meta.RESTMapper, error) {
|
||||
if f.restMapper != nil {
|
||||
return f.restMapper, nil
|
||||
@@ -60,21 +72,25 @@ func (f *TestConfigFlags) ToRESTMapper() (meta.RESTMapper, error) {
|
||||
return nil, fmt.Errorf("no restmapper")
|
||||
}
|
||||
|
||||
// WithClientConfig sets the clientConfig flag
|
||||
func (f *TestConfigFlags) WithClientConfig(clientConfig clientcmd.ClientConfig) *TestConfigFlags {
|
||||
f.clientConfig = clientConfig
|
||||
return f
|
||||
}
|
||||
|
||||
// WithRESTMapper sets the restMapper flag
|
||||
func (f *TestConfigFlags) WithRESTMapper(mapper meta.RESTMapper) *TestConfigFlags {
|
||||
f.restMapper = mapper
|
||||
return f
|
||||
}
|
||||
|
||||
// WithDiscoveryClient sets the discoveryClient flag
|
||||
func (f *TestConfigFlags) WithDiscoveryClient(c discovery.CachedDiscoveryInterface) *TestConfigFlags {
|
||||
f.discoveryClient = c
|
||||
return f
|
||||
}
|
||||
|
||||
// WithNamespace sets the clientConfig flag by modifying delagate and namespace
|
||||
func (f *TestConfigFlags) WithNamespace(ns string) *TestConfigFlags {
|
||||
if f.clientConfig == nil {
|
||||
panic("attempt to obtain a test RawKubeConfigLoader with no clientConfig specified")
|
||||
@@ -86,6 +102,7 @@ func (f *TestConfigFlags) WithNamespace(ns string) *TestConfigFlags {
|
||||
return f
|
||||
}
|
||||
|
||||
// NewTestConfigFlags builds a TestConfigFlags struct to test ConfigFlags
|
||||
func NewTestConfigFlags() *TestConfigFlags {
|
||||
return &TestConfigFlags{}
|
||||
}
|
||||
@@ -96,7 +113,7 @@ type namespacedClientConfig struct {
|
||||
}
|
||||
|
||||
func (c *namespacedClientConfig) Namespace() (string, bool, error) {
|
||||
return c.namespace, false, nil
|
||||
return c.namespace, len(c.namespace) > 0, nil
|
||||
}
|
||||
|
||||
func (c *namespacedClientConfig) RawConfig() (clientcmdapi.Config, error) {
|
||||
|
||||
Reference in New Issue
Block a user