kubectl: cannot use --force with --server-side

Kubernetes-commit: f93ad0204eeeb21e567df3d5841847373bf7a646
This commit is contained in:
Yuvaraj Kakaraparthi 2020-07-06 10:07:26 -07:00 committed by Kubernetes Publisher
parent 10a2ba5463
commit 36c221e3cf
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) {