clientcmd

package
v0.8.1-0...-6cd3763 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2015 License: Apache-2.0 Imports: 14 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.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

Constants

View Source
const (
	RecommendedConfigPathFlag   = "kubeconfig"
	RecommendedConfigPathEnvVar = "KUBECONFIG"
)
View Source
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"
	FlagBearerToken  = "token"
)

Variables

View Source
var ErrNoContext = errors.New("no context chosen")

Functions

func ConfirmUsable

func ConfirmUsable(config 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 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 Validate

func Validate(config 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 WriteToFile

func WriteToFile(config Config, filename string) error

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

Types

type AuthInfo

type AuthInfo struct {
	// AuthPath is the path to a kubernetes auth file (~/.kubernetes_auth).  If you provide an AuthPath, the other options specified are ignored
	AuthPath string `yaml:"auth-path,omitempty"`
	// ClientCertificate is the path to a client cert file for TLS.
	ClientCertificate string `yaml:"client-certificate,omitempty"`
	// ClientKey is the path to a client key file for TLS.
	ClientKey string `yaml:"client-key,omitempty"`
	// Token is the bearer token for authentication to the kubernetes cluster.
	Token string `yaml:"token,omitempty"`
}

AuthInfo contains information that describes identity information. This is use to tell the kubernetes cluster who you are.

func (*AuthInfo) BindFlags

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

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

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 {
	AuthPath          string
	ClientCertificate string
	ClientKey         string
	Token             string
}

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 {
	// ClientConfig returns a complete client config
	ClientConfig() (*client.Config, error)
}

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

func NewDefaultClientConfig

func NewDefaultClientConfig(config Config, overrides *ConfigOverrides) ClientConfig

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

func NewInteractiveClientConfig

func NewInteractiveClientConfig(config 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

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

func NewNonInteractiveClientConfig(config 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

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

NewNonInteractiveDeferredLoadingClientConfig creates a ConfigClientClientConfig using the passed context name

type ClientConfigLoadingRules

type ClientConfigLoadingRules struct {
	CommandLinePath      string
	EnvVarPath           string
	CurrentDirectoryPath string
	HomeDirectoryPath    string
}

ClientConfigLoadingRules is a struct that calls our specific locations that are used for merging together a Config

func NewClientConfigLoadingRules

func NewClientConfigLoadingRules() *ClientConfigLoadingRules

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

func (*ClientConfigLoadingRules) Load

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

Load takes the loading rules and merges together a Config object based on following order.

  1. CommandLinePath
  2. EnvVarPath
  3. CurrentDirectoryPath
  4. HomeDirectoryPath

Empty filenames are ignored. Files with non-deserializable content produced errors. The first file to set a particular value or map key wins and the value or map key is never changed. This means that the first file to set CurrentContext will have its context preserved. 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.

type Cluster

type Cluster struct {
	// Server is the address of the kubernetes cluster (https://hostname:port).
	Server string `yaml:"server"`
	// APIVersion is the preferred api version for communicating with the kubernetes cluster (v1beta1, v1beta2, v1beta3, etc).
	APIVersion string `yaml:"api-version,omitempty"`
	// InsecureSkipTLSVerify skips the validity check for the server's certificate. This will make your HTTPS connections insecure.
	InsecureSkipTLSVerify bool `yaml:"insecure-skip-tls-verify,omitempty"`
	// CertificateAuthority is the path to a cert file for the certificate authority.
	CertificateAuthority string `yaml:"certificate-authority,omitempty"`
}

Cluster contains information about how to communicate with a kubernetes cluster

func (*Cluster) BindFlags

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

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

type ClusterOverrideFlags

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

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 Config

type Config struct {
	// Preferences holds general information to be use for cli interactions
	Preferences Preferences `yaml:"preferences"`
	// Clusters is a map of referencable names to cluster configs
	Clusters map[string]Cluster `yaml:"clusters"`
	// AuthInfos is a map of referencable names to user configs
	AuthInfos map[string]AuthInfo `yaml:"users"`
	// Contexts is a map of referencable names to context configs
	Contexts map[string]Context `yaml:"contexts"`
	// CurrentContext is the name of the context that you would like to use by default
	CurrentContext string `yaml:"current-context"`
}

Config holds the information needed to build connect to remote kubernetes clusters as a given user

func LoadFromFile

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

LoadFromFile takes a filename and deserializes the contents into Config object

func NewConfig

func NewConfig() *Config

NewConfig is a convenience function that returns a new Config object with non-nil maps

type ConfigOverrideFlags

type ConfigOverrideFlags struct {
	AuthOverrideFlags    AuthOverrideFlags
	ClusterOverrideFlags ClusterOverrideFlags
	Namespace            string
	CurrentContext       string
	ClusterName          string
	AuthInfoName         string
}

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       AuthInfo
	ClusterInfo    Cluster
	Namespace      string
	CurrentContext string
	ClusterName    string
	AuthInfoName   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"

func (*ConfigOverrides) BindFlags

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

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

type Context

type Context struct {
	// Cluster is the name of the cluster for this context
	Cluster string `yaml:"cluster"`
	// AuthInfo is the name of the authInfo for this context
	AuthInfo string `yaml:"user"`
	// Namespace is the default namespace to use on unspecified requests
	Namespace string `yaml:"namespace,omitempty"`
}

Context is a tuple of references to a cluster (how do I communicate with a kubernetes cluster), a user (how do I identify myself), and a namespace (what subset of resources do I want to work with)

type DeferredLoadingClientConfig

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

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

ClientConfig implements ClientConfig

type DirectClientConfig

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

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

func (DirectClientConfig) ClientConfig

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

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

type Preferences

type Preferences struct {
	Colors bool `yaml:"colors,omitempty"`
}

type PromptingAuthLoader

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

func NewPromptingAuthLoader

func NewPromptingAuthLoader(reader io.Reader) *PromptingAuthLoader

NewDefaultAuthLoader 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

Prompt pulls the user and password from a reader

Jump to

Keyboard shortcuts

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