clientcmd

package
v10.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2018 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package clientcmd provides one stop shopping for building a working client from a fixed config, from a .kubeconfig file, from command line flags, or from any merged combination.

Sample usage from merged .kubeconfig files (local directory, home directory)

loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
// if you want to change the loading rules (which files in which order), you can do so here

configOverrides := &clientcmd.ConfigOverrides{}
// if you want to change override values or bind them to flags, there are methods to help you

kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
config, err := kubeConfig.ClientConfig()
if err != nil {
	// Do something
}
client, err := metav1.New(config)
// ...
Example (MergingEverythingNoConflicts)
commandLineFile, _ := ioutil.TempFile("", "")
defer os.Remove(commandLineFile.Name())
envVarFile, _ := ioutil.TempFile("", "")
defer os.Remove(envVarFile.Name())
currentDirFile, _ := ioutil.TempFile("", "")
defer os.Remove(currentDirFile.Name())
homeDirFile, _ := ioutil.TempFile("", "")
defer os.Remove(homeDirFile.Name())

WriteToFile(testConfigAlfa, commandLineFile.Name())
WriteToFile(testConfigBravo, envVarFile.Name())
WriteToFile(testConfigCharlie, currentDirFile.Name())
WriteToFile(testConfigDelta, homeDirFile.Name())

loadingRules := ClientConfigLoadingRules{
	Precedence: []string{commandLineFile.Name(), envVarFile.Name(), currentDirFile.Name(), homeDirFile.Name()},
}

mergedConfig, err := loadingRules.Load()

json, err := runtime.Encode(clientcmdlatest.Codec, mergedConfig)
if err != nil {
	fmt.Printf("Unexpected error: %v", err)
}
output, err := yaml.JSONToYAML(json)
if err != nil {
	fmt.Printf("Unexpected error: %v", err)
}

fmt.Printf("%v", string(output))
Output:

	apiVersion: v1
clusters:
- cluster:
    server: http://chicken.org:8080
  name: chicken-cluster
- cluster:
    server: http://cow.org:8080
  name: cow-cluster
- cluster:
    server: http://horse.org:8080
  name: horse-cluster
- cluster:
    server: http://pig.org:8080
  name: pig-cluster
contexts:
- context:
    cluster: cow-cluster
    namespace: hammer-ns
    user: red-user
  name: federal-context
- context:
    cluster: chicken-cluster
    namespace: plane-ns
    user: blue-user
  name: gothic-context
- context:
    cluster: pig-cluster
    namespace: saw-ns
    user: black-user
  name: queen-anne-context
- context:
    cluster: horse-cluster
    namespace: chisel-ns
    user: green-user
  name: shaker-context
current-context: ""
kind: Config
preferences: {}
users:
- name: black-user
  user:
    token: black-token
- name: blue-user
  user:
    token: blue-token
- name: green-user
  user:
    token: green-token
- name: red-user
  user:
    token: red-token
Example (MergingSomeWithConflict)
commandLineFile, _ := ioutil.TempFile("", "")
defer os.Remove(commandLineFile.Name())
envVarFile, _ := ioutil.TempFile("", "")
defer os.Remove(envVarFile.Name())

WriteToFile(testConfigAlfa, commandLineFile.Name())
WriteToFile(testConfigConflictAlfa, envVarFile.Name())

loadingRules := ClientConfigLoadingRules{
	Precedence: []string{commandLineFile.Name(), envVarFile.Name()},
}

mergedConfig, err := loadingRules.Load()

json, err := runtime.Encode(clientcmdlatest.Codec, mergedConfig)
if err != nil {
	fmt.Printf("Unexpected error: %v", err)
}
output, err := yaml.JSONToYAML(json)
if err != nil {
	fmt.Printf("Unexpected error: %v", err)
}

fmt.Printf("%v", string(output))
Output:

apiVersion: v1
clusters:
- cluster:
    server: http://cow.org:8080
  name: cow-cluster
- cluster:
    insecure-skip-tls-verify: true
    server: http://donkey.org:8080
  name: donkey-cluster
contexts:
- context:
    cluster: cow-cluster
    namespace: hammer-ns
    user: red-user
  name: federal-context
