Fix nil dereference in kubectl run-container

This commit is contained in:
Jeff Lowdermlk
2015-01-14 16:58:12 -08:00
parent 8a764c02d5
commit e6e6092904
4 changed files with 84 additions and 20 deletions

View File

@@ -36,28 +36,23 @@ func AddPrinterFlags(cmd *cobra.Command) {
}
// PrintObject prints an api object given command line flags to modify the output format
func PrintObject(cmd *cobra.Command, obj runtime.Object, f *Factory, out io.Writer) {
func PrintObject(cmd *cobra.Command, obj runtime.Object, f *Factory, out io.Writer) error {
mapper, _ := f.Object(cmd)
_, kind, err := api.Scheme.ObjectVersionAndKind(obj)
checkErr(err)
if err != nil {
return err
}
mapping, err := mapper.RESTMapping(kind)
checkErr(err)
printer, ok, err := PrinterForCommand(cmd)
checkErr(err)
if ok {
version := outputVersion(cmd)
if len(version) == 0 {
version = mapping.APIVersion
}
if len(version) == 0 {
checkErr(fmt.Errorf("you must specify an output-version when using this output format"))
}
printer = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, version)
if err != nil {
return err
}
printer.PrintObj(obj, out)
printer, err := PrinterForMapping(f, cmd, mapping)
if err != nil {
return err
}
return printer.PrintObj(obj, out)
}
// outputVersion returns the preferred output version for generic content (JSON, YAML, or templates)