cmd

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2015 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagMatchBinaryVersion = "match-server-version"
)

Variables

This section is empty.

Functions

func AddPrinterFlags added in v0.9.0

func AddPrinterFlags(cmd *cobra.Command)

func ClientMapperForCommand added in v0.9.0

func ClientMapperForCommand(cmd *cobra.Command, f *Factory) resource.ClientMapper

ClientMapperForCommand returns a ClientMapper for the given command and factory.

func CompareNamespace added in v0.9.1

func CompareNamespace(defaultNamespace, namespace string) error

CompareNamespace returns an error if the namespace the user has provided on the CLI or via the default namespace file does not match the namespace of an input file. This prevents a user from unintentionally updating the wrong namespace.

func DefaultClientConfig added in v0.9.0

func DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig

DefaultClientConfig creates a clientcmd.ClientConfig with the following hierarchy:

  1. Use the kubeconfig builder. The number of merges and overrides here gets a little crazy. Stay with me.
  2. Merge together the kubeconfig itself. This is done with the following hierarchy and merge rules:
  3. CommandLineLocation - this parsed from the command line, so it must be late bound
  4. EnvVarLocation
  5. CurrentDirectoryLocation
  6. 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.
  7. Determine the context to use based on the first hit in this chain
  8. command line argument - again, parsed from the command line, so it must be late bound
  9. CurrentContext from the merged kubeconfig file
  10. Empty is allowed at this stage
  11. 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)
  12. command line argument
  13. If context is present, then use the context value
  14. Empty is allowed
  15. 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:
  16. command line argument
  17. If cluster info is present and a value for the attribute is present, use it.
  18. If you don't have a server location, bail.
  19. 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:
  20. If there are two conflicting techniques specified from the command line, fail.
  21. If the command line does not specify one, and the auth info has conflicting techniques, fail.
  22. If the command line specifies one and the auth info specifies another, honor the command line technique.
  23. Use default values and potentially prompt for auth information

func FirstNonEmptyString

func FirstNonEmptyString(args ...string) string

Returns the first non-empty string out of the ones provided. If all strings are empty, returns an empty string.

func GetFilesFromDir

func GetFilesFromDir(directory string, fileType string) []string

Return a list of file names of a certain type within a given directory. TODO: replace with resource.Builder

func GetFlagBool

func GetFlagBool(cmd *cobra.Command, flag string) bool

func GetFlagBoolPtr

func GetFlagBoolPtr(cmd *cobra.Command, flag string) *bool

Returns nil if the flag wasn't set.

func GetFlagDuration added in v0.9.0

func GetFlagDuration(cmd *cobra.Command, flag string) time.Duration

func GetFlagInt

func GetFlagInt(cmd *cobra.Command, flag string) int

Assumes the flag has a default value.

func GetFlagString

func GetFlagString(cmd *cobra.Command, flag string) string

func Merge added in v0.9.0

func Merge(dst runtime.Object, fragment, kind string) error

func NewCmdNamespace

func NewCmdNamespace(out io.Writer) *cobra.Command

func PrintObject added in v0.9.0

func PrintObject(cmd *cobra.Command, obj runtime.Object, f *Factory, out io.Writer) error

PrintObject prints an api object given command line flags to modify the output format

func PrinterForCommand added in v0.9.0

func PrinterForCommand(cmd *cobra.Command) (kubectl.ResourcePrinter, bool, error)

PrinterForCommand returns the default printer for this command. Requires that printer flags have been added to cmd (see AddPrinterFlags).

func PrinterForMapping added in v0.9.0

func PrinterForMapping(f *Factory, cmd *cobra.Command, mapping *meta.RESTMapping) (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).

func ReadConfigData

func ReadConfigData(location string) ([]byte, error)

ReadConfigData reads the bytes from the specified filesytem or network location or from stdin if location == "-". TODO: replace with resource.Builder

func ReadConfigDataFromLocation

func ReadConfigDataFromLocation(location string) ([]byte, error)

TODO: replace with resource.Builder

func ResourceFromArgs

func ResourceFromArgs(cmd *cobra.Command, args []string, mapper meta.RESTMapper, cmdNamespace string) (mapping *meta.RESTMapping, namespace, name string)

ResourceFromArgs expects two arguments with a given type, and extracts the fields necessary to uniquely locate a resource. Displays a usageError if that contract is not satisfied, or a generic error if any other problems occur.

func ResourceFromArgsOrFile

func ResourceFromArgsOrFile(cmd *cobra.Command, args []string, filename string, typer runtime.ObjectTyper, mapper meta.RESTMapper, schema validation.Schema, cmdNamespace, cmdVersion string) (mapping *meta.RESTMapping, namespace, name string)

ResourceFromArgsOrFile expects two arguments or a valid file with a given type, and extracts the fields necessary to uniquely locate a resource. Displays a usageError if that contract is not satisfied, or a generic error if any other problems occur.

func ResourceFromFile

func ResourceFromFile(filename string, typer runtime.ObjectTyper, mapper meta.RESTMapper, schema validation.Schema, cmdVersion string) (mapping *meta.RESTMapping, namespace, name string, data []byte)