current-context: federal-context
kind: Config
preferences: {}
users:
- name: red-user
  user:
    token: red-token
- name: yellow-user
  user:
    token: yellow-token
Example (NoMergingOnExplicitPaths)
commandLineFile, _ := ioutil.TempFile("", "")
defer os.Remove(commandLineFile.Name())
envVarFile, _ := ioutil.TempFile("", "")
defer os.Remove(envVarFile.Name())

WriteToFile(testConfigAlfa, commandLineFile.Name())
WriteToFile(testConfigConflictAlfa, envVarFile.Name())

loadingRules := ClientConfigLoadingRules{
	ExplicitPath: commandLineFile.Name(),
	Precedence:   []string{envVarFile.Name()},
}

mergedConfig, err := loadingRules.Load()

json, err := runtime.Encode(clientcmdlatest.Codec, mergedConfig)
if err != nil {
	fmt.Printf("Unexpected error: %v", err)
}
output, err := yaml.JSONToYAML(json)
if err != nil {
	fmt.Printf("Unexpected error: %v", err)
}

fmt.Printf("%v", string(output))
Output:

apiVersion: v1
clusters:
- cluster:
    server: http://cow.org:8080
  name: cow-cluster
contexts:
- context:
    cluster: cow-cluster
    namespace: hammer-ns
    user: red-user
  name: federal-context
current-context: ""
kind: Config
preferences: {}
users:
- name: red-user
  user:
    token: red-token

Index

Examples

Constants

View Source
const (
	RecommendedConfigPathFlag   = "kubeconfig"
	RecommendedConfigPathEnvVar = "KUBECONFIG"
	RecommendedHomeDir          = ".kube"
	RecommendedFileName         = "config"
	RecommendedSchemaName       = "schema"
)
View Source
const (
	FlagClusterName      = "cluster"
	FlagAuthInfoName     = "user"
	FlagContext          = "context"
	FlagNamespace        = "namespace"
	FlagAPIServer        = "server"
	FlagInsecure         = "insecure-skip-tls-verify"
	FlagCertFile         = "client-certificate"
	FlagKeyFile          = "client-key"
	FlagCAFile           = "certificate-authority"
	FlagEmbedCerts       = "embed-certs"
	FlagBearerToken      = "token"
	FlagImpersonate      = "as"
	FlagImpersonateGroup = "as-group"
	FlagUsername         = "username"
	FlagPassword         = "password"
	FlagTimeout          = "request-timeout"
)

Variables

View Source
var (
	// ClusterDefaults has the same behavior as the old EnvVar and DefaultCluster fields
	// DEPRECATED will be replaced
	ClusterDefaults = clientcmdapi.Cluster{Server: getDefaultServer()}
	// DefaultClientConfig represents the legacy behavior of this package for defaulting
	// DEPRECATED will be replace
	DefaultClientConfig = DirectClientConfig{*clientcmdapi.NewConfig(), "", &ConfigOverrides{
		ClusterDefaults: ClusterDefaults,
	}, nil, NewDefaultClientConfigLoadingRules(), promptedCredentials{}}
)
View Source
var (
	RecommendedConfigDir  = path.Join(homedir.HomeDir(), RecommendedHomeDir)
	RecommendedHomeFile   = path.Join(RecommendedConfigDir, RecommendedFileName)
	RecommendedSchemaFile = path.Join(RecommendedConfigDir, RecommendedSchemaName)
)
View Source
var (
	ErrNoContext   = errors.New("no context chosen")
	ErrEmptyConfig = errors.New("no configuration has been provided")
	// message is for consistency with old behavior
	ErrEmptyCluster = errors.New("cluster has no server defined")
)

Functions

func BindAuthInfoFlags

func BindAuthInfoFlags(authInfo *clientcmdapi.AuthInfo, flags *pflag.FlagSet, flagNames AuthOverrideFlags)

BindAuthInfoFlags is a convenience method to bind the specified flags to their associated variables

func BindClusterFlags

func BindClusterFlags(clusterInfo *clientcmdapi.Cluster, flags *pflag.FlagSet, flagNames ClusterOverrideFlags)

