Skip to content

Commit 6416163

Browse files
authored
Merge pull request kubernetes#88133 from julianvmodesto/dry-run-tests
Cleanup --dry-run values in tests, docs, and scripts
2 parents 882b6f8 + d97169f commit 6416163

25 files changed

+96
-74
lines changed

cluster/gce/upgrade.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ function update-coredns-config() {
518518
if test "$(printf '%s\n' ${CURRENT_COREDNS_VERSION} ${NEW_COREDNS_VERSION} | sort -V | head -n 1)" != ${NEW_COREDNS_VERSION}; then
519519
echo "== Upgrading the CoreDNS ConfigMap =="
520520
${download_dir}/corefile-tool-${host_arch} migrate --from ${CURRENT_COREDNS_VERSION} --to ${NEW_COREDNS_VERSION} --corefile ${download_dir}/Corefile-old > ${download_dir}/Corefile
521-
${KUBE_ROOT}/cluster/kubectl.sh -n kube-system create configmap coredns --from-file ${download_dir}/Corefile -o yaml --dry-run | ${KUBE_ROOT}/cluster/kubectl.sh apply -f -
521+
${KUBE_ROOT}/cluster/kubectl.sh -n kube-system create configmap coredns --from-file ${download_dir}/Corefile -o yaml --dry-run=client | ${KUBE_ROOT}/cluster/kubectl.sh apply -f -
522522
else
523523
# In case of a downgrade, a custom CoreDNS Corefile will be overwritten by a default Corefile. In that case,
524524
# the user will need to manually modify the resulting (default) Corefile after the downgrade is complete.

pkg/kubectl/cmd/auth/reconcile.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ func NewCmdReconcile(f cmdutil.Factory, streams genericclioptions.IOStreams) *co
104104
o.PrintFlags.AddFlags(cmd)
105105

106106
cmdutil.AddFilenameOptionFlags(cmd, o.FilenameOptions, "identifying the resource to reconcile.")
107-
cmd.Flags().BoolVar(&o.DryRun, "dry-run", o.DryRun, "If true, display results but do not submit changes")
108107
cmd.Flags().BoolVar(&o.RemoveExtraPermissions, "remove-extra-permissions", o.RemoveExtraPermissions, "If true, removes extra permissions added to roles")
109108
cmd.Flags().BoolVar(&o.RemoveExtraSubjects, "remove-extra-subjects", o.RemoveExtraSubjects, "If true, removes extra subjects added to rolebindings")
109+
cmdutil.AddDryRunFlag(cmd)
110110

111111
return cmd
112112
}
@@ -121,6 +121,8 @@ func (o *ReconcileOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args
121121
return errors.New("no arguments are allowed")
122122
}
123123

124+
o.DryRun = getClientSideDryRun(cmd)
125+
124126
namespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()
125127
if err != nil {
126128
return err
@@ -328,3 +330,14 @@ func (o *ReconcileOptions) printResults(object runtime.Object,
328330
}
329331
}
330332
}
333+
334+
func getClientSideDryRun(cmd *cobra.Command) bool {
335+
dryRunStrategy, err := cmdutil.GetDryRunStrategy(cmd)
336+
if err != nil {
337+
klog.Fatalf("error accessing --dry-run flag for command %s: %v", cmd.Name(), err)
338+
}
339+
if dryRunStrategy == cmdutil.DryRunServer {
340+
klog.Fatalf("--dry-run=server for command %s is not supported yet", cmd.Name())
341+
}
342+
return dryRunStrategy == cmdutil.DryRunClient
343+
}

staging/src/k8s.io/kubectl/docs/book/pages/imperative_porcelain/creating_resources.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ kubectl create secret generic my-secret --from-file=path/to/bar
8383
{% endmethod %}
8484

8585
{% panel style="success", title="Bootstrapping Config" %}
86-
Imperative commands can be used to bootstrap config by using `--dry-run -o yaml`.
87-
`kubectl create secret generic my-secret --from-file=path/to/bar --dry-run -o yaml`
86+
Imperative commands can be used to bootstrap config by using `--dry-run=client -o yaml`.
87+
`kubectl create secret generic my-secret --from-file=path/to/bar --dry-run=client -o yaml`
8888
{% endpanel %}
8989

9090
{% method %}

