Skip to content

Commit

Permalink
fix kubectl set resource/selector/subject output
Browse files Browse the repository at this point in the history
  • Loading branch information
xilabao committed Aug 14, 2017
1 parent 2820b45 commit 3e5dabb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
11 changes: 8 additions & 3 deletions pkg/kubectl/cmd/set/set_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type ResourcesOptions struct {
Err io.Writer
Selector string
ContainerSelector string
ShortOutput bool
Output string
All bool
Record bool
ChangeCause string
Expand Down Expand Up @@ -129,7 +129,7 @@ func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
o.Mapper, o.Typer = f.Object()
o.UpdatePodSpecForObject = f.UpdatePodSpecForObject
o.Encoder = f.JSONEncoder()
o.ShortOutput = cmdutil.GetFlagString(cmd, "output") == "name"
o.Output = cmdutil.GetFlagString(cmd, "output")
o.Record = cmdutil.GetRecordFlag(cmd)
o.Local = cmdutil.GetFlagBool(cmd, "local")
o.ChangeCause = f.Command(cmd, false)
Expand Down Expand Up @@ -243,7 +243,12 @@ func (o *ResourcesOptions) Run() error {
}
}
info.Refresh(obj, true)
cmdutil.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, false, "resource requirements updated")

shortOutput := o.Output == "name"
if len(o.Output) > 0 && !shortOutput {
return o.PrintObject(o.Cmd, o.Local, o.Mapper, info.Object, o.Out)
}
cmdutil.PrintSuccess(o.Mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, false, "resource requirements updated")
}
return utilerrors.NewAggregate(allErrs)
}
9 changes: 8 additions & 1 deletion pkg/kubectl/cmd/set/set_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type SelectorOptions struct {
all bool
record bool
changeCause string
output string

resources []string
selector *metav1.LabelSelector
Expand Down Expand Up @@ -106,6 +107,7 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
o.all = cmdutil.GetFlagBool(cmd, "all")
o.record = cmdutil.GetRecordFlag(cmd)
o.dryrun = cmdutil.GetDryRunFlag(cmd)
o.output = cmdutil.GetFlagString(cmd, "output")

cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
if err != nil {
Expand Down Expand Up @@ -194,7 +196,12 @@ func (o *SelectorOptions) RunSelector() error {
}

info.Refresh(patched, true)
cmdutil.PrintSuccess(o.mapper, false, o.out, info.Mapping.Resource, info.Name, o.dryrun, "selector updated")

shortOutput := o.output == "name"
if len(o.output) > 0 && !shortOutput {
return o.PrintObject(info.Object)
}
cmdutil.PrintSuccess(o.mapper, shortOutput, o.out, info.Mapping.Resource, info.Name, o.dryrun, "selector updated")
return nil
})
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/kubectl/cmd/set/set_subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type SubjectOptions struct {
Err io.Writer
Selector string
ContainerSelector string
ShortOutput bool
Output string
All bool
DryRun bool
Local bool
Expand Down Expand Up @@ -112,7 +112,7 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
o.Local = cmdutil.GetFlagBool(cmd, "local")
o.Mapper, o.Typer = f.Object()
o.Encoder = f.JSONEncoder()
o.ShortOutput = cmdutil.GetFlagString(cmd, "output") == "name"
o.Output = cmdutil.GetFlagString(cmd, "output")
o.DryRun = cmdutil.GetDryRunFlag(cmd)
o.PrintObject = func(mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error {
return f.PrintObject(cmd, o.Local, mapper, obj, out)
Expand Down Expand Up @@ -235,7 +235,11 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
}
info.Refresh(obj, true)

cmdutil.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, false, "subjects updated")
shortOutput := o.Output == "name"
if len(o.Output) > 0 && !shortOutput {
return o.PrintObject(o.Mapper, info.Object, o.Out)
}
cmdutil.PrintSuccess(o.Mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, false, "subjects updated")
}
return utilerrors.NewAggregate(allErrs)
}
Expand Down

0 comments on commit 3e5dabb

Please sign in to comment.