Fix nil dereference in kubectl run-container
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user