-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07228ff
commit 2b17e27
Showing
9 changed files
with
109 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package mutation | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"k8s.io/kubernetes/pkg/api/meta" | ||
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" | ||
"k8s.io/kubernetes/pkg/kubectl/resource" | ||
"k8s.io/kubernetes/pkg/runtime" | ||
) | ||
|
||
func NewMutationOutputOptions(factory *kcmdutil.Factory, cmd *cobra.Command, out io.Writer) MutationOutputOptions { | ||
mapper, typer := factory.Object() | ||
if out == nil { | ||
out = ioutil.Discard | ||
} | ||
|
||
return MutationOutputOptions{ | ||
mapper: mapper, | ||
resourceMapper: resource.Mapper{ObjectTyper: typer, RESTMapper: mapper, ClientMapper: factory.ClientMapperForCommand()}, | ||
shortOutput: kcmdutil.GetFlagString(cmd, "output") == "name", | ||
out: out, | ||
} | ||
} | ||
|
||
// MutationOutputOptions holds all of the information necessary to correctly output the reslult of mutating | ||
// an object in etcd. | ||
type MutationOutputOptions struct { | ||
mapper meta.RESTMapper | ||
resourceMapper resource.Mapper | ||
shortOutput bool | ||
out io.Writer | ||
} | ||
|
||
// PrintSuccess wraps around kcmdutil.PrintSuccess | ||
func (o *MutationOutputOptions) PrintSuccess(object runtime.Object, operation string) error { | ||
info, err := o.resourceMapper.InfoForObject(object) | ||
if err != nil { | ||
return err | ||
} | ||
kcmdutil.PrintSuccess(o.mapper, o.shortOutput, o.out, info.Mapping.Resource, info.Name, operation) | ||
return nil | ||
} |