Merge pull request #107003 from julianvmodesto/dry-run-values

Re-introduce removed kubectl --dry-run values.

Kubernetes-commit: c83a94da72416219cf9f022dc44b0e6db158f092
This commit is contained in:
Kubernetes Publisher 2021-12-14 03:15:46 -08:00
commit 4a1c72da90
3 changed files with 28 additions and 15 deletions

4
go.mod
View File

@ -31,7 +31,7 @@ require (
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.0.0-20211213171716-0820d150f9ee
k8s.io/api v0.0.0-20211213234601-b7112c1b6e9e
k8s.io/apimachinery v0.0.0-20211213171520-e65876e14280
k8s.io/cli-runtime v0.0.0-20211213173919-7521450cf418
k8s.io/client-go v0.0.0-20211213171958-056a9de35397
@ -47,7 +47,7 @@ require (
)
replace (
k8s.io/api => k8s.io/api v0.0.0-20211213171716-0820d150f9ee
k8s.io/api => k8s.io/api v0.0.0-20211213234601-b7112c1b6e9e
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20211213171520-e65876e14280
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20211213173919-7521450cf418
k8s.io/client-go => k8s.io/client-go v0.0.0-20211213171958-056a9de35397

4
go.sum
View File

@ -911,8 +911,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.0.0-20211213171716-0820d150f9ee h1:/v+7rD7h8qwNabJfpXzvxuE1pY6wcJODhRknvg+nQi4=
k8s.io/api v0.0.0-20211213171716-0820d150f9ee/go.mod h1:vmCvbkzTfBQjlMNSgh69E+3vHHcFdYVCXF20g8xtEaE=
k8s.io/api v0.0.0-20211213234601-b7112c1b6e9e h1:Fzjke98RMhnE6jv2L7ODA/aCizYxOAhovMGjdPrlU9c=
k8s.io/api v0.0.0-20211213234601-b7112c1b6e9e/go.mod h1:vmCvbkzTfBQjlMNSgh69E+3vHHcFdYVCXF20g8xtEaE=
k8s.io/apimachinery v0.0.0-20211213171520-e65876e14280 h1:1Vi6MSKuJbfiiUckP6GaHTGYZtqayWlyf/JItZRH8Rg=
k8s.io/apimachinery v0.0.0-20211213171520-e65876e14280/go.mod h1:YpCy0BWvwSGZKMwmvPxCsfFJfl6vAwQdfVnPOJoUT2E=
k8s.io/cli-runtime v0.0.0-20211213173919-7521450cf418 h1:Zq6mshf2Hoib2zVJnpZjPTrBzAGZOo0fEIpZvANiCI8=

View File

@ -23,6 +23,7 @@ import (
"io"
"net/url"
"os"
"strconv"
"strings"
"time"
@ -589,18 +590,30 @@ const (
func GetDryRunStrategy(cmd *cobra.Command) (DryRunStrategy, error) {
var dryRunFlag = GetFlagString(cmd, "dry-run")
switch dryRunFlag {
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".`)
case "client":
return DryRunClient, nil
case "server":
return DryRunServer, nil
case "none":
return DryRunNone, nil
default:
return DryRunNone, fmt.Errorf(`Invalid dry-run value (%v). Must be "none", "server", or "client".`, dryRunFlag)
b, err := strconv.ParseBool(dryRunFlag)
// The flag is not a boolean
if err != nil {
switch dryRunFlag {
case cmd.Flag("dry-run").NoOptDefVal:
klog.Warning(`--dry-run is deprecated and can be replaced with --dry-run=client.`)
return DryRunClient, nil
case "client":
return DryRunClient, nil
case "server":
return DryRunServer, nil
case "none":
return DryRunNone, nil
default:
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