BindClusterFlags is a convenience method to bind the specified flags to their associated variables

func BindContextFlags

func BindContextFlags(contextInfo *clientcmdapi.Context, flags *pflag.FlagSet, flagNames ContextOverrideFlags)

BindFlags is a convenience method to bind the specified flags to their associated variables

func BindOverrideFlags

func BindOverrideFlags(overrides *ConfigOverrides, flags *pflag.FlagSet, flagNames ConfigOverrideFlags)

BindOverrideFlags is a convenience method to bind the specified flags to their associated variables

func BuildConfigFromFlags

func BuildConfigFromFlags(masterUrl, kubeconfigPath string) (*restclient.Config, error)

BuildConfigFromFlags is a helper function that builds configs from a master url or a kubeconfig filepath. These are passed in as command line flags for cluster components. Warnings should reflect this usage. If neither masterUrl or kubeconfigPath are passed in we fallback to inClusterConfig. If inClusterConfig fails, we fallback to the default config.

func BuildConfigFromKubeconfigGetter

func BuildConfigFromKubeconfigGetter(masterUrl string, kubeconfigGetter KubeconfigGetter) (*restclient.Config, error)

BuildConfigFromKubeconfigGetter is a helper function that builds configs from a master url and a kubeconfigGetter.

func ConfirmUsable

func ConfirmUsable(config clientcmdapi.Config, passedContextName string) error

ConfirmUsable looks a particular context and determines if that particular part of the config is useable. There might still be errors in the config, but no errors in the sections requested or referenced. It does not return early so that it can find as many errors as possible.

func GetAuthInfoFileReferences

func GetAuthInfoFileReferences(authInfo *clientcmdapi.AuthInfo) []*string

func GetClusterFileReferences

func GetClusterFileReferences(cluster *clientcmdapi.Cluster) []*string

func GetConfigFileReferences

func GetConfigFileReferences(config *clientcmdapi.Config) []*string

func GetConfigFromFileOrDie

func GetConfigFromFileOrDie(filename string) *clientcmdapi.Config

GetConfigFromFileOrDie tries to read a kubeconfig file and if it can't, it calls exit. One exception, missing files result in empty configs, not an exit

func IsConfigurationInvalid

func IsConfigurationInvalid(err error) bool

IsConfigurationInvalid returns true if the provided error indicates the configuration is invalid.

func IsContextNotFound

func IsContextNotFound(err error) bool

IsContextNotFound returns a boolean indicating whether the error is known to report that a context was not found

func IsEmptyConfig

func IsEmptyConfig(err error) bool

IsEmptyConfig returns true if the provided error indicates the provided configuration is empty.

func Load

func Load(data []byte) (*clientcmdapi.Config, error)

Load takes a byte slice and deserializes the contents into Config object. Encapsulates deserialization without assuming the source is a file.

func LoadFromFile

func LoadFromFile(filename string) (*clientcmdapi.Config, error)

LoadFromFile takes a filename and deserializes the contents into Config object

func MakeRelative

func MakeRelative(path, base string) (string, error)

func ModifyConfig

func ModifyConfig(configAccess ConfigAccess, newConfig clientcmdapi.Config, relativizePaths bool) error

ModifyConfig takes a Config object, iterates through Clusters, AuthInfos, and Contexts, uses the LocationOfOrigin if specified or uses the default destination file to write the results into. This results in multiple file reads, but it's very easy to follow. Preferences and CurrentContext should always be set in the default destination file. Since we can't distinguish between empty and missing values (no nil strings), we're forced have separate handling for them. In the kubeconfig cases, newConfig should have at most one difference, that means that this code will only write into a single file. If you want to relativizePaths, you must provide a fully qualified path in any modified element.

func ParseTimeout

func ParseTimeout(duration string) (time.Duration, error)

ParseTimeout returns a parsed duration from a string A duration string value must be a positive integer, optionally followed by a corresponding time unit (s|m|h).

func PersisterForUser

func PersisterForUser(configAccess ConfigAccess, user string) restclient.AuthProviderConfigPersister

func RESTConfigFromKubeConfig

func RESTConfigFromKubeConfig(configBytes []byte) (*restclient.Config, error)