ResourceFromFile retrieves the name and namespace from a valid file. If the file does not resolve to a known type an error is returned. The returned mapping can be used to determine the correct REST endpoint to modify this resource with.

func ResourceOrTypeFromArgs

func ResourceOrTypeFromArgs(cmd *cobra.Command, args []string, mapper meta.RESTMapper, cmdNamespace, cmdVersion string) (mapping *meta.RESTMapping, namespace, name string)

ResourceFromArgs expects two arguments with a given type, and extracts the fields necessary to uniquely locate a resource. Displays a usageError if that contract is not satisfied, or a generic error if any other problems occur.

func ResourcesFromArgsOrFile added in v0.8.0

func ResourcesFromArgsOrFile(
	cmd *cobra.Command,
	args []string,
	filename, selector string,
	typer runtime.ObjectTyper,
	mapper meta.RESTMapper,
	clientBuilder func(cmd *cobra.Command, mapping *meta.RESTMapping) (resource.RESTClient, error),
	schema validation.Schema,
	requireNames bool,
	cmdNamespace,
	cmdVersion string,
) resource.Visitor

ResourcesFromArgsOrFile computes a list of Resources by extracting info from filename or args. It will handle label selectors provided.

func RunGet added in v0.9.0

func RunGet(f *Factory, out io.Writer, cmd *cobra.Command, args []string)

RunGet implements the generic Get command TODO: convert all direct flag accessors to a struct and pass that instead of cmd TODO: return an error instead of using glog.Fatal and checkErr

func SplitResourceArgument added in v0.8.0

func SplitResourceArgument(arg string) []string

Types

type Factory

type Factory struct {

	// Returns interfaces for dealing with arbitrary runtime.Objects.
	Object func(cmd *cobra.Command) (meta.RESTMapper, runtime.ObjectTyper)
	// Returns a client for accessing Kubernetes resources or an error.
	Client func(cmd *cobra.Command) (*client.Client, error)
	// Returns a client.Config for accessing the Kubernetes server.
	ClientConfig func(cmd *cobra.Command) (*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(cmd *cobra.Command, mapping *meta.RESTMapping) (resource.RESTClient, error)
	// Returns a Describer for displaying the specified RESTMapping type or an error.
	Describer func(cmd *cobra.Command, mapping *meta.RESTMapping) (kubectl.Describer, error)
	// Returns a Printer for formatting objects of the given type or an error.
	Printer func(cmd *cobra.Command, mapping *meta.RESTMapping, noHeaders bool) (kubectl.ResourcePrinter, error)
	// Returns a Resizer for changing the size of the specified RESTMapping type or an error
	Resizer func(cmd *cobra.Command, mapping *meta.RESTMapping) (kubectl.Resizer, error)
	// Returns a Reaper for gracefully shutting down resources.
	Reaper func(cmd *cobra.Command, mapping *meta.RESTMapping) (kubectl.Reaper, error)
	// Returns a schema that can validate objects stored on disk.
	Validator func(*cobra.Command) (validation.Schema, error)
	// Returns the default namespace to use in cases where no other namespace is specified
	DefaultNamespace func(cmd *cobra.Command) (string, error)
	// 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

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) BindFlags added in v0.9.0

func (f *Factory) BindFlags(flags *pflag.FlagSet)

BindFlags adds any flags that are common to all kubectl sub commands.

func (*Factory) NewCmdCreate

func (f *Factory) NewCmdCreate(out io.Writer) *cobra.Command

func (*Factory) NewCmdDelete

func (f *Factory) NewCmdDelete(out io.Writer) *cobra.Command

func (*Factory) NewCmdDescribe

func (f *Factory) NewCmdDescribe(out io.Writer) *cobra.Command

func (*Factory) NewCmdGet

func (f *Factory) NewCmdGet(out io.Writer) *cobra.Command

NewCmdGet creates a command object for the generic "get" action, which retrieves one or more resources from a server.

func (*Factory) NewCmdLog added in v0.6.0

func (f *Factory) NewCmdLog(out io.Writer) *cobra.Command

func (*Factory) NewCmdProxy added in v0.6.0

func (f *Factory) NewCmdProxy(out io.Writer) *cobra.Command

func (*Factory) NewCmdResize added in v0.9.0

func (f *Factory) NewCmdResize(out io.Writer) *cobra.Command

func (*Factory) NewCmdRollingUpdate added in v0.9.0

func (f *Factory) NewCmdRollingUpdate(out io.Writer) *cobra.Command

func (*Factory) NewCmdRunContainer added in v0.9.0

func (f *Factory) NewCmdRunContainer(out io.Writer) *cobra.Command

func (*Factory) NewCmdStop added in v0.9.1

func (f *Factory) NewCmdStop(out io.Writer) *cobra.Command

func (*Factory) NewCmdUpdate

func (f *Factory) NewCmdUpdate(out io.Writer) *cobra.Command

func (*Factory) NewCmdVersion added in v0.6.0

func (f *Factory) NewCmdVersion(out io.Writer) *cobra.Command

func (*Factory) NewKubectlCommand added in v0.9.0

func (f *Factory) NewKubectlCommand(out io.Writer) *cobra.Command

NewKubectlCommand creates the `kubectl` command and its nested children.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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