{"modulePath":"github.com/dockerstack/kubernetes","version":"v0.20.1-0.20150627061651-1c0b765df6da","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package clientcmd\n\nPackage 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.\n\nSample usage from merged .kubeconfig files (local directory, home directory)\n\n\tloadingRules := clientcmd.NewKubeConfigLoadingRules()\n\t// if you want to change the loading rules (which files in which order), you can do so here\n\n\tconfigOverrides := \u0026clientcmd.ConfigOverrides{}\n\t// if you want to change override values or bind them to flags, there are methods to help you\n\n\tkubeConfig := clientcmd.NewNonInteractiveDeferredLoadingKubeConfig(loadingRules, configOverrides)\n\tkubeConfig.Client()\n\n## Constants\n\n```go\nconst (\n\tRecommendedConfigPathFlag   = \"kubeconfig\"\n\tRecommendedConfigPathEnvVar = \"KUBECONFIG\"\n\tRecommendedHomeFileName     = \"/.kube/config\"\n)\n```\n\n```go\nconst (\n\tFlagClusterName  = \"cluster\"\n\tFlagAuthInfoName = \"user\"\n\tFlagContext      = \"context\"\n\tFlagNamespace    = \"namespace\"\n\tFlagAPIServer    = \"server\"\n\tFlagAPIVersion   = \"api-version\"\n\tFlagInsecure     = \"insecure-skip-tls-verify\"\n\tFlagCertFile     = \"client-certificate\"\n\tFlagKeyFile      = \"client-key\"\n\tFlagCAFile       = \"certificate-authority\"\n\tFlagEmbedCerts   = \"embed-certs\"\n\tFlagBearerToken  = \"token\"\n\tFlagUsername     = \"username\"\n\tFlagPassword     = \"password\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// DefaultCluster is the cluster config used when no other config is specified\n\t// TODO: eventually apiserver should start on 443 and be secure by default\n\tDefaultCluster = clientcmdapi.Cluster{Server: \"http://localhost:8080\"}\n\n\t// EnvVarCluster allows overriding the DefaultCluster using an envvar for the server name\n\tEnvVarCluster = clientcmdapi.Cluster{Server: os.Getenv(\"KUBERNETES_MASTER\")}\n\n\tDefaultClientConfig = DirectClientConfig{*clientcmdapi.NewConfig(), \"\", \u0026ConfigOverrides{}, nil}\n)\n```\n\n```go\nvar ErrNoContext = errors.New(\"no context chosen\")\n```\n\n```go\nvar OldRecommendedHomeFile = path.Join(os.Getenv(\"HOME\"), \"/.kube/.kubeconfig\")\n```\n\n```go\nvar RecommendedHomeFile = path.Join(os.Getenv(\"HOME\"), RecommendedHomeFileName)\n```\n\n## Functions\n\n```go\nfunc BindAuthInfoFlags(authInfo *clientcmdapi.AuthInfo, flags *pflag.FlagSet, flagNames AuthOverrideFlags)\n```\nBindAuthInfoFlags is a convenience method to bind the specified flags to their associated variables\n\n```go\nfunc BindClusterFlags(clusterInfo *clientcmdapi.Cluster, flags *pflag.FlagSet, flagNames ClusterOverrideFlags)\n```\nBindClusterFlags is a convenience method to bind the specified flags to their associated variables\n\n```go\nfunc BindContextFlags(contextInfo *clientcmdapi.Context, flags *pflag.FlagSet, flagNames ContextOverrideFlags)\n```\nBindFlags is a convenience method to bind the specified flags to their associated variables\n\n```go\nfunc BindOverrideFlags(overrides *ConfigOverrides, flags *pflag.FlagSet, flagNames ConfigOverrideFlags)\n```\nBindOverrideFlags is a convenience method to bind the specified flags to their associated variables\n\n```go\nfunc ConfirmUsable(config clientcmdapi.Config, passedContextName string) error\n```\nConfirmUsable 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.\n\n```go\nfunc IsConfigurationInvalid(err error) bool\n```\nIsConfigurationInvalid returns true if the provided error indicates the configuration is invalid.\n\n```go\nfunc IsContextNotFound(err error) bool\n```\nIsContextNotFound returns a boolean indicating whether the error is known to report that a context was not found\n\n```go\nfunc Load(data []byte) (*clientcmdapi.Config, error)\n```\nLoad takes a byte slice and deserializes the contents into Config object. Encapsulates deserialization without assuming the source is a file.\n\n```go\nfunc LoadFromFile(filename string) (*clientcmdapi.Config, error)\n```\nLoadFromFile takes a filename and deserializes the contents into Config object\n\n```go\nfunc ResolveLocalPaths(filename string, config *clientcmdapi.Config) error\n```\nResolveLocalPaths resolves all relative paths in the config object with respect to the parent directory of the filename 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.\n\n```go\nfunc Validate(config clientcmdapi.Config) error\n```\nValidate checks for errors in the Config.  It does not return early so that it can find as many errors as possible.\n\n```go\nfunc Write(config clientcmdapi.Config) ([]byte, error)\n```\nWrite serializes the config to yaml. Encapsulates serialization without assuming the destination is a file.\n\n```go\nfunc WriteToFile(config clientcmdapi.Config, filename string) error\n```\nWriteToFile 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\n\n## Types\n\n```go\ntype AuthLoader interface {\n\t// LoadAuth takes a path to a config file and can then do anything it needs in order to return a valid clientauth.Info\n\tLoadAuth(path string) (*clientauth.Info, error)\n}\n```\nAuthLoaders are used to build clientauth.Info objects.\n\n```go\nfunc NewDefaultAuthLoader() AuthLoader\n```\nNewDefaultAuthLoader returns a default implementation of an AuthLoader that only reads from a config file\n\n```go\ntype AuthOverrideFlags struct {\n\tClientCertificate FlagInfo\n\tClientKey         FlagInfo\n\tToken             FlagInfo\n\tUsername          FlagInfo\n\tPassword          FlagInfo\n}\n```\nAuthOverrideFlags holds the flag names to be used for binding command line flags for AuthInfo objects\n\n```go\nfunc RecommendedAuthOverrideFlags(prefix string) AuthOverrideFlags\n```\nRecommendedAuthOverrideFlags is a convenience method to return recommended flag names prefixed with a string of your choosing\n\n```go\ntype ClientConfig interface {\n\t// RawConfig returns the merged result of all overrides\n\tRawConfig() (clientcmdapi.Config, error)\n\t// ClientConfig returns a complete client config\n\tClientConfig() (*client.Config, error)\n\t// Namespace returns the namespace resulting from the merged result of all overrides\n\tNamespace() (string, error)\n}\n```\nClientConfig is used to make it easy to get an api server client\n\n```go\nfunc NewDefaultClientConfig(config clientcmdapi.Config, overrides *ConfigOverrides) ClientConfig\n```\nNewDefaultClientConfig creates a DirectClientConfig using the config.CurrentContext as the context name\n\n```go\nfunc NewInteractiveClientConfig(config clientcmdapi.Config, contextName string, overrides *ConfigOverrides, fallbackReader io.Reader) ClientConfig\n```\nNewInteractiveClientConfig creates a DirectClientConfig using the passed context name and a reader in case auth information is not provided via files or flags\n\n```go\nfunc NewInteractiveDeferredLoadingClientConfig(loadingRules *ClientConfigLoadingRules, overrides *ConfigOverrides, fallbackReader io.Reader) ClientConfig\n```\nNewInteractiveDeferredLoadingClientConfig creates a ConfigClientClientConfig using the passed context name and the fallback auth reader\n\n```go\nfunc NewNonInteractiveClientConfig(config clientcmdapi.Config, contextName string, overrides *ConfigOverrides) ClientConfig\n```\nNewNonInteractiveClientConfig creates a DirectClientConfig using the passed context name and does not have a fallback reader for auth information\n\n```go\nfunc NewNonInteractiveDeferredLoadingClientConfig(loadingRules *ClientConfigLoadingRules, overrides *ConfigOverrides) ClientConfig\n```\nNewNonInteractiveDeferredLoadingClientConfig creates a ConfigClientClientConfig using the passed context name\n\n```go\ntype ClientConfigLoadingRules struct {\n\tExplicitPath string\n\tPrecedence   []string\n\n\t// MigrationRules is a map of destination files to source files.  If a destination file is not present, then the source file is checked.\n\t// If the source file is present, then it is copied to the destination file BEFORE any further loading happens.\n\tMigrationRules map[string]string\n\n\t// DoNotResolvePaths indicates whether or not to resolve paths with respect to the originating files.  This is phrased as a negative so\n\t// that a default object that doesn't set this will usually get the behavior it wants.\n\tDoNotResolvePaths bool\n}\n```\nClientConfigLoadingRules 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 thie file is not present\n\n```go\nfunc NewDefaultClientConfigLoadingRules() *ClientConfigLoadingRules\n```\nNewDefaultClientConfigLoadingRules returns a ClientConfigLoadingRules object with default fields filled in.  You are not required to use this constructor\n\n```go\nfunc (rules *ClientConfigLoadingRules) Load() (*clientcmdapi.Config, error)\n```\nLoad starts by running the MigrationRules and then takes the loading rules and returns a Config object based on following rules.\n\n\tif the ExplicitPath, return the unmerged explicit file\n\tOtherwise, return a merged config based on the Precedence slice\n\nA 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.\n\n```go\nfunc (rules *ClientConfigLoadingRules) Migrate() error\n```\nMigrate 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.\n\n```go\nfunc (rules ClientConfigLoadingRules) ResolvePaths() bool\n```\n\n```go\ntype ClusterOverrideFlags struct {\n\tAPIServer             FlagInfo\n\tAPIVersion            FlagInfo\n\tCertificateAuthority  FlagInfo\n\tInsecureSkipTLSVerify FlagInfo\n}\n```\nClusterOverride holds the flag names to be used for binding command line flags for Cluster objects\n\n```go\nfunc RecommendedClusterOverrideFlags(prefix string) ClusterOverrideFlags\n```\nRecommendedClusterOverrideFlags is a convenience method to return recommended flag names prefixed with a string of your choosing\n\n```go\ntype ConfigOverrideFlags struct {\n\tAuthOverrideFlags    AuthOverrideFlags\n\tClusterOverrideFlags ClusterOverrideFlags\n\tContextOverrideFlags ContextOverrideFlags\n\tCurrentContext       FlagInfo\n}\n```\nConfigOverrideFlags holds the flag names to be used for binding command line flags.  Notice that this structure tightly corresponds to ConfigOverrides\n\n```go\nfunc RecommendedConfigOverrideFlags(prefix string) ConfigOverrideFlags\n```\nRecommendedConfigOverrideFlags is a convenience method to return recommended flag names prefixed with a string of your choosing\n\n```go\ntype ConfigOverrides struct {\n\tAuthInfo       clientcmdapi.AuthInfo\n\tClusterInfo    clientcmdapi.Cluster\n\tContext        clientcmdapi.Context\n\tCurrentContext string\n}\n```\nConfigOverrides 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\"\n\n```go\ntype ContextOverrideFlags struct {\n\tClusterName  FlagInfo\n\tAuthInfoName FlagInfo\n\tNamespace    FlagInfo\n}\n```\nContextOverrideFlags holds the flag names to be used for binding command line flags for Cluster objects\n\n```go\nfunc RecommendedContextOverrideFlags(prefix string) ContextOverrideFlags\n```\nRecommendedContextOverrideFlags is a convenience method to return recommended flag names prefixed with a string of your choosing\n\n```go\ntype DeferredLoadingClientConfig struct {\n\t// contains filtered or unexported fields\n}\n```\nDeferredLoadingClientConfig is a ClientConfig interface that is backed by a set of loading rules 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\n\n```go\nfunc (config DeferredLoadingClientConfig) ClientConfig() (*client.Config, error)\n```\nClientConfig implements ClientConfig\n\n```go\nfunc (config DeferredLoadingClientConfig) Namespace() (string, error)\n```\nNamespace implements KubeConfig\n\n```go\nfunc (config DeferredLoadingClientConfig) RawConfig() (clientcmdapi.Config, error)\n```\n\n```go\ntype DirectClientConfig struct {\n\t// contains filtered or unexported fields\n}\n```\nDirectClientConfig is a ClientConfig interface that is backed by a clientcmdapi.Config, options overrides, and an optional fallbackReader for auth information\n\n```go\nfunc (config DirectClientConfig) ClientConfig() (*client.Config, error)\n```\nClientConfig implements ClientConfig\n\n```go\nfunc (config DirectClientConfig) ConfirmUsable() error\n```\nConfirmUsable 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.\n\n```go\nfunc (config DirectClientConfig) Namespace() (string, error)\n```\nNamespace implements KubeConfig\n\n```go\nfunc (config DirectClientConfig) RawConfig() (clientcmdapi.Config, error)\n```\n\n```go\ntype FlagInfo struct {\n\t// LongName is the long string for a flag.  If this is empty, then the flag will not be bound\n\tLongName string\n\t// ShortName is the single character for a flag.  If this is empty, then there will be no short flag\n\tShortName string\n\t// Default is the default value for the flag\n\tDefault string\n\t// Description is the description for the flag\n\tDescription string\n}\n```\nFlagInfo 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\n\n```go\nfunc (f FlagInfo) BindBoolFlag(flags *pflag.FlagSet, target *bool)\n```\nBindBoolFlag binds the flag based on the provided info.  If LongName == \"\", nothing is registered\n\n```go\nfunc (f FlagInfo) BindStringFlag(flags *pflag.FlagSet, target *string)\n```\nBindStringFlag binds the flag based on the provided info.  If LongName == \"\", nothing is registered\n\n```go\ntype PromptingAuthLoader struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewPromptingAuthLoader(reader io.Reader) *PromptingAuthLoader\n```\nNewPromptingAuthLoader is an AuthLoader that parses an AuthInfo object from a file path. It prompts user and creates file if it doesn't exist.\n\n```go\nfunc (a *PromptingAuthLoader) LoadAuth(path string) (*clientauth.Info, error)\n```\nLoadAuth parses an AuthInfo object from a file path. It prompts user and creates file if it doesn't exist.\n\n```go\nfunc (a *PromptingAuthLoader) Prompt() *clientauth.Info\n```\nPrompt pulls the user and password from a reader\n\n","path":"github.com/dockerstack/kubernetes/pkg/client/clientcmd","name":"clientcmd","synopsis":"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.","isRedistributable":true}
