const ApplyAnnotationsFlag … const DefaultErrorExitCode … const DefaultChunkSize … type debugError … // 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 AddSourceToErr(verb string, source string, err error) error { … } var fatalErrHandler … // 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 BehaviorOnFatal(f func(string, int)) { … } // DefaultBehaviorOnFatal allows you to undo any previous override. Useful in // tests. func DefaultBehaviorOnFatal() { … } // fatal prints the message (if provided) and then exits. If V(99) or greater, // klog.Fatal is invoked for extended information. This is intended for maintainer // debugging and out of a reasonable range for users. func fatal(msg string, code int) { … } var ErrExit … // 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 CheckErr(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 CheckDiffErr(err error) { … } // isInvalidReasonStatusError returns true if this is an API Status error with reason=Invalid. // This is distinct from generic 422 errors we want to fall back to generic error handling. func isInvalidReasonStatusError(err error) bool { … } // checkErr formats a given error as a string and calls the passed handleErr // func with that string and an kubectl exit code. func checkErr(err error, handleErr func(string, int)) { … } func statusCausesToAggrError(scs []metav1.StatusCause) utilerrors.Aggregate { … } // 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 StandardErrorMessage(err error) (string, bool) { … } // MultilineError returns a string representing an error that splits sub errors into their own // lines. The returned string will end with a newline. func MultilineError(prefix string, err error) string { … } // 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 PrintErrorWithCauses(err error, errOut io.Writer) bool { … } // MultipleErrors returns a newline delimited string containing // the prefix and referenced errors in standard form. func MultipleErrors(prefix string, errs []error) string { … } // messageForError returns the string representing the error. func messageForError(err error) string { … } func UsageErrorf(cmd *cobra.Command, format string, args ...interface{ … } func IsFilenameSliceEmpty(filenames []string, directory string) bool { … } func GetFlagString(cmd *cobra.Command, flag string) string { … } // GetFlagStringSlice can be used to accept multiple argument with flag repetition (e.g. -f arg1,arg2 -f arg3 ...) func GetFlagStringSlice(cmd *cobra.Command, flag string) []string { … } // GetFlagStringArray can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...) func GetFlagStringArray(cmd *cobra.Command, flag string) []string { … } func GetFlagBool(cmd *cobra.Command, flag string) bool { … } // Assumes the flag has a default value. func GetFlagInt(cmd *cobra.Command, flag string) int { … } // Assumes the flag has a default value. func GetFlagInt32(cmd *cobra.Command, flag string) int32 { … } // Assumes the flag has a default value. func GetFlagInt64(cmd *cobra.Command, flag string) int64 { … } func GetFlagDuration(cmd *cobra.Command, flag string) time.Duration { … } func GetPodRunningTimeoutFlag(cmd *cobra.Command) (time.Duration, error) { … } type FeatureGate … const ApplySet … const CmdPluginAsSubcommand … const OpenAPIV3Patch … const RemoteCommandWebsockets … const PortForwardWebsockets … const DebugCustomProfile … // IsEnabled returns true iff environment variable is set to true. // All other cases, it returns false. func (f FeatureGate) IsEnabled() 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 (f FeatureGate) IsDisabled() bool { … } func AddValidateFlags(cmd *cobra.Command) { … } func AddFilenameOptionFlags(cmd *cobra.Command, options *resource.FilenameOptions, usage string) { … } func AddJsonFilenameFlag(flags *pflag.FlagSet, value *[]string, usage string) { … } // AddKustomizeFlag adds kustomize flag to a command func AddKustomizeFlag(flags *pflag.FlagSet, value *string) { … } // AddDryRunFlag adds dry-run flag to a command. Usually used by mutations. func AddDryRunFlag(cmd *cobra.Command) { … } func AddFieldManagerFlagVar(cmd *cobra.Command, p *string, defaultFieldManager string) { … } func AddContainerVarFlags(cmd *cobra.Command, p *string, containerName string) { … } func AddServerSideApplyFlags(cmd *cobra.Command) { … } func AddPodRunningTimeoutFlag(cmd *cobra.Command, defaultTimeout time.Duration) { … } func AddApplyAnnotationFlags(cmd *cobra.Command) { … } func AddApplyAnnotationVarFlags(cmd *cobra.Command, applyAnnotation *bool) { … } func AddChunkSizeFlag(cmd *cobra.Command, value *int64) { … } func AddLabelSelectorFlagVar(cmd *cobra.Command, p *string) { … } func AddPruningFlags(cmd *cobra.Command, prune *bool, pruneAllowlist *[]string, all *bool, applySetRef *string) { … } func AddSubresourceFlags(cmd *cobra.Command, subresource *string, usage string, allowedSubresources ...string) { … } type ValidateOptions … // 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 Merge(codec runtime.Codec, dst runtime.Object, fragment string) (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 StrategicMerge(codec runtime.Codec, dst runtime.Object, fragment string, dataStruct runtime.Object) (runtime.Object, error) { … } // 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 JSONPatch(codec runtime.Codec, dst runtime.Object, fragment string) (runtime.Object, error) { … } // DumpReaderToFile writes all data from the given io.Reader to the specified file // (usually for temporary use). func DumpReaderToFile(reader io.Reader, filename string) error { … } func GetServerSideApplyFlag(cmd *cobra.Command) bool { … } func GetForceConflictsFlag(cmd *cobra.Command) bool { … } func GetFieldManagerFlag(cmd *cobra.Command) string { … } func GetValidationDirective(cmd *cobra.Command) (string, error) { … } type DryRunStrategy … const DryRunNone … const DryRunClient … const DryRunServer … func GetDryRunStrategy(cmd *cobra.Command) (DryRunStrategy, error) { … } // 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 PrintFlagsWithDryRunStrategy(printFlags *genericclioptions.PrintFlags, dryRunStrategy DryRunStrategy) *genericclioptions.PrintFlags { … } // GetResourcesAndPairs retrieves resources and "KEY=VALUE or KEY-" pair args from given args func GetResourcesAndPairs(args []string, pairType string) (resources []string, pairArgs []string, err error) { … } // ParsePairs retrieves new and remove pairs (if supportRemove is true) from "KEY=VALUE or KEY-" pair args func ParsePairs(pairArgs []string, pairType string, supportRemove bool) (newPairs map[string]string, removePairs []string, err error) { … } // 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 IsSiblingCommandExists(cmd *cobra.Command, targetCmdName string) bool { … } // DefaultSubCommandRun prints a command's help string to the specified output if no // arguments (sub-commands) are provided, or a usage error otherwise. func DefaultSubCommandRun(out io.Writer) func(c *cobra.Command, args []string) { … } // RequireNoArguments exits with a usage error if extra arguments are provided. func RequireNoArguments(c *cobra.Command, args []string) { … } // 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 StripComments(file []byte) []byte { … } // ManualStrip is used for dropping comments from a YAML file func ManualStrip(file []byte) []byte { … } type ScaleClientFunc … var ScaleClientFn … // scaleClient gives you back scale getter func scaleClient(restClientGetter genericclioptions.RESTClientGetter) (scale.ScalesGetter, error) { … } func Warning(cmdErr io.Writer, newGeneratorName, oldGeneratorName string) { … } // Difference removes any elements of subArray from fullArray and returns the result func Difference(fullArray []string, subArray []string) []string { … }