From 13d5d5066069376d8b92ef79cff09ba6d79b19e8 Mon Sep 17 00:00:00 2001 From: xiongzhongliang Date: Wed, 23 Dec 2020 00:03:48 +0800 Subject: [PATCH] fix kubectl label error when local=true is set. fix kubectl label error when local=true is set. fix kubectl label error when local=true is set. Kubernetes-commit: cb7009a63bbc90569493f070463ae6715088d46a --- pkg/cmd/label/label.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/label/label.go b/pkg/cmd/label/label.go index 4c6c77df..1b2cbded 100644 --- a/pkg/cmd/label/label.go +++ b/pkg/cmd/label/label.go @@ -213,17 +213,26 @@ func (o *LabelOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st // Validate checks to the LabelOptions to see if there is sufficient information run the command. func (o *LabelOptions) Validate() error { - if o.local && o.dryRunStrategy == cmdutil.DryRunServer { - return fmt.Errorf("cannot specify --local and --dry-run=server - did you mean --dry-run=client?") - } if o.all && len(o.selector) > 0 { return fmt.Errorf("cannot set --all and --selector at the same time") } if o.all && len(o.fieldSelector) > 0 { return fmt.Errorf("cannot set --all and --field-selector at the same time") } - if len(o.resources) < 1 && cmdutil.IsFilenameSliceEmpty(o.FilenameOptions.Filenames, o.FilenameOptions.Kustomize) { - return fmt.Errorf("one or more resources must be specified as or /") + if o.local { + if o.dryRunStrategy == cmdutil.DryRunServer { + return fmt.Errorf("cannot specify --local and --dry-run=server - did you mean --dry-run=client?") + } + if len(o.resources) > 0 { + return fmt.Errorf("can only use local files by -f pod.yaml or --filename=pod.json when --local=true is set") + } + if cmdutil.IsFilenameSliceEmpty(o.FilenameOptions.Filenames, o.FilenameOptions.Kustomize) { + return fmt.Errorf("one or more files must be specified as -f pod.yaml or --filename=pod.json") + } + } else { + if len(o.resources) < 1 && cmdutil.IsFilenameSliceEmpty(o.FilenameOptions.Filenames, o.FilenameOptions.Kustomize) { + return fmt.Errorf("one or more resources must be specified as or /") + } } if len(o.newLabels) < 1 && len(o.removeLabels) < 1 && !o.list { return fmt.Errorf("at least one label update is required")