RESTConfigFromKubeConfig is a convenience method to give back a restconfig from your kubeconfig bytes. For programmatic access, this is what you want 80% of the time

func RelativizeAuthInfoLocalPaths

func RelativizeAuthInfoLocalPaths(authInfo *clientcmdapi.AuthInfo) error

RelativizeAuthInfoLocalPaths first absolutizes the paths by calling ResolveLocalPaths. This assumes that any NEW path is already absolute, but any existing path will be resolved relative to LocationOfOrigin

func RelativizeClusterLocalPaths

func RelativizeClusterLocalPaths(cluster *clientcmdapi.Cluster) error

RelativizeClusterLocalPaths first absolutizes the paths by calling ResolveLocalPaths. This assumes that any NEW path is already absolute, but any existing path will be resolved relative to LocationOfOrigin

func RelativizeConfigPaths

func RelativizeConfigPaths(config *clientcmdapi.Config, base string) error

func RelativizePathWithNoBacksteps

func RelativizePathWithNoBacksteps(refs []*string, base string) error

RelativizePathWithNoBacksteps updates the given refs to be relative paths, relative to the given base directory as long as they do not require backsteps. Any path requiring a backstep is left as-is as long it is absolute. Any non-absolute path that can't be relativized produces an error

func RemoveNamespacesPrefix

func RemoveNamespacesPrefix(value string) (string, error)

RemoveNamespacesPrefix is a transformer that strips "ns/", "namespace/" and "namespaces/" prefixes case-insensitively

func ResolveConfigPaths

func ResolveConfigPaths(config *clientcmdapi.Config, base string) error

func ResolveLocalPaths

func ResolveLocalPaths(config *clientcmdapi.Config) error

ResolveLocalPaths resolves all relative paths in the config object with respect to the stanza's LocationOfOrigin this cannot be done directly inside of LoadFromFile because doing so there would make it impossible to load a file without modification of its contents.

func ResolvePaths

func ResolvePaths(refs []*string, base string) error

ResolvePaths updates the given refs to be absolute paths, relative to the given base directory

func Validate

func Validate(config clientcmdapi.Config) error

Validate checks for errors in the Config. It does not return early so that it can find as many errors as possible.

func Write

func Write(config clientcmdapi.Config) ([]byte, error)

Write serializes the config to yaml. Encapsulates serialization without assuming the destination is a file.

func WriteToFile

func WriteToFile(config clientcmdapi.Config, filename string) error

WriteToFile serializes the config to yaml and writes it out to a file. If not present, it creates the file with the mode 0600. If it is present it stomps the contents

Types

type AuthLoader

type AuthLoader interface {
	// LoadAuth takes a path to a config file and can then do anything it needs in order to return a valid clientauth.Info
	LoadAuth(path string) (*clientauth.Info, error)
}

AuthLoaders are used to build clientauth.Info objects.

func NewDefaultAuthLoader

func NewDefaultAuthLoader() AuthLoader

NewDefaultAuthLoader returns a default implementation of an AuthLoader that only reads from a config file

type AuthOverrideFlags

type AuthOverrideFlags struct {
	ClientCertificate FlagInfo
	ClientKey         FlagInfo
	Token             FlagInfo
	Impersonate       FlagInfo
	ImpersonateGroups FlagInfo
	Username          FlagInfo
	Password          FlagInfo
}

AuthOverrideFlags holds the flag names to be used for binding command line flags for AuthInfo objects

func RecommendedAuthOverrideFlags

func RecommendedAuthOverrideFlags(prefix string) AuthOverrideFlags

RecommendedAuthOverrideFlags is a convenience method to return recommended flag names prefixed with a string of your choosing

type ClientConfig

type ClientConfig interface {
	// RawConfig returns the merged result of all overrides
	RawConfig() (clientcmdapi.Config, error)
	// ClientConfig returns a complete client config
	ClientConfig() (*restclient.Config, error)
	// Namespace returns the namespace resulting from the merged
	// result of all overrides and a boolean indicating if it was
	// overridden
	Namespace() (string, bool, error)
	// ConfigAccess returns the rules for loading/persisting the config.
	ConfigAccess() ConfigAccess
}

