diff --git a/contrib/completions/bash/oc b/contrib/completions/bash/oc index e3e0027d878d..71a8edf2b139 100644 --- a/contrib/completions/bash/oc +++ b/contrib/completions/bash/oc @@ -6835,6 +6835,8 @@ _oc_apply_edit-last-applied() flags_with_completion=() flags_completion=() + flags+=("--allow-missing-template-keys") + local_nonpersistent_flags+=("--allow-missing-template-keys") flags+=("--filename=") flags_with_completion+=("--filename") flags_completion+=("__oc_handle_filename_extension_flag json|yaml|yml") @@ -6852,6 +6854,10 @@ _oc_apply_edit-last-applied() flags+=("--recursive") flags+=("-R") local_nonpersistent_flags+=("--recursive") + flags+=("--template=") + flags_with_completion+=("--template") + flags_completion+=("_filedir") + local_nonpersistent_flags+=("--template=") flags+=("--windows-line-endings") local_nonpersistent_flags+=("--windows-line-endings") flags+=("--as=") diff --git a/contrib/completions/zsh/oc b/contrib/completions/zsh/oc index 0bd90fc59af6..26c16b8bc396 100644 --- a/contrib/completions/zsh/oc +++ b/contrib/completions/zsh/oc @@ -6977,6 +6977,8 @@ _oc_apply_edit-last-applied() flags_with_completion=() flags_completion=() + flags+=("--allow-missing-template-keys") + local_nonpersistent_flags+=("--allow-missing-template-keys") flags+=("--filename=") flags_with_completion+=("--filename") flags_completion+=("__oc_handle_filename_extension_flag json|yaml|yml") @@ -6994,6 +6996,10 @@ _oc_apply_edit-last-applied() flags+=("--recursive") flags+=("-R") local_nonpersistent_flags+=("--recursive") + flags+=("--template=") + flags_with_completion+=("--template") + flags_completion+=("_filedir") + local_nonpersistent_flags+=("--template=") flags+=("--windows-line-endings") local_nonpersistent_flags+=("--windows-line-endings") flags+=("--as=") diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/apply_edit_last_applied.go b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/apply_edit_last_applied.go index e4700989ce9c..585998bf4140 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/apply_edit_last_applied.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/apply_edit_last_applied.go @@ -76,10 +76,10 @@ func NewCmdApplyEditLastApplied(f cmdutil.Factory, ioStreams genericclioptions.I // bind flag structs o.RecordFlags.AddFlags(cmd) + o.PrintFlags.AddFlags(cmd) usage := "to use to edit the resource" cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, usage) - cmd.Flags().StringVarP(&o.Output, "output", "o", o.Output, "Output format. One of: yaml|json.") cmd.Flags().BoolVar(&o.WindowsLineEndings, "windows-line-endings", o.WindowsLineEndings, "Defaults to the line ending native to your platform.") cmdutil.AddIncludeUninitializedFlag(cmd) diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/create/create.go b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/create/create.go index a6bb8b03b8e5..e72b6d0796ab 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/create/create.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/create/create.go @@ -209,7 +209,7 @@ func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error { } if o.EditBeforeCreate { - return RunEditOnCreate(f, o.RecordFlags, o.IOStreams, cmd, &o.FilenameOptions) + return RunEditOnCreate(f, o.PrintFlags, o.RecordFlags, o.IOStreams, cmd, &o.FilenameOptions) } schema, err := f.Validator(cmdutil.GetFlagBool(cmd, "validate")) if err != nil { @@ -298,13 +298,13 @@ func (o *CreateOptions) raw(f cmdutil.Factory) error { return nil } -func RunEditOnCreate(f cmdutil.Factory, recordFlags *genericclioptions.RecordFlags, ioStreams genericclioptions.IOStreams, cmd *cobra.Command, options *resource.FilenameOptions) error { +func RunEditOnCreate(f cmdutil.Factory, printFlags *genericclioptions.PrintFlags, recordFlags *genericclioptions.RecordFlags, ioStreams genericclioptions.IOStreams, cmd *cobra.Command, options *resource.FilenameOptions) error { editOptions := editor.NewEditOptions(editor.EditBeforeCreateMode, ioStreams) editOptions.FilenameOptions = *options editOptions.ValidateOptions = cmdutil.ValidateOptions{ EnableValidation: cmdutil.GetFlagBool(cmd, "validate"), } - editOptions.Output = cmdutil.GetFlagString(cmd, "output") + editOptions.PrintFlags = printFlags editOptions.ApplyAnnotation = cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag) editOptions.RecordFlags = recordFlags diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied/test.yaml b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied/test.yaml index 73d8fd98b25d..106bfb963c44 100755 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied/test.yaml +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/testdata/edit/testcase-apply-edit-last-applied/test.yaml @@ -6,7 +6,7 @@ args: outputFormat: yaml namespace: myproject expectedStdout: -- service/svc1 edited +- 'targetPort: 92' expectedExitCode: 0 steps: - type: request diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/editor/editoptions.go b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/editor/editoptions.go index 43b826126843..73c2aac8fd55 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/editor/editoptions.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/editor/editoptions.go @@ -61,7 +61,6 @@ type EditOptions struct { PrintFlags *genericclioptions.PrintFlags ToPrinter func(string) (printers.ResourcePrinter, error) - Output string OutputPatch bool WindowsLineEndings bool @@ -91,19 +90,56 @@ func NewEditOptions(editMode EditMode, ioStreams genericclioptions.IOStreams) *E PrintFlags: genericclioptions.NewPrintFlags("edited").WithTypeSetter(scheme.Scheme), + editPrinterOptions: &editPrinterOptions{ + // create new editor-specific PrintFlags, with all + // output flags disabled, except json / yaml + printFlags: (&genericclioptions.PrintFlags{ + JSONYamlPrintFlags: genericclioptions.NewJSONYamlPrintFlags(), + }).WithDefaultOutput("yaml"), + ext: ".yaml", + addHeader: true, + }, + WindowsLineEndings: goruntime.GOOS == "windows", Recorder: genericclioptions.NoopRecorder{}, IOStreams: ioStreams, - Output: "yaml", } } type editPrinterOptions struct { - printer printers.ResourcePrinter - ext string - addHeader bool + printFlags *genericclioptions.PrintFlags + ext string + addHeader bool +} + +func (e *editPrinterOptions) Complete(fromPrintFlags *genericclioptions.PrintFlags) error { + if e.printFlags == nil { + return fmt.Errorf("missing PrintFlags in editor printer options") + } + // bind output format from existing printflags + if fromPrintFlags != nil && len(*fromPrintFlags.OutputFormat) > 0 { + e.printFlags.OutputFormat = fromPrintFlags.OutputFormat + } + // prevent a commented header at the top of the user's + // default editor if presenting contents as json. + if *e.printFlags.OutputFormat == "json" { + e.addHeader = false + e.ext = ".json" + return nil + } + // we default to yaml if check above is false, as only json or yaml are supported + e.addHeader = true + e.ext = ".yaml" + return nil +} +func (e *editPrinterOptions) PrintObj(obj runtime.Object, out io.Writer) error { + p, err := e.printFlags.ToPrinter() + if err != nil { + return err + } + return p.PrintObj(obj, out) } // Complete completes all the required options @@ -119,12 +155,8 @@ func (o *EditOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Comm if o.EditMode != NormalEditMode && o.EditMode != EditBeforeCreateMode && o.EditMode != ApplyEditMode { return fmt.Errorf("unsupported edit mode %q", o.EditMode) } - if o.Output != "" { - if o.Output != "yaml" && o.Output != "json" { - return fmt.Errorf("invalid output format %s, only yaml|json supported", o.Output) - } - } - o.editPrinterOptions = getPrinter(o.Output) + + o.editPrinterOptions.Complete(o.PrintFlags) if o.OutputPatch && o.EditMode != NormalEditMode { return fmt.Errorf("the edit mode doesn't support output the patch") @@ -226,7 +258,7 @@ func (o *EditOptions) Run() error { } if !containsError { - if err := o.editPrinterOptions.printer.PrintObj(originalObj, w); err != nil { + if err := o.editPrinterOptions.PrintObj(originalObj, w); err != nil { return preservedFile(err, results.file, o.ErrOut) } original = buf.Bytes() @@ -510,30 +542,6 @@ func encodeToJson(obj runtime.Unstructured) ([]byte, error) { return js, nil } -func getPrinter(format string) *editPrinterOptions { - switch format { - case "json": - return &editPrinterOptions{ - printer: &printers.JSONPrinter{}, - ext: ".json", - addHeader: false, - } - case "yaml": - return &editPrinterOptions{ - printer: &printers.YAMLPrinter{}, - ext: ".yaml", - addHeader: true, - } - default: - // if format is not specified, use yaml as default - return &editPrinterOptions{ - printer: &printers.YAMLPrinter{}, - ext: ".yaml", - addHeader: true, - } - } -} - func (o *EditOptions) visitToPatch(originalInfos []*resource.Info, patchVisitor resource.Visitor, results *editResults) error { err := patchVisitor.Visit(func(info *resource.Info, incomingErr error) error { editObjUID, err := meta.NewAccessor().UID(info.Object) diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/genericclioptions/json_yaml_flags.go b/vendor/k8s.io/kubernetes/pkg/kubectl/genericclioptions/json_yaml_flags.go index 8205f5191d14..f133dd399abc 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/genericclioptions/json_yaml_flags.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/genericclioptions/json_yaml_flags.go @@ -25,6 +25,9 @@ import ( ) func (f *JSONYamlPrintFlags) AllowedFormats() []string { + if f == nil { + return []string{} + } return []string{"json", "yaml"} } diff --git a/vendor/k8s.io/kubernetes/pkg/kubectl/genericclioptions/name_flags.go b/vendor/k8s.io/kubernetes/pkg/kubectl/genericclioptions/name_flags.go index 13c714554f87..8da378f391fb 100644 --- a/vendor/k8s.io/kubernetes/pkg/kubectl/genericclioptions/name_flags.go +++ b/vendor/k8s.io/kubernetes/pkg/kubectl/genericclioptions/name_flags.go @@ -41,6 +41,9 @@ func (f *NamePrintFlags) Complete(successTemplate string) error { } func (f *NamePrintFlags) AllowedFormats() []string { + if f == nil { + return []string{} + } return []string{"name"} }