Merge pull request #30247 from ardnaxelarak/28695_suppress_noisy_output

Automatic merge from submit-queue

Make more messages respect --quiet flag

Make following two messages respect `--quiet` in `kubectl run`
- `If you don't see a command prompt, try pressing enter.`
- `Pod "name" deleted`

Ref #28695
This commit is contained in:
Kubernetes Submit Queue 2016-08-12 21:34:14 -07:00 committed by GitHub
commit f0e5dac1f1
6 changed files with 13 additions and 7 deletions

View File

@ -220,7 +220,8 @@ func (p *AttachOptions) Run() error {
} }
fn := func() error { fn := func() error {
if stderr != nil {
if !p.Quiet && stderr != nil {
fmt.Fprintln(stderr, "If you don't see a command prompt, try pressing enter.") fmt.Fprintln(stderr, "If you don't see a command prompt, try pressing enter.")
} }

View File

@ -161,12 +161,12 @@ func RunDelete(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
shortOutput := cmdutil.GetFlagString(cmd, "output") == "name" shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
// By default use a reaper to delete all related resources. // By default use a reaper to delete all related resources.
if cmdutil.GetFlagBool(cmd, "cascade") { if cmdutil.GetFlagBool(cmd, "cascade") {
return ReapResult(r, f, out, cmdutil.GetFlagBool(cmd, "cascade"), ignoreNotFound, cmdutil.GetFlagDuration(cmd, "timeout"), gracePeriod, shortOutput, mapper) return ReapResult(r, f, out, cmdutil.GetFlagBool(cmd, "cascade"), ignoreNotFound, cmdutil.GetFlagDuration(cmd, "timeout"), gracePeriod, shortOutput, mapper, false)
} }
return DeleteResult(r, out, ignoreNotFound, shortOutput, mapper) return DeleteResult(r, out, ignoreNotFound, shortOutput, mapper)
} }
func ReapResult(r *resource.Result, f *cmdutil.Factory, out io.Writer, isDefaultDelete, ignoreNotFound bool, timeout time.Duration, gracePeriod int, shortOutput bool, mapper meta.RESTMapper) error { func ReapResult(r *resource.Result, f *cmdutil.Factory, out io.Writer, isDefaultDelete, ignoreNotFound bool, timeout time.Duration, gracePeriod int, shortOutput bool, mapper meta.RESTMapper, quiet bool) error {
found := 0 found := 0
if ignoreNotFound { if ignoreNotFound {
r = r.IgnoreErrors(errors.IsNotFound) r = r.IgnoreErrors(errors.IsNotFound)
@ -191,7 +191,9 @@ func ReapResult(r *resource.Result, f *cmdutil.Factory, out io.Writer, isDefault
if err := reaper.Stop(info.Namespace, info.Name, timeout, options); err != nil { if err := reaper.Stop(info.Namespace, info.Name, timeout, options); err != nil {
return cmdutil.AddSourceToErr("stopping", info.Source, err) return cmdutil.AddSourceToErr("stopping", info.Source, err)
} }
cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, "deleted") if !quiet {
cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, "deleted")
}
return nil return nil
}) })
if err != nil { if err != nil {

View File

@ -107,6 +107,8 @@ type StreamOptions struct {
ContainerName string ContainerName string
Stdin bool Stdin bool
TTY bool TTY bool
// minimize unnecessary output
Quiet bool
// InterruptParent, if set, is used to handle interrupts while attached // InterruptParent, if set, is used to handle interrupts while attached
InterruptParent *interrupt.Handler InterruptParent *interrupt.Handler
In io.Reader In io.Reader

View File

@ -204,7 +204,7 @@ func forceReplace(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
// By default use a reaper to delete all related resources. // By default use a reaper to delete all related resources.
if cmdutil.GetFlagBool(cmd, "cascade") { if cmdutil.GetFlagBool(cmd, "cascade") {
glog.Warningf("\"cascade\" is set, kubectl will delete and re-create all resources managed by this resource (e.g. Pods created by a ReplicationController). Consider using \"kubectl rolling-update\" if you want to update a ReplicationController together with its Pods.") glog.Warningf("\"cascade\" is set, kubectl will delete and re-create all resources managed by this resource (e.g. Pods created by a ReplicationController). Consider using \"kubectl rolling-update\" if you want to update a ReplicationController together with its Pods.")
err = ReapResult(r, f, out, cmdutil.GetFlagBool(cmd, "cascade"), ignoreNotFound, cmdutil.GetFlagDuration(cmd, "timeout"), cmdutil.GetFlagInt(cmd, "grace-period"), shortOutput, mapper) err = ReapResult(r, f, out, cmdutil.GetFlagBool(cmd, "cascade"), ignoreNotFound, cmdutil.GetFlagDuration(cmd, "timeout"), cmdutil.GetFlagInt(cmd, "grace-period"), shortOutput, mapper, false)
} else { } else {
err = DeleteResult(r, out, ignoreNotFound, shortOutput, mapper) err = DeleteResult(r, out, ignoreNotFound, shortOutput, mapper)
} }

View File

@ -250,6 +250,7 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
Err: cmdErr, Err: cmdErr,
Stdin: interactive, Stdin: interactive,
TTY: tty, TTY: tty,
Quiet: quiet,
}, },
CommandName: cmd.Parent().CommandPath() + " attach", CommandName: cmd.Parent().CommandPath() + " attach",
@ -294,7 +295,7 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
ResourceNames(mapping.Resource, name). ResourceNames(mapping.Resource, name).
Flatten(). Flatten().
Do() Do()
return ReapResult(r, f, cmdOut, true, true, 0, -1, false, mapper) return ReapResult(r, f, cmdOut, true, true, 0, -1, false, mapper, quiet)
} }
return nil return nil
} }

View File

@ -104,5 +104,5 @@ func RunStop(f *cmdutil.Factory, cmd *cobra.Command, args []string, out io.Write
return r.Err() return r.Err()
} }
shortOutput := cmdutil.GetFlagString(cmd, "output") == "name" shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
return ReapResult(r, f, out, false, cmdutil.GetFlagBool(cmd, "ignore-not-found"), cmdutil.GetFlagDuration(cmd, "timeout"), cmdutil.GetFlagInt(cmd, "grace-period"), shortOutput, mapper) return ReapResult(r, f, out, false, cmdutil.GetFlagBool(cmd, "ignore-not-found"), cmdutil.GetFlagDuration(cmd, "timeout"), cmdutil.GetFlagInt(cmd, "grace-period"), shortOutput, mapper, false)
} }