ClientConfig is used to make it easy to get an api server client

func NewClientConfigFromBytes

func NewClientConfigFromBytes(configBytes []byte) (ClientConfig, error)

NewClientConfigFromBytes takes your kubeconfig and gives you back a ClientConfig

func NewDefaultClientConfig

func NewDefaultClientConfig(config clientcmdapi.Config, overrides *ConfigOverrides) ClientConfig

NewDefaultClientConfig creates a DirectClientConfig using the config.CurrentContext as the context name

func NewInteractiveClientConfig

func NewInteractiveClientConfig(config clientcmdapi.Config, contextName string, overrides *ConfigOverrides, fallbackReader io.Reader, configAccess ConfigAccess) ClientConfig

NewInteractiveClientConfig creates a DirectClientConfig using the passed context name and a reader in case auth information is not provided via files or flags

func NewInteractiveDeferredLoadingClientConfig

func NewInteractiveDeferredLoadingClientConfig(loader ClientConfigLoader, overrides *ConfigOverrides, fallbackReader io.Reader) ClientConfig

NewInteractiveDeferredLoadingClientConfig creates a ConfigClientClientConfig using the passed context name and the fallback auth reader

func NewNonInteractiveClientConfig

func NewNonInteractiveClientConfig(config clientcmdapi.Config, contextName string, overrides *ConfigOverrides, configAccess ConfigAccess) ClientConfig

NewNonInteractiveClientConfig creates a DirectClientConfig using the passed context name and does not have a fallback reader for auth information

func NewNonInteractiveDeferredLoadingClientConfig

func NewNonInteractiveDeferredLoadingClientConfig(loader ClientConfigLoader, overrides *ConfigOverrides) ClientConfig

NewNonInteractiveDeferredLoadingClientConfig creates a ConfigClientClientConfig using the passed context name

type ClientConfigGetter

type ClientConfigGetter struct {
	// contains filtered or unexported fields
}

func (*ClientConfigGetter) GetDefaultFilename

func (g *ClientConfigGetter) GetDefaultFilename() string

func (*ClientConfigGetter) GetExplicitFile

func (g *ClientConfigGetter) GetExplicitFile() string

func (*ClientConfigGetter) GetLoadingPrecedence

func (g *ClientConfigGetter) GetLoadingPrecedence() []string

func (*ClientConfigGetter) GetStartingConfig

func (g *ClientConfigGetter) GetStartingConfig() (*clientcmdapi.Config, error)

func (*ClientConfigGetter) IsDefaultConfig

func (g *ClientConfigGetter) IsDefaultConfig(config *restclient.Config) bool

func (*ClientConfigGetter) IsExplicitFile

func (g *ClientConfigGetter) IsExplicitFile() bool

func (*ClientConfigGetter) Load

type ClientConfigLoader

type ClientConfigLoader interface {
	ConfigAccess
	// IsDefaultConfig returns true if the returned config matches the defaults.
	IsDefaultConfig(*restclient.Config) bool
	// Load returns the latest config
	Load() (*clientcmdapi.Config, error)
}

type ClientConfigLoadingRules

type ClientConfigLoadingRules struct {
	ExplicitPath string
	Precedence   []string

	// MigrationRules is a map of destination files to source files.  If a destination file is not present, then the source file is checked.
	// If the source file is present, then it is copied to the destination file BEFORE any further loading happens.
	MigrationRules map[string]string

	// DoNotResolvePaths indicates whether or not to resolve paths with respect to the originating files.  This is phrased as a negative so
	// that a default object that doesn't set this will usually get the behavior it wants.
	DoNotResolvePaths bool

	// DefaultClientConfig is an optional field indicating what rules to use to calculate a default configuration.
	// This should match the overrides passed in to ClientConfig loader.
	DefaultClientConfig ClientConfig
}

ClientConfigLoadingRules is an ExplicitPath and string slice of specific locations that are used for merging together a Config Callers can put the chain together however they want, but we'd recommend: EnvVarPathFiles if set (a list of files if set) OR the HomeDirectoryPath ExplicitPath is special, because if a user specifically requests a certain file be used and error is reported if this file is not present

func NewDefaultClientConfigLoadingRules