staging/src/k8s.io/kubectl/docs/book/pages/imperative_porcelain/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use cases, imperative porcelain commands may be helpful for development or debug
99
issues. These commands are particularly helpful for learning about Kubernetes when coming
1010
from an imperative system.
1111

12-
**Note:** Some imperative commands can be run with `--dry-run -o yaml` to display the declarative
12+
**Note:** Some imperative commands can be run with `--dry-run=client -o yaml` to display the declarative
1313
form.
1414

1515
This section describes imperative commands that will generate or patch Resource Config.

staging/src/k8s.io/kubectl/docs/book/pages/kubectl_book/getting_started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ List the Kubernetes *Deployment* Resources that are in the kube-system namespace
2929
```bash
3030
kubectl get deployments --namespace kube-system
3131
```
32-
32+
3333
```bash
3434
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
3535
event-exporter-v0.2.3 1 1 1 1 14d
@@ -51,7 +51,7 @@ Print detailed information about the kube-dns Deployment in the kube-system name
5151
```bash
5252
kubectl describe deployment kube-dns --namespace kube-system
5353
```
54-
54+
5555
```bash
5656
Name: kube-dns
5757
Namespace: kube-system
@@ -126,7 +126,7 @@ due to the serialization process of go objects.
126126

127127
{% sample lang="yaml" %}
128128
```bash
129-
kubectl create deployment nginx --dry-run -o yaml --image nginx
129+
kubectl create deployment nginx --dry-run=client -o yaml --image nginx
130130
```
131131

132132
```yaml

staging/src/k8s.io/kubectl/pkg/cmd/create/create_clusterrole.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func NewCmdCreateClusterRole(f cmdutil.Factory, ioStreams genericclioptions.IOSt
7373
AggregationRule: map[string]string{},
7474
}
7575
cmd := &cobra.Command{
76-
Use: "clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run]",
76+
Use: "clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]",
7777
DisableFlagsInUseLine: true,
7878
Short: clusterRoleLong,
7979
Long: clusterRoleLong,

staging/src/k8s.io/kubectl/pkg/cmd/create/create_clusterrolebinding.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func NewCmdCreateClusterRoleBinding(f cmdutil.Factory, ioStreams genericclioptio
4848
}
4949

5050
cmd := &cobra.Command{
51-
Use: "clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname] [--serviceaccount=namespace:serviceaccountname] [--dry-run]",
51+
Use: "clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname] [--serviceaccount=namespace:serviceaccountname] [--dry-run=server|client|none]",
5252
DisableFlagsInUseLine: true,
5353
Short: i18n.T("Create a ClusterRoleBinding for a particular ClusterRole"),
5454
Long: clusterRoleBindingLong,

staging/src/k8s.io/kubectl/pkg/cmd/create/create_configmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewCmdCreateConfigMap(f cmdutil.Factory, ioStreams genericclioptions.IOStre
6969
}
7070

7171
cmd := &cobra.Command{
72-
Use: "configmap NAME [--from-file=[key=]source] [--from-literal=key1=value1] [--dry-run]",
72+
Use: "configmap NAME [--from-file=[key=]source] [--from-literal=key1=value1] [--dry-run=server|client|none]",
7373
DisableFlagsInUseLine: true,
7474
Aliases: []string{"cm"},
7575
Short: i18n.T("Create a configmap from a local file, directory or literal value"),

staging/src/k8s.io/kubectl/pkg/cmd/create/create_deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewCmdCreateDeployment(f cmdutil.Factory, ioStreams genericclioptions.IOStr
5050
}
5151

5252
cmd := &cobra.Command{
53-
Use: "deployment NAME --image=image [--dry-run]",
53+
Use: "deployment NAME --image=image [--dry-run=server|client|none]",
5454
DisableFlagsInUseLine: true,
5555
Aliases: []string{"deploy"},
5656
Short: i18n.T("Create a deployment with the specified name."),

staging/src/k8s.io/kubectl/pkg/cmd/create/create_namespace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func NewCmdCreateNamespace(f cmdutil.Factory, ioStreams genericclioptions.IOStre
4848
}
4949

5050
cmd := &cobra.Command{
51-
Use: "namespace NAME [--dry-run]",
51+
Use: "namespace NAME [--dry-run=server|client|none]",
5252
DisableFlagsInUseLine: true,
5353
Aliases: []string{"ns"},
5454
Short: i18n.T("Create a namespace with the specified name"),

0 commit comments

Comments
 (0)