mirror of https://github.com/k3s-io/k3s
Require force when using grace period or timeout
parent
d877967c1a
commit
88e17d7478
|
@ -750,6 +750,15 @@ runTests() {
|
|||
kubectl replace "${kube_flags[@]}" --force -f /tmp/tmp-valid-pod.json
|
||||
# Post-condition: spec.container.name = "replaced-k8s-serve-hostname"
|
||||
kube::test::get_object_assert 'pod valid-pod' "{{(index .spec.containers 0).name}}" 'replaced-k8s-serve-hostname'
|
||||
|
||||
## check replace --grace-period requires --force
|
||||
output_message=$(! kubectl replace "${kube_flags[@]}" --grace-period=1 -f /tmp/tmp-valid-pod.json 2>&1)
|
||||
kube::test::if_has_string "${output_message}" '\-\-grace-period must have \-\-force specified'
|
||||
|
||||
## check replace --timeout requires --force
|
||||
output_message=$(! kubectl replace "${kube_flags[@]}" --timeout=1s -f /tmp/tmp-valid-pod.json 2>&1)
|
||||
kube::test::if_has_string "${output_message}" '\-\-timeout must have \-\-force specified'
|
||||
|
||||
#cleaning
|
||||
rm /tmp/tmp-valid-pod.json
|
||||
|
||||
|
|
|
@ -120,6 +120,14 @@ func RunReplace(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
|
|||
return forceReplace(f, out, cmd, args, shortOutput, options)
|
||||
}
|
||||
|
||||
if cmdutil.GetFlagInt(cmd, "grace-period") >= 0 {
|
||||
return fmt.Errorf("--grace-period must have --force specified")
|
||||
}
|
||||
|
||||
if cmdutil.GetFlagDuration(cmd, "timeout") != 0 {
|
||||
return fmt.Errorf("--timeout must have --force specified")
|
||||
}
|
||||
|
||||
mapper, typer := f.Object(cmdutil.GetIncludeThirdPartyAPIs(cmd))
|
||||
r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)).
|
||||
Schema(schema).
|
||||
|
|
Loading…
Reference in New Issue