Documentation ¶
Index ¶
- Constants
- Variables
- func AddApplyAnnotationFlags(cmd *cobra.Command)
- func AddApplyAnnotationVarFlags(cmd *cobra.Command, applyAnnotation *bool)
- func AddChunkSizeFlag(cmd *cobra.Command, value *int64)
- func AddContainerVarFlags(cmd *cobra.Command, p *string, containerName string)
- func AddDryRunFlag(cmd *cobra.Command)
- func AddFieldManagerFlagVar(cmd *cobra.Command, p *string, defaultFieldManager string)
- func AddFilenameOptionFlags(cmd *cobra.Command, options *resource.FilenameOptions, usage string)
- func AddFromEnvFile(filePath string, addTo func(key, value string) error) error
- func AddJsonFilenameFlag(flags *pflag.FlagSet, value *[]string, usage string)
- func AddKustomizeFlag(flags *pflag.FlagSet, value *string)
- func AddLabelSelectorFlagVar(cmd *cobra.Command, p *string)
- func AddPodRunningTimeoutFlag(cmd *cobra.Command, defaultTimeout time.Duration)
- func AddPruningFlags(cmd *cobra.Command, prune *bool, pruneAllowlist *[]string, ...)
- func AddServerSideApplyFlags(cmd *cobra.Command)
- func AddSourceToErr(verb string, source string, err error) error
- func AddSubresourceFlags(cmd *cobra.Command, subresource *string, usage string, ...)
- func AddValidateFlags(cmd *cobra.Command)
- func BehaviorOnFatal(f func(string, int))
- func CheckDiffErr(err error)
- func CheckErr(err error)
- func DefaultBehaviorOnFatal()
- func DefaultSubCommandRun(out io.Writer) func(c *cobra.Command, args []string)
- func Difference(fullArray []string, subArray []string) []string
- func DumpReaderToFile(reader io.Reader, filename string) error
- func GetFieldManagerFlag(cmd *cobra.Command) string
- 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 GetForceConflictsFlag(cmd *cobra.Command) bool
- func GetPodRunningTimeoutFlag(cmd *cobra.Command) (time.Duration, error)
- func GetResourcesAndPairs(args []string, pairType string) (resources []string, pairArgs []string, err error)
- func GetServerSideApplyFlag(cmd *cobra.Command) bool
- func GetValidationDirective(cmd *cobra.Command) (string, error)
- func IsFilenameSliceEmpty(filenames []string, directory string) bool
- func IsSiblingCommandExists(cmd *cobra.Command, targetCmdName string) bool
- func JSONPatch(codec runtime.Codec, dst runtime.Object, fragment string) (runtime.Object, error)
- 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 PrintFlagsWithDryRunStrategy(printFlags *genericclioptions.PrintFlags, dryRunStrategy DryRunStrategy) *genericclioptions.PrintFlags
- func RequireNoArguments(c *cobra.Command, args []string)
- func StandardErrorMessage(err error) (string, bool)
- func StrategicMerge(codec runtime.Codec, dst runtime.Object, fragment string, ...) (runtime.Object, error)
- 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 DryRunStrategy
- type Factory
- type FeatureGate
- 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 OverrideOptions
- type OverrideType
- type Overrider
- type ScaleClientFunc
- type ValidateOptions
Constants ¶
const ( ApplyAnnotationsFlag = "save-config" DefaultErrorExitCode = 1 DefaultChunkSize = 500 )
const DefaultOverrideType = OverrideTypeMerge
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 ¶
func AddChunkSizeFlag ¶ added in v0.22.0
func AddContainerVarFlags ¶ added in v0.21.0
func AddDryRunFlag ¶
AddDryRunFlag adds dry-run flag to a command. Usually used by mutations.
func AddFieldManagerFlagVar ¶ added in v0.19.0
func AddFilenameOptionFlags ¶
func AddFilenameOptionFlags(cmd *cobra.Command, options *resource.FilenameOptions, usage string)
func AddFromEnvFile ¶ added in v0.21.0
AddFromEnvFile processes an env file allows a generic addTo to handle the collection of key value pairs or returns an error.
func AddJsonFilenameFlag ¶
func AddKustomizeFlag ¶
AddKustomizeFlag adds kustomize flag to a command
func AddLabelSelectorFlagVar ¶ added in v0.24.0
func AddPruningFlags ¶ added in v0.27.0
func AddServerSideApplyFlags ¶
func AddSourceToErr ¶
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 AddSubresourceFlags ¶ added in v0.24.0
func AddValidateFlags ¶
func BehaviorOnFatal ¶
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 CheckDiffErr ¶ added in v0.18.0
func CheckDiffErr(err error)
CheckDiffErr prints a user friendly error to STDERR and exits with a non-zero and non-one exit code. Unrecognized errors will be printed with an "error: " prefix.
This method is meant specifically for `kubectl diff` and may be used by other commands.
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 DefaultBehaviorOnFatal ¶
func DefaultBehaviorOnFatal()
DefaultBehaviorOnFatal allows you to undo any previous override. Useful in tests.
func DefaultSubCommandRun ¶
DefaultSubCommandRun prints a command's help string to the specified output if no arguments (sub-commands) are provided, or a usage error otherwise.
func Difference ¶ added in v0.23.0
Difference removes any elements of subArray from fullArray and returns the result
func DumpReaderToFile ¶
DumpReaderToFile writes all data from the given io.Reader to the specified file (usually for temporary use).
func GetFieldManagerFlag ¶
func GetFlagInt ¶
Assumes the flag has a default value.
func GetFlagInt32 ¶
Assumes the flag has a default value.
func GetFlagInt64 ¶
Assumes the flag has a default value.
func GetFlagStringArray ¶
GetFlagStringArray can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...)
func GetFlagStringSlice ¶
GetFlagStringSlice can be used to accept multiple argument with flag repetition (e.g. -f arg1,arg2 -f arg3 ...)
func GetForceConflictsFlag ¶
func GetResourcesAndPairs ¶
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 GetServerSideApplyFlag ¶
func GetValidationDirective ¶ added in v0.24.0
func IsFilenameSliceEmpty ¶
func IsSiblingCommandExists ¶
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 JSONPatch ¶ added in v0.23.0
JSONPatch converts the passed in object to JSON, performs an RFC6902 JSON Patch using operations specified in the fragment, and returns the resulting object
func ManualStrip ¶
ManualStrip is used for dropping comments from a YAML file
func Merge ¶
Merge converts the passed in object to JSON, merges the fragment into it using an RFC7396 JSON Merge Patch, and returns the resulting object TODO: merge assumes JSON serialization, and does not properly abstract API retrieval
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 ParsePairs ¶
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 ¶
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 PrintFlagsWithDryRunStrategy ¶ added in v0.18.0
func PrintFlagsWithDryRunStrategy(printFlags *genericclioptions.PrintFlags, dryRunStrategy DryRunStrategy) *genericclioptions.PrintFlags
PrintFlagsWithDryRunStrategy sets a success message at print time for the dry run strategy
TODO(juanvallejo): This can be cleaned up even further by creating a PrintFlags struct that binds the --dry-run flag, and whose ToPrinter method returns a printer that understands how to print this success message.
func RequireNoArguments ¶
RequireNoArguments exits with a usage error if extra arguments are provided.
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 klog.
This method is generic to the command in use and may be used by non-Kubectl commands.
func StrategicMerge ¶ added in v0.23.0
func StrategicMerge(codec runtime.Codec, dst runtime.Object, fragment string, dataStruct runtime.Object) (runtime.Object, error)
StrategicMerge converts the passed in object to JSON, merges the fragment into it using a Strategic Merge Patch, and returns the resulting object
func StripComments ¶
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
Types ¶
type DryRunStrategy ¶ added in v0.18.0
type DryRunStrategy int
const ( // DryRunNone indicates the client will make all mutating calls DryRunNone DryRunStrategy = iota // DryRunClient, or client-side dry-run, indicates the client will prevent // making mutating calls such as CREATE, PATCH, and DELETE DryRunClient // DryRunServer, or server-side dry-run, indicates the client will send // mutating calls to the APIServer with the dry-run parameter to prevent // persisting changes. // // Note that clients sending server-side dry-run calls should verify that // the APIServer and the resource supports server-side dry-run, and otherwise // clients should fail early. // // If a client sends a server-side dry-run call to an APIServer that doesn't // support server-side dry-run, then the APIServer will persist changes inadvertently. DryRunServer )
func GetDryRunStrategy ¶ added in v0.18.0
func GetDryRunStrategy(cmd *cobra.Command) (DryRunStrategy, error)
type Factory ¶
type Factory interface { genericclioptions.RESTClientGetter // DynamicClient returns a dynamic client ready for use DynamicClient() (dynamic.Interface, error) // KubernetesClientSet gives you back an external clientset KubernetesClientSet() (*kubernetes.Clientset, error) // Returns a RESTClient for accessing Kubernetes resources or an error. RESTClient() (*restclient.RESTClient, 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 // 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 schema that can validate objects stored on disk. Validator(validationDirective string) (validation.Schema, error) // Used for retrieving openapi v2 resources. openapi.OpenAPIResourcesGetter // OpenAPIV3Schema returns a client for fetching parsed schemas for // any group version OpenAPIV3Client() (openapiclient.Client, error) }
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 ¶
func NewFactory(clientGetter genericclioptions.RESTClientGetter) Factory
type FeatureGate ¶ added in v0.27.0
type FeatureGate string
const ( ApplySet FeatureGate = "KUBECTL_APPLYSET" CmdPluginAsSubcommand FeatureGate = "KUBECTL_ENABLE_CMD_SHADOW" InteractiveDelete FeatureGate = "KUBECTL_INTERACTIVE_DELETE" OpenAPIV3Patch FeatureGate = "KUBECTL_OPENAPIV3_PATCH" RemoteCommandWebsockets FeatureGate = "KUBECTL_REMOTE_COMMAND_WEBSOCKETS" )
func (FeatureGate) IsDisabled ¶ added in v0.29.0
func (f FeatureGate) IsDisabled() bool
IsDisabled returns true iff environment variable is set to false. All other cases, it returns true. This function is used for the cases where feature is enabled by default, but it may be needed to provide a way to ability to disable this feature.
func (FeatureGate) IsEnabled ¶ added in v0.27.0
func (f FeatureGate) IsEnabled() bool
IsEnabled returns true iff environment variable is set to true. All other cases, it returns false.
type MatchVersionFlags ¶
type MatchVersionFlags struct { Delegate genericclioptions.RESTClientGetter RequireMatchedServerVersion bool // contains filtered or unexported fields }
MatchVersionFlags is for setting the "match server version" function.
func NewMatchVersionFlags ¶
func NewMatchVersionFlags(delegate genericclioptions.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)
ToRESTMapper returns a mapper.
func (*MatchVersionFlags) ToRawKubeConfigLoader ¶
func (f *MatchVersionFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig
type OverrideOptions ¶ added in v0.23.0
type OverrideOptions struct { Overrides string OverrideType OverrideType }
func (*OverrideOptions) AddOverrideFlags ¶ added in v0.23.0
func (o *OverrideOptions) AddOverrideFlags(cmd *cobra.Command)
func (*OverrideOptions) NewOverrider ¶ added in v0.23.0
func (o *OverrideOptions) NewOverrider(dataStruct runtime.Object) *Overrider
type OverrideType ¶ added in v0.23.0
type OverrideType string
const ( // OverrideTypeJSON will use an RFC6902 JSON Patch to alter the generated output OverrideTypeJSON OverrideType = "json" // OverrideTypeMerge will use an RFC7396 JSON Merge Patch to alter the generated output OverrideTypeMerge OverrideType = "merge" // OverrideTypeStrategic will use a Strategic Merge Patch to alter the generated output OverrideTypeStrategic OverrideType = "strategic" )
type Overrider ¶ added in v0.23.0
type Overrider struct { Options *OverrideOptions DataStruct runtime.Object }
type ScaleClientFunc ¶
type ScaleClientFunc func(genericclioptions.RESTClientGetter) (scale.ScalesGetter, error)
ScaleClientFunc provides a ScalesGetter
var ScaleClientFn ScaleClientFunc = scaleClient
ScaleClientFn gives a way to easily override the function for unit testing if needed.
type ValidateOptions ¶
type ValidateOptions struct {
ValidationDirective string
}