From 9c04919f3b1a3f524f72cb221f1df2dc46e16f77 Mon Sep 17 00:00:00 2001 From: "Julian V. Modesto" Date: Thu, 13 Feb 2020 16:44:14 -0500 Subject: [PATCH] Error if --local and --dry-run=server are passed Kubernetes-commit: 5fcd9c7c7ec432dd27e770e49e0e6872335c765d --- pkg/cmd/annotate/annotate.go | 3 +++ pkg/cmd/label/label.go | 3 +++ pkg/cmd/patch/patch.go | 3 +++ pkg/cmd/set/set_env.go | 3 +++ pkg/cmd/set/set_image.go | 3 +++ pkg/cmd/set/set_resources.go | 3 +++ pkg/cmd/set/set_serviceaccount.go | 3 +++ pkg/cmd/set/set_subject.go | 3 +++ 8 files changed, 24 insertions(+) diff --git a/pkg/cmd/annotate/annotate.go b/pkg/cmd/annotate/annotate.go index 3a014f49..ed4a0be2 100644 --- a/pkg/cmd/annotate/annotate.go +++ b/pkg/cmd/annotate/annotate.go @@ -223,6 +223,9 @@ func (o AnnotateOptions) Validate() error { return fmt.Errorf("one or more resources must be specified as or /") } } else { + 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 rsrc.yaml or --filename=rsrc.json when --local=true is set") } diff --git a/pkg/cmd/label/label.go b/pkg/cmd/label/label.go index 5af6b524..1e0b0eed 100644 --- a/pkg/cmd/label/label.go +++ b/pkg/cmd/label/label.go @@ -211,6 +211,9 @@ 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") } diff --git a/pkg/cmd/patch/patch.go b/pkg/cmd/patch/patch.go index 9b5fd9f5..b67f9a9f 100644 --- a/pkg/cmd/patch/patch.go +++ b/pkg/cmd/patch/patch.go @@ -176,6 +176,9 @@ func (o *PatchOptions) Validate() error { if o.Local && len(o.args) != 0 { return fmt.Errorf("cannot specify --local and server resources") } + if o.Local && o.dryRunStrategy == cmdutil.DryRunServer { + return fmt.Errorf("cannot specify --local and --dry-run=server - did you mean --dry-run=client?") + } if len(o.Patch) == 0 { return fmt.Errorf("must specify -p to patch") } diff --git a/pkg/cmd/set/set_env.go b/pkg/cmd/set/set_env.go index 1e5af2c6..4501ae59 100644 --- a/pkg/cmd/set/set_env.go +++ b/pkg/cmd/set/set_env.go @@ -254,6 +254,9 @@ func (o *EnvOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri // Validate makes sure provided values for EnvOptions are valid func (o *EnvOptions) 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 len(o.Filenames) == 0 && len(o.resources) < 1 { return fmt.Errorf("one or more resources must be specified as or /") } diff --git a/pkg/cmd/set/set_image.go b/pkg/cmd/set/set_image.go index 634aebf4..cf97c29c 100644 --- a/pkg/cmd/set/set_image.go +++ b/pkg/cmd/set/set_image.go @@ -216,6 +216,9 @@ func (o *SetImageOptions) Validate() error { } else if len(o.ContainerImages) > 1 && hasWildcardKey(o.ContainerImages) { errors = append(errors, fmt.Errorf("all containers are already specified by *, but saw more than one container_name=container_image pairs")) } + if o.Local && o.DryRunStrategy == cmdutil.DryRunServer { + errors = append(errors, fmt.Errorf("cannot specify --local and --dry-run=server - did you mean --dry-run=client?")) + } return utilerrors.NewAggregate(errors) } diff --git a/pkg/cmd/set/set_resources.go b/pkg/cmd/set/set_resources.go index c3ad8524..611e326f 100644 --- a/pkg/cmd/set/set_resources.go +++ b/pkg/cmd/set/set_resources.go @@ -210,6 +210,9 @@ func (o *SetResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, ar // Validate makes sure that provided values in ResourcesOptions are valid func (o *SetResourcesOptions) Validate() error { var err 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") } diff --git a/pkg/cmd/set/set_serviceaccount.go b/pkg/cmd/set/set_serviceaccount.go index d5600e23..bc7ac2b9 100644 --- a/pkg/cmd/set/set_serviceaccount.go +++ b/pkg/cmd/set/set_serviceaccount.go @@ -133,6 +133,9 @@ func (o *SetServiceAccountOptions) Complete(f cmdutil.Factory, cmd *cobra.Comman if err != nil { return err } + if o.local && o.dryRunStrategy == cmdutil.DryRunServer { + return fmt.Errorf("cannot specify --local and --dry-run=server - did you mean --dry-run=client?") + } dynamicClient, err := f.DynamicClient() if err != nil { return err diff --git a/pkg/cmd/set/set_subject.go b/pkg/cmd/set/set_subject.go index 8499c974..e5d11cf4 100644 --- a/pkg/cmd/set/set_subject.go +++ b/pkg/cmd/set/set_subject.go @@ -181,6 +181,9 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [] // Validate makes sure provided values in SubjectOptions are valid func (o *SubjectOptions) 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") }