func NewDefaultClientConfigLoadingRules() *ClientConfigLoadingRules

NewDefaultClientConfigLoadingRules returns a ClientConfigLoadingRules object with default fields filled in. You are not required to use this constructor

func (*ClientConfigLoadingRules) GetDefaultFilename

func (rules *ClientConfigLoadingRules) GetDefaultFilename() string

GetDefaultFilename implements ConfigAccess

func (*ClientConfigLoadingRules) GetExplicitFile

func (rules *ClientConfigLoadingRules) GetExplicitFile() string

GetExplicitFile implements ConfigAccess

func (*ClientConfigLoadingRules) GetLoadingPrecedence

func (rules *ClientConfigLoadingRules) GetLoadingPrecedence() []string

GetLoadingPrecedence implements ConfigAccess

func (*ClientConfigLoadingRules) GetStartingConfig

func (rules *ClientConfigLoadingRules) GetStartingConfig() (*clientcmdapi.Config, error)

GetStartingConfig implements ConfigAccess

func (*ClientConfigLoadingRules) IsDefaultConfig

func (rules *ClientConfigLoadingRules) IsDefaultConfig(config *restclient.Config) bool

IsDefaultConfig returns true if the provided configuration matches the default

func (*ClientConfigLoadingRules) IsExplicitFile

func (rules *ClientConfigLoadingRules) IsExplicitFile() bool

IsExplicitFile implements ConfigAccess

func (*ClientConfigLoadingRules) Load

Load starts by running the MigrationRules and then takes the loading rules and returns a Config object based on following rules.

if the ExplicitPath, return the unmerged explicit file
Otherwise, return a merged config based on the Precedence slice

A missing ExplicitPath file produces an error. Empty filenames or other missing files are ignored. Read errors or files with non-deserializable content produce errors. The first file to set a particular map key wins and map key's value is never changed. BUT, if you set a struct value that is NOT contained inside of map, the value WILL be changed. This results in some odd looking logic to merge in one direction, merge in the other, and then merge the two. It also means that if two files specify a "red-user", only values from the first file's red-user are used. Even non-conflicting entries from the second file's "red-user" are discarded. Relative paths inside of the .kubeconfig files are resolved against the .kubeconfig file's parent folder and only absolute file paths are returned.

func (*ClientConfigLoadingRules) Migrate

func (rules *ClientConfigLoadingRules) Migrate() error

Migrate uses the MigrationRules map. If a destination file is not present, then the source file is checked. If the source file is present, then it is copied to the destination file BEFORE any further loading happens.

func (ClientConfigLoadingRules) ResolvePaths

func (rules ClientConfigLoadingRules) ResolvePaths() bool

type ClusterOverrideFlags

type ClusterOverrideFlags struct {
	APIServer             FlagInfo
	APIVersion            FlagInfo
	CertificateAuthority  FlagInfo
	InsecureSkipTLSVerify FlagInfo
}

ClusterOverride holds the flag names to be used for binding command line flags for Cluster objects

func RecommendedClusterOverrideFlags

func RecommendedClusterOverrideFlags(prefix string) ClusterOverrideFlags

RecommendedClusterOverrideFlags is a convenience method to return recommended flag names prefixed with a string of your choosing

type ConfigAccess

type ConfigAccess interface {
	// GetLoadingPrecedence returns the slice of files that should be used for loading and inspecting the config
	GetLoadingPrecedence() []string
	// GetStartingConfig returns the config that subcommands should being operating against.  It may or may not be merged depending on loading rules
	GetStartingConfig() (*clientcmdapi.Config, error)
	// GetDefaultFilename returns the name of the file you should write into (create if necessary), if you're trying to create a new stanza as opposed to updating an existing one.
	GetDefaultFilename() string
	// IsExplicitFile indicates whether or not this command is interested in exactly one file.  This implementation only ever does that  via a flag, but implementations that handle local, global, and flags may have more
	IsExplicitFile() bool
	// GetExplicitFile returns the particular file this command is operating against.  This implementation only ever has one, but implementations that handle local, global, and flags may have more
	GetExplicitFile() string
}

ConfigAccess is used by subcommands and methods in this package to load and modify the appropriate config files

