Documentation
¶
Index ¶
- Constants
- Variables
- func AddApplyAnnotationFlags(cmd *cobra.Command)
- func AddApplyAnnotationVarFlags(cmd *cobra.Command, applyAnnotation *bool)
- func AddDryRunFlag(cmd *cobra.Command)
- func AddFilenameOptionFlags(cmd *cobra.Command, options *resource.FilenameOptions, usage string)
- func AddGeneratorFlags(cmd *cobra.Command, defaultGenerator string)
- func AddIncludeUninitializedFlag(cmd *cobra.Command)
- func AddPodRunningTimeoutFlag(cmd *cobra.Command, defaultTimeout time.Duration)
- func AddSourceToErr(verb string, source string, err error) error
- func AddValidateFlags(cmd *cobra.Command)
- func AddValidateOptionFlags(cmd *cobra.Command, options *ValidateOptions)
- func AsDefaultVersionedOrOriginal(obj runtime.Object, mapping *meta.RESTMapping) runtime.Object
- func BehaviorOnFatal(f func(string, int))
- func CheckErr(err error)
- func Contains(resourcesList []*metav1.APIResourceList, resource schema.GroupVersionResource) bool
- func DefaultBehaviorOnFatal()
- func DefaultGenerators(cmdName string) map[string]kubectl.Generator
- func DefaultSubCommandRun(out io.Writer) func(c *cobra.Command, args []string)
- func DumpReaderToFile(reader io.Reader, filename string) error
- func FallbackGeneratorNameIfNecessary(generatorName string, discoveryClient discovery.DiscoveryInterface, ...) (string, error)
- func GetDryRunFlag(cmd *cobra.Command) bool
- func GetFirstPod(client coreclient.PodsGetter, namespace string, selector string, ...) (*api.Pod, int, 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 GetFlagInt32(cmd *cobra.Command, flag string) int32
- func GetFlagInt64(cmd *cobra.Command, flag string) int64
- func GetFlagString(cmd *cobra.Command, flag string) string
- func GetFlagStringArray(cmd *cobra.Command, flag string) []string
- func GetFlagStringSlice(cmd *cobra.Command, flag string) []string
- func GetPodRunningTimeoutFlag(cmd *cobra.Command) (time.Duration, error)
- func GetResourcesAndPairs(args []string, pairType string) (resources []string, pairArgs []string, err error)
- func GetWideFlag(cmd *cobra.Command) bool
- func HasResource(client discovery.DiscoveryInterface, resource schema.GroupVersionResource) (bool, error)
- func InternalVersionDecoder() runtime.Decoder
- func InternalVersionJSONEncoder() runtime.Encoder
- func IsFilenameSliceEmpty(filenames []string) bool
- func IsSiblingCommandExists(cmd *cobra.Command, targetCmdName string) bool
- func ManualStrip(file []byte) []byte
- func Merge(codec runtime.Codec, dst runtime.Object, fragment string) (runtime.Object, error)
- func MultilineError(prefix string, err error) string
- func MultipleErrors(prefix string, errs []error) string
- func ParsePairs(pairArgs []string, pairType string, supportRemove bool) (newPairs map[string]string, removePairs []string, err error)
- func PrintErrorWithCauses(err error, errOut io.Writer) bool
- func RequireNoArguments(c *cobra.Command, args []string)
- func ShouldIncludeUninitialized(cmd *cobra.Command, includeUninitialized bool) bool
- func StandardErrorMessage(err error) (string, bool)
- func StripComments(file []byte) []byte
- func SuggestApiResources(parent string) string
- func UsageErrorf(cmd *cobra.Command, format string, args ...interface{}) error
- func Warning(cmdErr io.Writer, newGeneratorName, oldGeneratorName string)
- type BuilderFactory
- type ClientAccessFactory
- type Factory
- type MatchVersionFlags
- func (f *MatchVersionFlags) AddFlags(flags *pflag.FlagSet)
- func (f *MatchVersionFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)
- func (f *MatchVersionFlags) ToRESTConfig() (*rest.Config, error)
- func (f *MatchVersionFlags) ToRESTMapper() (meta.RESTMapper, error)
- func (f *MatchVersionFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig
- type ObjectMappingFactory
- type RESTClientGetter
- type ValidateOptions
Constants ¶
const ( // TODO(sig-cli): Enforce consistent naming for generators here. // See discussion in https://github.com/kubernetes/kubernetes/issues/46237 // before you add any more. RunV1GeneratorName = "run/v1" RunPodV1GeneratorName = "run-pod/v1" ServiceV1GeneratorName = "service/v1" ServiceV2GeneratorName = "service/v2" ServiceNodePortGeneratorV1Name = "service-nodeport/v1" ServiceClusterIPGeneratorV1Name = "service-clusterip/v1" ServiceLoadBalancerGeneratorV1Name = "service-loadbalancer/v1" ServiceExternalNameGeneratorV1Name = "service-externalname/v1" ServiceAccountV1GeneratorName = "serviceaccount/v1" HorizontalPodAutoscalerV1GeneratorName = "horizontalpodautoscaler/v1" DeploymentV1Beta1GeneratorName = "deployment/v1beta1" DeploymentAppsV1Beta1GeneratorName = "deployment/apps.v1beta1" DeploymentBasicV1Beta1GeneratorName = "deployment-basic/v1beta1" DeploymentBasicAppsV1Beta1GeneratorName = "deployment-basic/apps.v1beta1" DeploymentBasicAppsV1GeneratorName = "deployment-basic/apps.v1" JobV1GeneratorName = "job/v1" CronJobV2Alpha1GeneratorName = "cronjob/v2alpha1" CronJobV1Beta1GeneratorName = "cronjob/v1beta1" NamespaceV1GeneratorName = "namespace/v1" ResourceQuotaV1GeneratorName = "resourcequotas/v1" SecretV1GeneratorName = "secret/v1" SecretForDockerRegistryV1GeneratorName = "secret-for-docker-registry/v1" SecretForTLSV1GeneratorName = "secret-for-tls/v1" ConfigMapV1GeneratorName = "configmap/v1" ClusterRoleBindingV1GeneratorName = "clusterrolebinding.rbac.authorization.k8s.io/v1alpha1" RoleBindingV1GeneratorName = "rolebinding.rbac.authorization.k8s.io/v1alpha1" ClusterV1Beta1GeneratorName = "cluster/v1beta1" PodDisruptionBudgetV1GeneratorName = "poddisruptionbudget/v1beta1" PodDisruptionBudgetV2GeneratorName = "poddisruptionbudget/v1beta1/v2" PriorityClassV1Alpha1GeneratorName = "priorityclass/v1alpha1" )
const ( ApplyAnnotationsFlag = "save-config" DefaultErrorExitCode = 1 IncludeUninitializedFlag = "include-uninitialized" )
Variables ¶
var ErrExit = fmt.Errorf("exit")
ErrExit may be passed to CheckError to instruct it to output nothing but exit with status code 1.
Functions ¶
func AddApplyAnnotationFlags ¶ added in v1.2.0
func AddApplyAnnotationVarFlags ¶ added in v1.7.0
func AddDryRunFlag ¶ added in v1.3.0
AddDryRunFlag adds dry-run flag to a command. Usually used by mutations.
func AddFilenameOptionFlags ¶ added in v1.5.0
func AddFilenameOptionFlags(cmd *cobra.Command, options *resource.FilenameOptions, usage string)
func AddGeneratorFlags ¶ added in v1.2.0
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 AddIncludeUninitializedFlag ¶ added in v1.8.0
func AddPodRunningTimeoutFlag ¶ added in v1.7.0
func AddSourceToErr ¶ added in v0.20.0
AddSourceToErr adds handleResourcePrefix and source string to error message. verb is the string like "creating", "deleting" etc. source is the filename or URL to the template file(*.json or *.yaml), or stdin to use to handle the resource.
func AddValidateFlags ¶ added in v1.1.0
func AddValidateOptionFlags ¶ added in v1.7.0
func AddValidateOptionFlags(cmd *cobra.Command, options *ValidateOptions)
func AsDefaultVersionedOrOriginal ¶
AsDefaultVersionedOrOriginal returns the object as a Go object in the external form if possible (matching the group version kind of the mapping if provided, a best guess based on serialization if not provided, or obj if it cannot be converted. TODO update call sites to specify the scheme they want on their builder.
func BehaviorOnFatal ¶ added in v1.1.0
BehaviorOnFatal allows you to override the default behavior when a fatal error occurs, which is to call os.Exit(code). You can pass 'panic' as a function here if you prefer the panic() over os.Exit(1).
func CheckErr ¶ added in v0.13.0
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 Contains ¶ added in v1.9.0
func Contains(resourcesList []*metav1.APIResourceList, resource schema.GroupVersionResource) bool
func DefaultBehaviorOnFatal ¶ added in v1.2.0
func DefaultBehaviorOnFatal()
DefaultBehaviorOnFatal allows you to undo any previous override. Useful in tests.
func DefaultGenerators ¶ added in v1.2.0
DefaultGenerators returns the set of default generators for use in Factory instances
func DefaultSubCommandRun ¶ added in v1.5.0
DefaultSubCommandRun prints a command's help string to the specified output if no arguments (sub-commands) are provided, or a usage error otherwise.
func DumpReaderToFile ¶ added in v1.1.0
DumpReaderToFile writes all data from the given io.Reader to the specified file (usually for temporary use).
func FallbackGeneratorNameIfNecessary ¶ added in v1.9.0
func FallbackGeneratorNameIfNecessary( generatorName string, discoveryClient discovery.DiscoveryInterface, cmdErr io.Writer, ) (string, error)
fallbackGeneratorNameIfNecessary returns the name of the old generator if server does not support new generator. Otherwise, the generator string is returned unchanged.
If the generator name is changed, print a warning message to let the user know.
func GetDryRunFlag ¶ added in v1.3.0
func GetFirstPod ¶ added in v1.2.0
func GetFirstPod(client coreclient.PodsGetter, namespace string, selector string, timeout time.Duration, sortBy func([]*v1.Pod) sort.Interface) (*api.Pod, int, error)
GetFirstPod returns a pod matching the namespace and label selector and the number of all pods that match the label selector.
func GetFlagInt ¶
Assumes the flag has a default value.
func GetFlagInt32 ¶ added in v1.9.0
Assumes the flag has a default value.
func GetFlagInt64 ¶ added in v1.1.0
Assumes the flag has a default value.
func GetFlagStringArray ¶ added in v1.5.0
GetFlagStringArray can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...)
func GetFlagStringSlice ¶ added in v1.1.0
GetFlagStringSlice can be used to accept multiple argument with flag repetition (e.g. -f arg1,arg2 -f arg3 ...)
func GetPodRunningTimeoutFlag ¶ added in v1.7.0
func GetResourcesAndPairs ¶ added in v1.3.0
func GetResourcesAndPairs(args []string, pairType string) (resources []string, pairArgs []string, err error)
GetResourcesAndPairs retrieves resources and "KEY=VALUE or KEY-" pair args from given args
func GetWideFlag ¶ added in v0.21.0
GetWideFlag is used to determine if "-o wide" is used
func HasResource ¶ added in v1.9.0
func HasResource(client discovery.DiscoveryInterface, resource schema.GroupVersionResource) (bool, error)
func InternalVersionDecoder ¶ added in v1.10.0
this method exists to help us find the points still relying on internal types.
func InternalVersionJSONEncoder ¶ added in v1.10.0
func IsFilenameSliceEmpty ¶ added in v1.8.0
func IsSiblingCommandExists ¶ added in v1.5.0
IsSiblingCommandExists receives a pointer to a cobra command and a target string. Returns true if the target string is found in the list of sibling commands.
func ManualStrip ¶ added in v1.7.0
ManualStrip is used for dropping comments from a YAML file
func Merge ¶
Merge requires JSON serialization TODO: merge assumes JSON serialization, and does not properly abstract API retrieval
func MultilineError ¶ added in v0.15.0
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 ¶ added in v0.18.0
MultipleErrors returns a newline delimited string containing the prefix and referenced errors in standard form.
func ParsePairs ¶ added in v1.3.0
func ParsePairs(pairArgs []string, pairType string, supportRemove bool) (newPairs map[string]string, removePairs []string, err error)
ParsePairs retrieves new and remove pairs (if supportRemove is true) from "KEY=VALUE or KEY-" pair args
func PrintErrorWithCauses ¶ added in v1.5.0
PrintErrorWithCauses prints an error's kind, name, and each of the error's causes in a new line. The returned string will end with a newline. Returns true if a case exists to handle the error type, or false otherwise.
func RequireNoArguments ¶ added in v1.5.0
RequireNoArguments exits with a usage error if extra arguments are provided.
func ShouldIncludeUninitialized ¶ added in v1.8.0
ShouldIncludeUninitialized identifies whether to include uninitialized objects. includeUninitialized is the default value. Assume we can parse `all` and `selector` from cmd.
func StandardErrorMessage ¶ added in v0.18.0
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 StripComments ¶ added in v1.7.0
StripComments will transform a YAML file into JSON, thus dropping any comments in it. Note that if the given file has a syntax error, the transformation will fail and we will manually drop all comments from the file.
func SuggestApiResources ¶
SuggestApiResources returns a suggestion to use the "api-resources" command to retrieve a supported list of resources
func UsageErrorf ¶ added in v1.8.0
Types ¶
type BuilderFactory ¶ added in v1.6.0
type BuilderFactory interface { // ScaleClient gives you back scale getter ScaleClient() (scaleclient.ScalesGetter, error) // Returns a Reaper for gracefully shutting down resources. Reaper(mapping *meta.RESTMapping) (kubectl.Reaper, error) }
BuilderFactory holds the third level of factory methods. These functions depend upon ObjectMappingFactory and ClientAccessFactory methods. Generally they depend upon client mapper functions
func NewBuilderFactory ¶ added in v1.6.0
func NewBuilderFactory(clientAccessFactory ClientAccessFactory, objectMappingFactory ObjectMappingFactory) BuilderFactory
type ClientAccessFactory ¶ added in v1.6.0
type ClientAccessFactory interface { // Returns a discovery client DiscoveryClient() (discovery.CachedDiscoveryInterface, error) // ClientSet gives you back an internal, generated clientset ClientSet() (internalclientset.Interface, error) // DynamicClient returns a dynamic client ready for use DynamicClient() (dynamic.Interface, error) // KubernetesClientSet gives you back an external clientset KubernetesClientSet() (*kubernetes.Clientset, error) // Returns interfaces for dealing with arbitrary runtime.Objects. RESTMapper() (meta.RESTMapper, error) // Returns a RESTClient for accessing Kubernetes resources or an error. RESTClient() (*restclient.RESTClient, error) // Returns a client.Config for accessing the Kubernetes server. ClientConfig() (*restclient.Config, error) // BareClientConfig returns a client.Config that has NOT been negotiated. It's // just directions to the server. People use this to build RESTMappers on top of BareClientConfig() (*restclient.Config, error) // NewBuilder returns an object that assists in loading objects from both disk and the server // and which implements the common patterns for CLI interactions with generic resources. NewBuilder() *resource.Builder // UpdatePodSpecForObject will call the provided function on the pod spec this object supports, // return false if no pod spec is supported, or return an error. UpdatePodSpecForObject(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error) // MapBasedSelectorForObject returns the map-based selector associated with the provided object. If a // new set-based selector is provided, an error is returned if the selector cannot be converted to a // map-based selector MapBasedSelectorForObject(object runtime.Object) (string, error) // PortsForObject returns the ports associated with the provided object PortsForObject(object runtime.Object) ([]string, error) // ProtocolsForObject returns the <port, protocol> mapping associated with the provided object ProtocolsForObject(object runtime.Object) (map[string]string, error) // LabelsForObject returns the labels associated with the provided object LabelsForObject(object runtime.Object) (map[string]string, error) // Command will stringify and return all environment arguments ie. a command run by a client // using the factory. Command(cmd *cobra.Command, showSecrets bool) string // SuggestedPodTemplateResources returns a list of resource types that declare a pod template SuggestedPodTemplateResources() []schema.GroupResource // Pauser marks the object in the info as paused. Currently supported only for Deployments. // Returns the patched object in bytes and any error that occurred during the encoding or // in case the object is already paused. Pauser(info *resource.Info) ([]byte, error) // Resumer resumes a paused object inside the info. Currently supported only for Deployments. // Returns the patched object in bytes and any error that occurred during the encoding or // in case the object is already resumed. Resumer(info *resource.Info) ([]byte, error) // ResolveImage resolves the image names. For kubernetes this function is just // passthrough but it allows to perform more sophisticated image name resolving for // third-party vendors. ResolveImage(imageName string) (string, error) // Returns the default namespace to use in cases where no // other namespace is specified and whether the namespace was // overridden. DefaultNamespace() (string, bool, error) // Generators returns the generators for the provided command Generators(cmdName string) map[string]kubectl.Generator // Check whether the kind of resources could be exposed CanBeExposed(kind schema.GroupKind) error // Check whether the kind of resources could be autoscaled CanBeAutoscaled(kind schema.GroupKind) error }
ClientAccessFactory holds the first level of factory methods. Generally provides discovery, negotiation, and no-dep calls. TODO The polymorphic calls probably deserve their own interface.
func NewClientAccessFactory ¶ added in v1.6.0
func NewClientAccessFactory(clientGetter RESTClientGetter) ClientAccessFactory
type Factory ¶ added in v0.15.0
type Factory interface { ClientAccessFactory ObjectMappingFactory BuilderFactory }
Factory provides abstractions that allow the Kubectl command to be extended across multiple types of resources and different API sets. The rings are here for a reason. In order for composers to be able to provide alternative factory implementations they need to provide low level pieces of *certain* functions so that when the factory calls back into itself it uses the custom version of the function. Rather than try to enumerate everything that someone would want to override we split the factory into rings, where each ring can depend on methods in an earlier ring, but cannot depend upon peer methods in its own ring. 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 ¶ added in v0.15.0
func NewFactory(clientGetter RESTClientGetter) Factory
NewFactory creates a factory with the default Kubernetes resources defined Receives a clientGetter capable of providing a discovery client and a REST client configuration.
type MatchVersionFlags ¶
type MatchVersionFlags struct { Delegate RESTClientGetter RequireMatchedServerVersion bool // contains filtered or unexported fields }
MatchVersionFlags is for setting the "match server version" function.
func NewMatchVersionFlags ¶
func NewMatchVersionFlags(delegate RESTClientGetter) *MatchVersionFlags
func (*MatchVersionFlags) AddFlags ¶
func (f *MatchVersionFlags) AddFlags(flags *pflag.FlagSet)
func (*MatchVersionFlags) ToDiscoveryClient ¶
func (f *MatchVersionFlags) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)
func (*MatchVersionFlags) ToRESTConfig ¶
func (f *MatchVersionFlags) ToRESTConfig() (*rest.Config, error)
ToRESTConfig implements RESTClientGetter. Returns a REST client configuration based on a provided path to a .kubeconfig file, loading rules, and config flag overrides. Expects the AddFlags method to have been called.
func (*MatchVersionFlags) ToRESTMapper ¶
func (f *MatchVersionFlags) ToRESTMapper() (meta.RESTMapper, error)
RESTMapper returns a mapper.
func (*MatchVersionFlags) ToRawKubeConfigLoader ¶
func (f *MatchVersionFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig
type ObjectMappingFactory ¶ added in v1.6.0
type ObjectMappingFactory interface { // 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. ClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) // Returns a RESTClient for working with Unstructured objects. UnstructuredClientForMapping(mapping *meta.RESTMapping) (resource.RESTClient, error) // Returns a Describer for displaying the specified RESTMapping type or an error. Describer(mapping *meta.RESTMapping) (printers.Describer, error) // LogsForObject returns a request for the logs associated with the provided object LogsForObject(object, options runtime.Object, timeout time.Duration) (*restclient.Request, error) // Returns a HistoryViewer for viewing change history HistoryViewer(mapping *meta.RESTMapping) (kubectl.HistoryViewer, error) // Returns a Rollbacker for changing the rollback version of the specified RESTMapping type or an error Rollbacker(mapping *meta.RESTMapping) (kubectl.Rollbacker, error) // Returns a StatusViewer for printing rollout status. StatusViewer(mapping *meta.RESTMapping) (kubectl.StatusViewer, error) // AttachablePodForObject returns the pod to which to attach given an object. AttachablePodForObject(object runtime.Object, timeout time.Duration) (*api.Pod, error) // ApproximatePodTemplateForObject returns a pod template object for the provided source. // It may return both an error and a object. It attempt to return the best possible template // available at the current time. ApproximatePodTemplateForObject(runtime.Object) (*api.PodTemplateSpec, error) // Returns a schema that can validate objects stored on disk. Validator(validate bool) (validation.Schema, error) // OpenAPISchema returns the schema openapi schema definition OpenAPISchema() (openapi.Resources, error) }
ObjectMappingFactory holds the second level of factory methods. These functions depend upon ClientAccessFactory methods. Generally they provide object typing and functions that build requests based on the negotiated clients.
func NewObjectMappingFactory ¶ added in v1.6.0
func NewObjectMappingFactory(clientAccessFactory ClientAccessFactory) ObjectMappingFactory
type RESTClientGetter ¶
type RESTClientGetter interface { ToRESTConfig() (*restclient.Config, error) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) ToRESTMapper() (meta.RESTMapper, error) ToRawKubeConfigLoader() clientcmd.ClientConfig }
type ValidateOptions ¶ added in v1.7.0
type ValidateOptions struct {
EnableValidation bool
}
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package env provides functions to incorporate environment variables into kubectl commands.
|
Package env provides functions to incorporate environment variables into kubectl commands. |
Package openapi is a collection of libraries for fetching the openapi spec from a Kubernetes server and then indexing the type definitions.
|
Package openapi is a collection of libraries for fetching the openapi spec from a Kubernetes server and then indexing the type definitions. |