mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #90225 from brianpursley/kubernetes-90017
Added kubectl apply validation to prevent using --dry-run=server with --force
This commit is contained in:
commit
875f31e988
@ -250,6 +250,10 @@ func (o *ApplyOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if o.DryRunStrategy == cmdutil.DryRunServer && o.DeleteOptions.ForceDeletion {
|
||||
return fmt.Errorf("--dry-run=server cannot be used with --force")
|
||||
}
|
||||
|
||||
o.OpenAPISchema, _ = f.OpenAPISchema()
|
||||
o.Validator, err = f.Validator(cmdutil.GetFlagBool(cmd, "validate"))
|
||||
if err != nil {
|
||||
|
@ -1382,3 +1382,31 @@ func TestForceApply(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDontAllowForceApplyWithServerDryRun(t *testing.T) {
|
||||
expectedError := "error: --dry-run=server cannot be used with --force"
|
||||
|
||||
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("dry-run", "server")
|
||||
cmd.Flags().Set("force", "true")
|
||||
cmd.Run(cmd, []string{})
|
||||
|
||||
t.Fatalf(`expected error "%s"`, expectedError)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user