mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #92834 from ykakarap/kubectl_force_flag_serverside
kubectl: cannot use --force with --server-side
This commit is contained in:
commit
3615291cb3
@ -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")
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user