mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #13383 from hurf/label_drun
Add --dry-run option for label command
This commit is contained in:
commit
be19554bae
@ -822,6 +822,7 @@ _kubectl_label()
|
|||||||
flags_completion=()
|
flags_completion=()
|
||||||
|
|
||||||
flags+=("--all")
|
flags+=("--all")
|
||||||
|
flags+=("--dry-run")
|
||||||
flags+=("--filename=")
|
flags+=("--filename=")
|
||||||
flags_with_completion+=("--filename")
|
flags_with_completion+=("--filename")
|
||||||
flags_completion+=("__handle_filename_extension_flag json|stdin|yaml|yml")
|
flags_completion+=("__handle_filename_extension_flag json|stdin|yaml|yml")
|
||||||
|
@ -26,6 +26,10 @@ If \-\-resource\-version is specified, then updates will use this resource versi
|
|||||||
\fB\-\-all\fP=false
|
\fB\-\-all\fP=false
|
||||||
select all resources in the namespace of the specified resource types
|
select all resources in the namespace of the specified resource types
|
||||||
|
|
||||||
|
.PP
|
||||||
|
\fB\-\-dry\-run\fP=false
|
||||||
|
If true, only print the object that would be sent, without sending it.
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
\fB\-f\fP, \fB\-\-filename\fP=[]
|
\fB\-f\fP, \fB\-\-filename\fP=[]
|
||||||
Filename, directory, or URL to a file identifying the resource to update the labels
|
Filename, directory, or URL to a file identifying the resource to update the labels
|
||||||
|
@ -75,6 +75,7 @@ $ kubectl label pods foo bar-
|
|||||||
|
|
||||||
```
|
```
|
||||||
--all[=false]: select all resources in the namespace of the specified resource types
|
--all[=false]: select all resources in the namespace of the specified resource types
|
||||||
|
--dry-run[=false]: If true, only print the object that would be sent, without sending it.
|
||||||
-f, --filename=[]: Filename, directory, or URL to a file identifying the resource to update the labels
|
-f, --filename=[]: Filename, directory, or URL to a file identifying the resource to update the labels
|
||||||
-h, --help[=false]: help for label
|
-h, --help[=false]: help for label
|
||||||
--no-headers[=false]: When using the default output, don't print headers.
|
--no-headers[=false]: When using the default output, don't print headers.
|
||||||
@ -120,7 +121,7 @@ $ kubectl label pods foo bar-
|
|||||||
|
|
||||||
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
|
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra at 2015-08-26 09:03:39.977006328 +0000 UTC
|
###### Auto generated by spf13/cobra at 2015-08-31 12:51:55.222410248 +0000 UTC
|
||||||
|
|
||||||
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||||||
[]()
|
[]()
|
||||||
|
@ -90,6 +90,8 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||||||
cmd.Flags().String("resource-version", "", "If non-empty, the labels update will only succeed if this is the current resource-version for the object. Only valid when specifying a single resource.")
|
cmd.Flags().String("resource-version", "", "If non-empty, the labels update will only succeed if this is the current resource-version for the object. Only valid when specifying a single resource.")
|
||||||
usage := "Filename, directory, or URL to a file identifying the resource to update the labels"
|
usage := "Filename, directory, or URL to a file identifying the resource to update the labels"
|
||||||
kubectl.AddJsonFilenameFlag(cmd, &options.Filenames, usage)
|
kubectl.AddJsonFilenameFlag(cmd, &options.Filenames, usage)
|
||||||
|
cmd.Flags().Bool("dry-run", false, "If true, only print the object that would be sent, without sending it.")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,22 +221,31 @@ func RunLabel(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
obj, err := cmdutil.UpdateObject(info, func(obj runtime.Object) error {
|
|
||||||
err := labelFunc(obj, overwrite, resourceVersion, lbls, remove)
|
var outputObj runtime.Object
|
||||||
|
if cmdutil.GetFlagBool(cmd, "dry-run") {
|
||||||
|
err = labelFunc(info.Object, overwrite, resourceVersion, lbls, remove)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
outputObj = info.Object
|
||||||
|
} else {
|
||||||
|
outputObj, err = cmdutil.UpdateObject(info, func(obj runtime.Object) error {
|
||||||
|
err := labelFunc(obj, overwrite, resourceVersion, lbls, remove)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outputFormat := cmdutil.GetFlagString(cmd, "output")
|
outputFormat := cmdutil.GetFlagString(cmd, "output")
|
||||||
if outputFormat == "" {
|
if outputFormat == "" {
|
||||||
cmdutil.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, "labeled")
|
cmdutil.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, "labeled")
|
||||||
} else {
|
} else {
|
||||||
f.PrintObject(cmd, obj, out)
|
return f.PrintObject(cmd, outputObj, out)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user