Validate dry-run and force flags can not be used same time in replace

This PR adds validation to check that `dry-run` and `force` flags
are not used at the same time. Because when `force` flag is set,
`dry-run` is discarded and objects are replaced already.

Kubernetes-commit: e389b2723e6af29a9f70509fe8ff6e5121c30681
This commit is contained in:
Arda Güçlü 2022-06-01 14:01:40 +03:00 committed by Kubernetes Publisher
parent 3474b03beb
commit bdaa26ce9e

View file

@ -227,6 +227,10 @@ func (o *ReplaceOptions) Validate() error {
return fmt.Errorf("--timeout must have --force specified")
}
if o.DeleteOptions.ForceDeletion && o.DryRunStrategy != cmdutil.DryRunNone {
return fmt.Errorf("dry-run can not be used when --force is set")
}
if cmdutil.IsFilenameSliceEmpty(o.DeleteOptions.FilenameOptions.Filenames, o.DeleteOptions.FilenameOptions.Kustomize) {
return fmt.Errorf("Must specify --filename to replace")
}