kubernetes: github.com/erimatnor/kubernetes/pkg/client/clientcmd Index | Files | Directories

package clientcmd

import "github.com/erimatnor/kubernetes/pkg/client/clientcmd"

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.NewKubeConfigLoadingRules()
// 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.NewNonInteractiveDeferredLoadingKubeConfig(loadingRules, configOverrides)
kubeConfig.Client()

Index

Package Files

auth_loaders.go client_config.go doc.go loader.go merged_client_builder.go overrides.go validation.go

Constants

const (
    RecommendedConfigPathFlag   = "kubeconfig"
    RecommendedConfigPathEnvVar = "KUBECONFIG"
    RecommendedHomeFileName     = "/.kube/config"
)
const (
    FlagClusterName  = "cluster"
    FlagAuthInfoName = "user"
    FlagContext      = "context"
    FlagNamespace    = "namespace"
    FlagAPIServer    = "server"
    FlagAPIVersion   = "api-version"
    FlagAuthPath     = "auth-path"
    FlagInsecure     = "insecure-skip-tls-verify"
    FlagCertFile     = "client-certificate"
    FlagKeyFile      = "client-key"
    FlagCAFile       = "certificate-authority"
    FlagEmbedCerts   = "embed-certs"
    FlagBearerToken  = "token"
    FlagUsername     = "username"
    FlagPassword     = "password"
)

Variables

var (
    // DefaultCluster is the cluster config used when no other config is specified
    // TODO: eventually apiserver should start on 443 and be secure by default
    DefaultCluster = clientcmdapi.Cluster{Server: "http://localhost:8080"}

    // EnvVarCluster allows overriding the DefaultCluster using an envvar for the server name
    EnvVarCluster = clientcmdapi.Cluster{Server: os.Getenv("KUBERNETES_MASTER")}
)
var ErrNoContext = errors.New("no context chosen")
var OldRecommendedHomeFile = path.Join(os.Getenv("HOME"), "/.kube/.kubeconfig")
var RecommendedHomeFile = path.Join(os.Getenv("HOME"), RecommendedHomeFileName)

func BindAuthInfoFlags Uses

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 Uses

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 Uses

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 Uses

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

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

func ConfirmUsable Uses

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 IsConfigurationInvalid Uses

func IsConfigurationInvalid(err error) bool

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

func IsContextNotFound Uses

func IsContextNotFound(err error) bool

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

func Load Uses

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 Uses

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

LoadFromFile takes a filename and deserializes the contents into Config object

func ResolveLocalPaths Uses

func ResolveLocalPaths(filename string, config *clientcmdapi.Config) error

ResolveLocalPaths 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.

func Validate Uses

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 Uses

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

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

func WriteToFile Uses

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

type AuthLoader Uses

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 Uses

func NewDefaultAuthLoader() AuthLoader

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

type AuthOverrideFlags Uses

type AuthOverrideFlags struct {
    AuthPath          FlagInfo
    ClientCertificate FlagInfo
    ClientKey         FlagInfo
    Token             FlagInfo
    Username          FlagInfo
    Password          FlagInfo
}

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

func RecommendedAuthOverrideFlags Uses

func RecommendedAuthOverrideFlags(prefix string) AuthOverrideFlags

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

type ClientConfig Uses

type ClientConfig interface {
    // RawConfig returns the merged result of all overrides
    RawConfig() (clientcmdapi.Config, error)
    // ClientConfig returns a complete client config
    ClientConfig() (*client.Config, error)
    // Namespace returns the namespace resulting from the merged result of all overrides
    Namespace() (string, error)
}

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

func NewDefaultClientConfig Uses

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

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

func NewInteractiveClientConfig Uses

func NewInteractiveClientConfig(config clientcmdapi.Config, contextName string, overrides *ConfigOverrides, fallbackReader io.Reader) 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 Uses

func NewInteractiveDeferredLoadingClientConfig(loadingRules *ClientConfigLoadingRules, overrides *ConfigOverrides, fallbackReader io.Reader) ClientConfig

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

func NewNonInteractiveClientConfig Uses

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

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

func NewNonInteractiveDeferredLoadingClientConfig Uses

func NewNonInteractiveDeferredLoadingClientConfig(loadingRules *ClientConfigLoadingRules, overrides *ConfigOverrides) ClientConfig

NewNonInteractiveDeferredLoadingClientConfig creates a ConfigClientClientConfig using the passed context name

type ClientConfigLoadingRules Uses

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
}

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 thie file is not present

func NewDefaultClientConfigLoadingRules Uses

func NewDefaultClientConfigLoadingRules() *ClientConfigLoadingRules

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

func (*ClientConfigLoadingRules) Load Uses

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

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 Uses

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 Uses

func (rules ClientConfigLoadingRules) ResolvePaths() bool

type ClusterOverrideFlags Uses

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 Uses

func RecommendedClusterOverrideFlags(prefix string) ClusterOverrideFlags

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

type ConfigOverrideFlags Uses

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

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

func RecommendedConfigOverrideFlags Uses

func RecommendedConfigOverrideFlags(prefix string) ConfigOverrideFlags

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

type ConfigOverrides Uses

type ConfigOverrides struct {
    AuthInfo       clientcmdapi.AuthInfo
    ClusterInfo    clientcmdapi.Cluster
    Context        clientcmdapi.Context
    CurrentContext 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 Uses

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 Uses

func RecommendedContextOverrideFlags(prefix string) ContextOverrideFlags

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

type DeferredLoadingClientConfig Uses

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

DeferredLoadingClientConfig 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

func (DeferredLoadingClientConfig) ClientConfig Uses

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

ClientConfig implements ClientConfig

func (DeferredLoadingClientConfig) Namespace Uses

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

Namespace implements KubeConfig

func (DeferredLoadingClientConfig) RawConfig Uses

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

type DirectClientConfig Uses

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 Uses

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

ClientConfig implements ClientConfig

func (DirectClientConfig) ConfirmUsable Uses

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 Uses

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

Namespace implements KubeConfig

func (DirectClientConfig) RawConfig Uses

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

type FlagInfo Uses

type FlagInfo struct {
    LongName    string
    ShortName   string
    Default     string
    Description string
}

type PromptingAuthLoader Uses

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

func NewPromptingAuthLoader Uses

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 Uses

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 Uses

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

Prompt pulls the user and password from a reader

Directories

PathSynopsis
api
api/latest
api/v1

Package clientcmd imports 20 packages (graph). Updated 2017-05-11. Refresh now. Tools for package owners.