Merge pull request #92834 from ykakarap/kubectl_force_flag_serverside

kubectl: cannot use --force with --server-side
This commit is contained in:
Kubernetes Prow Robot 2020-07-06 20:37:58 -07:00 committed by GitHub
commit 3615291cb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -250,6 +250,10 @@ func (o *ApplyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
return err
}
if o.ServerSideApply && o.DeleteOptions.ForceDeletion {
return fmt.Errorf("--force cannot be used with --server-side")
}
if o.DryRunStrategy == cmdutil.DryRunServer && o.DeleteOptions.ForceDeletion {
return fmt.Errorf("--dry-run=server cannot be used with --force")
}

View File

@ -1412,6 +1412,34 @@ func TestDontAllowForceApplyWithServerDryRun(t *testing.T) {
t.Fatalf(`expected error "%s"`, expectedError)
}
func TestDontAllowForceApplyWithServerSide(t *testing.T) {
expectedError := "error: --force cannot be used with --server-side"
cmdutil.BehaviorOnFatal(func(str string, code int) {
panic(str)
})
defer func() {
actualError := recover()
if expectedError != actualError {
t.Fatalf(`expected error "%s", but got "%s"`, expectedError, actualError)
}
}()
tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup()
tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams()
cmd := NewCmdApply("kubectl", tf, ioStreams)
cmd.Flags().Set("filename", filenameRC)
cmd.Flags().Set("server-side", "true")
cmd.Flags().Set("force", "true")
cmd.Run(cmd, []string{})
t.Fatalf(`expected error "%s"`, expectedError)
}
func TestDontAllowApplyWithPodGeneratedName(t *testing.T) {
expectedError := "error: from testing-: cannot use generate name with apply"
cmdutil.BehaviorOnFatal(func(str string, code int) {