type ConfigOverrideFlags

type ConfigOverrideFlags struct {
	AuthOverrideFlags    AuthOverrideFlags
	ClusterOverrideFlags ClusterOverrideFlags
	ContextOverrideFlags ContextOverrideFlags
	CurrentContext       FlagInfo
	Timeout              FlagInfo
}

ConfigOverrideFlags holds the flag names to be used for binding command line flags. Notice that this structure tightly corresponds to ConfigOverrides

func RecommendedConfigOverrideFlags

func RecommendedConfigOverrideFlags(prefix string) ConfigOverrideFlags

RecommendedConfigOverrideFlags is a convenience method to return recommended flag names prefixed with a string of your choosing

type ConfigOverrides

type ConfigOverrides struct {
	AuthInfo clientcmdapi.AuthInfo
	// ClusterDefaults are applied before the configured cluster info is loaded.
	ClusterDefaults clientcmdapi.Cluster
	ClusterInfo     clientcmdapi.Cluster
	Context         clientcmdapi.Context
	CurrentContext  string
	Timeout         string
}

ConfigOverrides holds values that should override whatever information is pulled from the actual Config object. You can't simply use an actual Config object, because Configs hold maps, but overrides are restricted to "at most one"

type ContextOverrideFlags

type ContextOverrideFlags struct {
	ClusterName  FlagInfo
	AuthInfoName FlagInfo
	Namespace    FlagInfo
}

ContextOverrideFlags holds the flag names to be used for binding command line flags for Cluster objects

func RecommendedContextOverrideFlags

func RecommendedContextOverrideFlags(prefix string) ContextOverrideFlags

RecommendedContextOverrideFlags is a convenience method to return recommended flag names prefixed with a string of your choosing

type DeferredLoadingClientConfig

type DeferredLoadingClientConfig struct {
	// contains filtered or unexported fields
}

DeferredLoadingClientConfig is a ClientConfig interface that is backed by a client config loader. It is used in cases where the loading rules may change after you've instantiated them and you want to be sure that the most recent rules are used. This is useful in cases where you bind flags to loading rule parameters before the parse happens and you want your calling code to be ignorant of how the values are being mutated to avoid passing extraneous information down a call stack

func (*DeferredLoadingClientConfig) ClientConfig

func (config *DeferredLoadingClientConfig) ClientConfig() (*restclient.Config, error)

ClientConfig implements ClientConfig

func (*DeferredLoadingClientConfig) ConfigAccess

func (config *DeferredLoadingClientConfig) ConfigAccess() ConfigAccess

ConfigAccess implements ClientConfig

func (*DeferredLoadingClientConfig) Namespace

func (config *DeferredLoadingClientConfig) Namespace() (string, bool, error)

Namespace implements KubeConfig

func (*DeferredLoadingClientConfig) RawConfig

func (config *DeferredLoadingClientConfig) RawConfig() (clientcmdapi.Config, error)

type DirectClientConfig

type DirectClientConfig struct {
	// contains filtered or unexported fields
}

DirectClientConfig is a ClientConfig interface that is backed by a clientcmdapi.Config, options overrides, and an optional fallbackReader for auth information

func (*DirectClientConfig) ClientConfig

func (config *DirectClientConfig) ClientConfig() (*restclient.Config, error)

ClientConfig implements ClientConfig

func (*DirectClientConfig) ConfigAccess

func (config *DirectClientConfig) ConfigAccess() ConfigAccess

ConfigAccess implements ClientConfig

func (*DirectClientConfig) ConfirmUsable

func (config *DirectClientConfig) ConfirmUsable() error

ConfirmUsable looks a particular context and determines if that particular part of the config is useable. There might still be errors in the config, but no errors in the sections requested or referenced. It does not return early so that it can find as many errors as possible.

func (*DirectClientConfig) Namespace

func (config *DirectClientConfig) Namespace() (string, bool, error)

Namespace implements ClientConfig

func (*DirectClientConfig) RawConfig

func (config *DirectClientConfig) RawConfig() (clientcmdapi.Config, error)

type FlagInfo

