mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
Merge pull request #107003 from julianvmodesto/dry-run-values
Re-introduce removed kubectl --dry-run values.
This commit is contained in:
commit
c83a94da72
@ -23,6 +23,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -589,9 +590,13 @@ const (
|
|||||||
|
|
||||||
func GetDryRunStrategy(cmd *cobra.Command) (DryRunStrategy, error) {
|
func GetDryRunStrategy(cmd *cobra.Command) (DryRunStrategy, error) {
|
||||||
var dryRunFlag = GetFlagString(cmd, "dry-run")
|
var dryRunFlag = GetFlagString(cmd, "dry-run")
|
||||||
|
b, err := strconv.ParseBool(dryRunFlag)
|
||||||
|
// The flag is not a boolean
|
||||||
|
if err != nil {
|
||||||
switch dryRunFlag {
|
switch dryRunFlag {
|
||||||
case cmd.Flag("dry-run").NoOptDefVal:
|
case cmd.Flag("dry-run").NoOptDefVal:
|
||||||
return DryRunNone, errors.New(`--dry-run flag without a value was specified. A value must be set: "none", "server", or "client".`)
|
klog.Warning(`--dry-run is deprecated and can be replaced with --dry-run=client.`)
|
||||||
|
return DryRunClient, nil
|
||||||
case "client":
|
case "client":
|
||||||
return DryRunClient, nil
|
return DryRunClient, nil
|
||||||
case "server":
|
case "server":
|
||||||
@ -601,6 +606,14 @@ func GetDryRunStrategy(cmd *cobra.Command) (DryRunStrategy, error) {
|
|||||||
default:
|
default:
|
||||||
return DryRunNone, fmt.Errorf(`Invalid dry-run value (%v). Must be "none", "server", or "client".`, dryRunFlag)
|
return DryRunNone, fmt.Errorf(`Invalid dry-run value (%v). Must be "none", "server", or "client".`, dryRunFlag)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// The flag was a boolean
|
||||||
|
if b {
|
||||||
|
klog.Warningf(`--dry-run=%v is deprecated (boolean value) and can be replaced with --dry-run=%s.`, dryRunFlag, "client")
|
||||||
|
return DryRunClient, nil
|
||||||
|
}
|
||||||
|
klog.Warningf(`--dry-run=%v is deprecated (boolean value) and can be replaced with --dry-run=%s.`, dryRunFlag, "none")
|
||||||
|
return DryRunNone, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintFlagsWithDryRunStrategy sets a success message at print time for the dry run strategy
|
// PrintFlagsWithDryRunStrategy sets a success message at print time for the dry run strategy
|
||||||
|
@ -101,6 +101,7 @@ run_kubectl_apply_tests() {
|
|||||||
kube::test::get_object_assert pods "{{range.items}}{{${id_field:?}}}:{{end}}" ''
|
kube::test::get_object_assert pods "{{range.items}}{{${id_field:?}}}:{{end}}" ''
|
||||||
|
|
||||||
# apply dry-run
|
# apply dry-run
|
||||||
|
kubectl apply --dry-run=true -f hack/testdata/pod.yaml "${kube_flags[@]:?}"
|
||||||
kubectl apply --dry-run=client -f hack/testdata/pod.yaml "${kube_flags[@]:?}"
|
kubectl apply --dry-run=client -f hack/testdata/pod.yaml "${kube_flags[@]:?}"
|
||||||
kubectl apply --dry-run=server -f hack/testdata/pod.yaml "${kube_flags[@]:?}"
|
kubectl apply --dry-run=server -f hack/testdata/pod.yaml "${kube_flags[@]:?}"
|
||||||
# No pod exists
|
# No pod exists
|
||||||
|
@ -49,7 +49,7 @@ run_job_tests() {
|
|||||||
kube::test::describe_resource_chunk_size_assert cronjobs events "--namespace=test-jobs"
|
kube::test::describe_resource_chunk_size_assert cronjobs events "--namespace=test-jobs"
|
||||||
|
|
||||||
### Create a job in dry-run mode
|
### Create a job in dry-run mode
|
||||||
output_message=$(kubectl create job test-job --from=cronjob/pi --dry-run=client --namespace=test-jobs -o name)
|
output_message=$(kubectl create job test-job --from=cronjob/pi --dry-run=true --namespace=test-jobs -o name)
|
||||||
# Post-condition: The text 'job.batch/test-job' should be part of the output
|
# Post-condition: The text 'job.batch/test-job' should be part of the output
|
||||||
kube::test::if_has_string "${output_message}" 'job.batch/test-job'
|
kube::test::if_has_string "${output_message}" 'job.batch/test-job'
|
||||||
# Post-condition: The test-job wasn't created actually
|
# Post-condition: The test-job wasn't created actually
|
||||||
|
Loading…
Reference in New Issue
Block a user