Skip to content

Commit f93ad02

Browse files
author
Yuvaraj Kakaraparthi
committed
kubectl: cannot use --force with --server-side
1 parent 205d5c5 commit f93ad02

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/apply/apply.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ func (o *ApplyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
250250
return err
251251
}
252252

253+
if o.ServerSideApply && o.DeleteOptions.ForceDeletion {
254+
return fmt.Errorf("--force cannot be used with --server-side")
255+
}
256+
253257
if o.DryRunStrategy == cmdutil.DryRunServer && o.DeleteOptions.ForceDeletion {
254258
return fmt.Errorf("--dry-run=server cannot be used with --force")
255259
}

staging/src/k8s.io/kubectl/pkg/cmd/apply/apply_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,34 @@ func TestDontAllowForceApplyWithServerDryRun(t *testing.T) {
14121412
t.Fatalf(`expected error "%s"`, expectedError)
14131413
}
14141414

1415+
func TestDontAllowForceApplyWithServerSide(t *testing.T) {
1416+
expectedError := "error: --force cannot be used with --server-side"
1417+
1418+
cmdutil.BehaviorOnFatal(func(str string, code int) {
1419+
panic(str)
1420+
})
1421+
defer func() {
1422+
actualError := recover()
1423+
if expectedError != actualError {
1424+
t.Fatalf(`expected error "%s", but got "%s"`, expectedError, actualError)
1425+
}
1426+
}()
1427+
1428+
tf := cmdtesting.NewTestFactory().WithNamespace("test")
1429+
defer tf.Cleanup()
1430+
1431+
tf.ClientConfigVal = cmdtesting.DefaultClientConfig()
1432+
1433+
ioStreams, _, _, _ := genericclioptions.NewTestIOStreams()
1434+
cmd := NewCmdApply("kubectl", tf, ioStreams)
1435+
cmd.Flags().Set("filename", filenameRC)
1436+
cmd.Flags().Set("server-side", "true")
1437+
cmd.Flags().Set("force", "true")
1438+
cmd.Run(cmd, []string{})
1439+
1440+
t.Fatalf(`expected error "%s"`, expectedError)
1441+
}
1442+
14151443
func TestDontAllowApplyWithPodGeneratedName(t *testing.T) {
14161444
expectedError := "error: from testing-: cannot use generate name with apply"
14171445
cmdutil.BehaviorOnFatal(func(str string, code int) {

0 commit comments

Comments
 (0)