type FlagInfo struct {
	// LongName is the long string for a flag.  If this is empty, then the flag will not be bound
	LongName string
	// ShortName is the single character for a flag.  If this is empty, then there will be no short flag
	ShortName string
	// Default is the default value for the flag
	Default string
	// Description is the description for the flag
	Description string
}

FlagInfo contains information about how to register a flag. This struct is useful if you want to provide a way for an extender to get back a set of recommended flag names, descriptions, and defaults, but allow for customization by an extender. This makes for coherent extension, without full prescription

func (FlagInfo) AddSecretAnnotation

func (f FlagInfo) AddSecretAnnotation(flags *pflag.FlagSet) FlagInfo

AddSecretAnnotation add secret flag to Annotation.

func (FlagInfo) BindBoolFlag

func (f FlagInfo) BindBoolFlag(flags *pflag.FlagSet, target *bool) FlagInfo

BindBoolFlag binds the flag based on the provided info. If LongName == "", nothing is registered

func (FlagInfo) BindStringArrayFlag

func (f FlagInfo) BindStringArrayFlag(flags *pflag.FlagSet, target *[]string) FlagInfo

BindStringSliceFlag binds the flag based on the provided info. If LongName == "", nothing is registered

func (FlagInfo) BindStringFlag

func (f FlagInfo) BindStringFlag(flags *pflag.FlagSet, target *string) FlagInfo

BindStringFlag binds the flag based on the provided info. If LongName == "", nothing is registered

func (FlagInfo) BindTransformingStringFlag

func (f FlagInfo) BindTransformingStringFlag(flags *pflag.FlagSet, target *string, transformer func(string) (string, error)) FlagInfo

BindTransformingStringFlag binds the flag based on the provided info. If LongName == "", nothing is registered

type InClusterConfig

type InClusterConfig interface {
	ClientConfig
	Possible() bool
}

InClusterConfig abstracts details of whether the client is running in a cluster for testing.

type KubeconfigGetter

type KubeconfigGetter func() (*clientcmdapi.Config, error)

type PathOptions

type PathOptions struct {
	// GlobalFile is the full path to the file to load as the global (final) option
	GlobalFile string
	// EnvVar is the env var name that points to the list of kubeconfig files to load
	EnvVar string
	// ExplicitFileFlag is the name of the flag to use for prompting for the kubeconfig file
	ExplicitFileFlag string

	// GlobalFileSubpath is an optional value used for displaying help
	GlobalFileSubpath string

	LoadingRules *ClientConfigLoadingRules
}

func NewDefaultPathOptions

func NewDefaultPathOptions() *PathOptions

func (*PathOptions) GetDefaultFilename

func (o *PathOptions) GetDefaultFilename() string

func (*PathOptions) GetEnvVarFiles

func (o *PathOptions) GetEnvVarFiles() []string

func (*PathOptions) GetExplicitFile

func (o *PathOptions) GetExplicitFile() string

func (*PathOptions) GetLoadingPrecedence

func (o *PathOptions) GetLoadingPrecedence() []string

func (*PathOptions) GetStartingConfig

func (o *PathOptions) GetStartingConfig() (*clientcmdapi.Config, error)

func (*PathOptions) IsExplicitFile

func (o *PathOptions) IsExplicitFile() bool

type PersistAuthProviderConfigForUser

type PersistAuthProviderConfigForUser func(user string) restclient.AuthProviderConfigPersister

type PromptingAuthLoader

type PromptingAuthLoader struct {
	// contains filtered or unexported fields
}

func NewPromptingAuthLoader

func NewPromptingAuthLoader(reader io.Reader) *PromptingAuthLoader

NewPromptingAuthLoader is an AuthLoader that parses an AuthInfo object from a file path. It prompts user and creates file if it doesn't exist.

func (*PromptingAuthLoader) LoadAuth

func (a *PromptingAuthLoader) LoadAuth(path string) (*clientauth.Info, error)

LoadAuth parses an AuthInfo object from a file path. It prompts user and creates file if it doesn't exist.

func (*PromptingAuthLoader) Prompt

func (a *PromptingAuthLoader) Prompt() (*clientauth.Info, error)

Prompt pulls the user and password from a reader

Directories

Path Synopsis
api
v1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL