Documentation ¶
Index ¶
- Constants
- func AddApplyAnnotationFlags(cmd *cobra.Command)
- func AddGeneratorFlags(cmd *cobra.Command, defaultGenerator string)
- func AddOutputFlagsForMutation(cmd *cobra.Command)
- func AddPrinterFlags(cmd *cobra.Command)
- func AddSourceToErr(verb string, source string, err error) error
- func AddValidateFlags(cmd *cobra.Command)
- func BehaviorOnFatal(f func(string))
- func CheckErr(err error)
- func DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig
- func DefaultGenerators() map[string]kubectl.Generator
- func DumpReaderToFile(reader io.Reader, filename string) error
- func GetFirstPod(client *client.Client, namespace string, selector map[string]string) (*api.Pod, error)
- func GetFlagBool(cmd *cobra.Command, flag string) bool
- func GetFlagDuration(cmd *cobra.Command, flag string) time.Duration
- func GetFlagInt(cmd *cobra.Command, flag string) int
- func GetFlagInt64(cmd *cobra.Command, flag string) int64
- func GetFlagString(cmd *cobra.Command, flag string) string
- func GetFlagStringSlice(cmd *cobra.Command, flag string) []string
- func GetWideFlag(cmd *cobra.Command) bool
- func Merge(dst runtime.Object, fragment, kind string) (runtime.Object, error)
- func MultilineError(prefix string, err error) string
- func MultipleErrors(prefix string, errs []error) string
- func OutputVersion(cmd *cobra.Command, defaultVersion *unversioned.GroupVersion) (unversioned.GroupVersion, error)
- func PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource string, ...)
- func PrinterForCommand(cmd *cobra.Command) (kubectl.ResourcePrinter, bool, error)
- func ReadConfigData(location string) ([]byte, error)
- func ReadConfigDataFromLocation(location string) ([]byte, error)
- func ReadConfigDataFromReader(reader io.Reader, source string) ([]byte, error)
- func StandardErrorMessage(err error) (string, bool)
- func UpdateObject(info *resource.Info, updateFn func(runtime.Object) error) (runtime.Object, error)
- func UsageError(cmd *cobra.Command, format string, args ...interface{}) error
- func ValidateOutputArgs(cmd *cobra.Command) error
- type ClientCache
- type Factory
- func (f *Factory) BindFlags(flags *pflag.FlagSet)
- func (f *Factory) ClientMapperForCommand() resource.ClientMapper
- func (f *Factory) NilClientMapperForCommand() resource.ClientMapper
- func (f *Factory) PrintObject(cmd *cobra.Command, obj runtime.Object, out io.Writer) error
- func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMapping, withNamespace bool) (kubectl.ResourcePrinter, error)
Constants ¶
const ( RunV1GeneratorName = "run/v1" RunPodV1GeneratorName = "run-pod/v1" ServiceV1GeneratorName = "service/v1" ServiceV2GeneratorName = "service/v2" HorizontalPodAutoscalerV1Beta1GeneratorName = "horizontalpodautoscaler/v1beta1" DeploymentV1Beta1GeneratorName = "deployment/v1beta1" JobV1Beta1GeneratorName = "job/v1beta1" NamespaceV1GeneratorName = "namespace/v1" SecretV1GeneratorName = "secret/v1" SecretForDockerRegistryV1GeneratorName = "secret-for-docker-registry/v1" )
const (
ApplyAnnotationsFlag = "save-config"
)
const (
FlagMatchBinaryVersion = "match-server-version"
)
Variables ¶
This section is empty.
Functions ¶
func AddApplyAnnotationFlags ¶
func AddGeneratorFlags ¶
AddGeneratorFlags adds flags common to resource generation commands TODO: need to take a pass at other generator commands to use this set of flags
func AddOutputFlagsForMutation ¶
AddOutputFlagsForMutation adds output related flags to a command. Used by mutations only.
func AddPrinterFlags ¶
AddPrinterFlags adds printing related flags to a command (e.g. output format, no headers, template path)
func AddSourceToErr ¶
AddSourceToErr adds handleResourcePrefix and source string to error message. verb is the string like "creating", "deleting" etc. souce is the filename or URL to the template file(*.json or *.yaml), or stdin to use to handle the resource.
func AddValidateFlags ¶
func BehaviorOnFatal ¶
func BehaviorOnFatal(f func(string))
BehaviorOnFatal allows you to override the default behavior when a fatal error occurs, which is call os.Exit(1). You can pass 'panic' as a function here if you prefer the panic() over os.Exit(1).
func CheckErr ¶
func CheckErr(err error)
CheckErr prints a user friendly error to STDERR and exits with a non-zero exit code. Unrecognized errors will be printed with an "error: " prefix.
This method is generic to the command in use and may be used by non-Kubectl commands.
func DefaultClientConfig ¶
func DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig
DefaultClientConfig creates a clientcmd.ClientConfig with the following hierarchy:
Use the kubeconfig builder. The number of merges and overrides here gets a little crazy. Stay with me.
Merge together the kubeconfig itself. This is done with the following hierarchy rules:
CommandLineLocation - this parsed from the command line, so it must be late bound. If you specify this, then no other kubeconfig files are merged. This file must exist.
If $KUBECONFIG is set, then it is treated as a list of files that should be merged.
HomeDirectoryLocation 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.
Determine the context to use based on the first hit in this chain
command line argument - again, parsed from the command line, so it must be late bound
CurrentContext from the merged kubeconfig file
Empty is allowed at this stage
Determine the cluster info and auth info to use. At this point, we may or may not have a context. They are built based on the first hit in this chain. (run it twice, once for auth, once for cluster)
command line argument
If context is present, then use the context value
Empty is allowed
Determine the actual cluster info to use. At this point, we may or may not have a cluster info. Build each piece of the cluster info based on the chain:
command line argument
If cluster info is present and a value for the attribute is present, use it.
If you don't have a server location, bail.
Auth info is build using the same rules as cluster info, EXCEPT that you can only have one authentication technique per auth info. The following conditions result in an error:
If there are two conflicting techniques specified from the command line, fail.
If the command line does not specify one, and the auth info has conflicting techniques, fail.
If the command line specifies one and the auth info specifies another, honor the command line technique.
Use default values and potentially prompt for auth information
However, if it appears that we're running in a kubernetes cluster container environment, then run with the auth info kubernetes mounted for us. Specifically: The env vars KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT are set, and the file /var/run/secrets/kubernetes.io/serviceaccount/token exists and is not a directory.
func DefaultGenerators ¶
DefaultGenerators returns the set of default generators for use in Factory instances
func DumpReaderToFile ¶
DumpReaderToFile writes all data from the given io.Reader to the specified file (usually for temporary use).
func GetFirstPod ¶
func GetFirstPod(client *client.Client, namespace string, selector map[string]string) (*api.Pod, error)
GetFirstPod returns the first pod of an object from its namespace and selector
func GetFlagInt ¶
Assumes the flag has a default value.
func GetFlagInt64 ¶
Assumes the flag has a default value.
func GetFlagStringSlice ¶
GetFlagStringList can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...)
func GetWideFlag ¶
GetWideFlag is used to determine if "-o wide" is used
func MultilineError ¶
MultilineError returns a string representing an error that splits sub errors into their own lines. The returned string will end with a newline.
func MultipleErrors ¶
MultipleErrors returns a newline delimited string containing the prefix and referenced errors in standard form.
func OutputVersion ¶
func OutputVersion(cmd *cobra.Command, defaultVersion *unversioned.GroupVersion) (unversioned.GroupVersion, error)
OutputVersion returns the preferred output version for generic content (JSON, YAML, or templates) defaultVersion is never mutated. Nil simply allows clean passing in common usage from client.Config
func PrintSuccess ¶
func PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource string, name string, operation string)
PrintSuccess prints message after finishing mutating operations
func PrinterForCommand ¶
PrinterForCommand returns the default printer for this command. Requires that printer flags have been added to cmd (see AddPrinterFlags).
func ReadConfigData ¶
ReadConfigData reads the bytes from the specified filesytem or network location or from stdin if location == "-". TODO: replace with resource.Builder
func ReadConfigDataFromLocation ¶
TODO: replace with resource.Builder
func StandardErrorMessage ¶
StandardErrorMessage translates common errors into a human readable message, or returns false if the error is not one of the recognized types. It may also log extended information to glog.
This method is generic to the command in use and may be used by non-Kubectl commands.
func UpdateObject ¶
UpdateObject updates resource object with updateFn
func ValidateOutputArgs ¶
ValidateOutputArgs validates -o flag args for mutations
Types ¶
type ClientCache ¶
type ClientCache struct {
// contains filtered or unexported fields
}
ClientCache caches previously loaded clients for reuse, and ensures MatchServerVersion is invoked only once
func NewClientCache ¶
func NewClientCache(loader clientcmd.ClientConfig) *ClientCache
func (*ClientCache) ClientConfigForVersion ¶
func (c *ClientCache) ClientConfigForVersion(version *unversioned.GroupVersion) (*client.Config, error)
ClientConfigForVersion returns the correct config for a server
func (*ClientCache) ClientForVersion ¶
func (c *ClientCache) ClientForVersion(version *unversioned.GroupVersion) (*client.Client, error)
ClientForVersion initializes or reuses a client for the specified version, or returns an error if that is not possible
type Factory ¶
type Factory struct { // Returns interfaces for dealing with arbitrary runtime.Objects. Object func() (meta.RESTMapper, runtime.ObjectTyper) // Returns a client for accessing Kubernetes resources or an error. Client func() (*client.Client, error) // Returns a client.Config for accessing the Kubernetes server. ClientConfig func() (*client.Config, error) // Returns a RESTClient for working with the specified RESTMapping or an error. This is intended // for working with arbitrary resources and is not guaranteed to point to a Kubernetes APIServer. RESTClient func(mapping *meta.RESTMapping) (resource.RESTClient, error) // Returns a Describer for displaying the specified RESTMapping type or an error. Describer func(mapping *meta.RESTMapping) (kubectl.Describer, error) // Returns a Printer for formatting objects of the given type or an error. Printer func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, showAll bool, absoluteTimestamps bool, columnLabels []string) (kubectl.ResourcePrinter, error) // Returns a Scaler for changing the size of the specified RESTMapping type or an error Scaler func(mapping *meta.RESTMapping) (kubectl.Scaler, error) // Returns a Reaper for gracefully shutting down resources. Reaper func(mapping *meta.RESTMapping) (kubectl.Reaper, error) // PodSelectorForObject returns the pod selector associated with the provided object PodSelectorForObject func(object runtime.Object) (string, error) // PortsForObject returns the ports associated with the provided object PortsForObject func(object runtime.Object) ([]string, error) // LabelsForObject returns the labels associated with the provided object LabelsForObject func(object runtime.Object) (map[string]string, error) // LogsForObject returns a request for the logs associated with the provided object LogsForObject func(object, options runtime.Object) (*client.Request, error) // Returns a schema that can validate objects stored on disk. Validator func(validate bool, cacheDir string) (validation.Schema, error) // Returns the default namespace to use in cases where no // other namespace is specified and whether the namespace was // overriden. DefaultNamespace func() (string, bool, error) // Returns the generator for the provided generator name Generator func(name string) (kubectl.Generator, bool) // Check whether the kind of resources could be exposed CanBeExposed func(kind unversioned.GroupKind) error // Check whether the kind of resources could be autoscaled CanBeAutoscaled func(kind unversioned.GroupKind) error // AttachablePodForObject returns the pod to which to attach given an object. AttachablePodForObject func(object runtime.Object) (*api.Pod, error) // EditorEnvs returns a group of environment variables that the edit command // can range over in order to determine if the user has specified an editor // of their choice. EditorEnvs func() []string // contains filtered or unexported fields }
Factory provides abstractions that allow the Kubectl command to be extended across multiple types of resources and different API sets. TODO: make the functions interfaces TODO: pass the various interfaces on the factory directly into the command constructors (so the commands are decoupled from the factory).
func NewFactory ¶
func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory
NewFactory creates a factory with the default Kubernetes resources defined if optionalClientConfig is nil, then flags will be bound to a new clientcmd.ClientConfig. if optionalClientConfig is not nil, then this factory will make use of it.
func (*Factory) ClientMapperForCommand ¶
func (f *Factory) ClientMapperForCommand() resource.ClientMapper
ClientMapperForCommand returns a ClientMapper for the factory.
func (*Factory) NilClientMapperForCommand ¶
func (f *Factory) NilClientMapperForCommand() resource.ClientMapper
NilClientMapperForCommand returns a ClientMapper which always returns nil. When command is running locally and client isn't needed, this mapper can be parsed to NewBuilder.
func (*Factory) PrintObject ¶
PrintObject prints an api object given command line flags to modify the output format
func (*Factory) PrinterForMapping ¶
func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMapping, withNamespace bool) (kubectl.ResourcePrinter, error)
PrinterForMapping returns a printer suitable for displaying the provided resource type. Requires that printer flags have been added to cmd (see AddPrinterFlags).