func (ph *printHandler) printInternal(tableVersion string, o runtime.Object) (*metav1.Table, error) {
	internalVersion, err := legacyscheme.Scheme.New(schema.GroupVersionKind{Group: o.GetObjectKind().GroupVersionKind().Group, Kind: o.GetObjectKind().GroupVersionKind().Kind, Version: runtime.APIVersionInternal})
	if err != nil {
		return nil, nil
	}
	handler, ok := ph.handlers[reflect.TypeOf(internalVersion)]
	if !ok {
		ph.log.Info("Found no handler for type", zap.String("type", fmt.Sprintf("%T", internalVersion)))
		return nil, nil
	}
	ph.log.Info("Found handler for type", zap.String("type", fmt.Sprintf("%T", internalVersion)))
	if err := legacyscheme.Scheme.Convert(o, internalVersion, nil); err != nil {
		return nil, fmt.Errorf("failed to convert to internal version: %w", err)
	}

	generateOpts := printers.GenerateOptions{Wide: true}
	var result []reflect.Value
	switch argCount := reflect.TypeOf(handler.printFunc.Interface()).NumIn(); argCount {
	case 2:
		result = handler.printFunc.Call([]reflect.Value{
			reflect.ValueOf(internalVersion),
			reflect.ValueOf(generateOpts),
		})
	case 3:
		result = handler.printFunc.Call([]reflect.Value{
			reflect.ValueOf(context.Background()),
			reflect.ValueOf(internalVersion),
			// Can be literally anything, but needs a concrete type, ValueOf(runtime.Object(nil)
			// results in a zero reflect.Value.
			reflect.Zero(reflect.TypeOf(&unstructured.Unstructured{})),
		})
	default:
		ph.log.Error("Unexpected argument count for print func, exepected to or three", zap.Int("arg_count", argCount))
		return nil, nil

	}
	rowsVal, errVal := result[0], result[1]
	if v := errVal.Interface(); v != nil {
		err := v.(error)
		return nil, fmt.Errorf("printFunc failed: %w", err)
	}
	var rows []metav1.TableRow
	switch v := rowsVal.Interface().(type) {
	case []metav1.TableRow:
		rows = v
	case *metav1.Table:
		rows = v.Rows
	default:
		return nil, fmt.Errorf("printFunc returned unexepcted type %T", v)
	}
	for idx := range rows {
		// We have to convert the embedded object back to the external version
		gvk := o.GetObjectKind().GroupVersionKind()
		gvk.Kind = strings.TrimSuffix(gvk.Kind, "List")
		externalVersion, err := legacyscheme.Scheme.New(gvk)
		if err != nil {
			return nil, fmt.Errorf("failed to get an object from scheme for %s: %w", gvk, err)
		}
		if err := legacyscheme.Scheme.Convert(rows[idx].Object.Object, externalVersion, nil); err != nil {
			return nil, fmt.Errorf("failed to convert embedded object to external version: %w", err)
		}
		externalVersion.(gvkSetter).SetGroupVersionKind(gvk)
		rows[idx].Object = runtime.RawExtension{Object: externalVersion}
	}
	return &metav1.Table{
		TypeMeta: metav1.TypeMeta{
			APIVersion: "meta.k8s.io/" + tableVersion,
			Kind:       "Table",
		},
		ColumnDefinitions: handler.columnDefinitions,
		Rows:              rows,
	}, nil
}
// printInternal prints using an imported table printer. Because the tableprinters act on the internal version, we have to:
// * Convert into the internal version
// * Call the printfunc using reflect (The printfuncs are given to us as a slice of type Any)
// * Convert the object that is part of the row from the internal version to the external version and set the GVK along
//   the way, because:
//    * Kubectl will refuse the entire list if any of the object keys does not have GVK set
//    * Kubectl infers the namespace in case of namespaced objects from the embedded object, so we can not just omit it
printInternal prints using an imported table printer. Because the tableprinters act on the internal version, we have to:
Convert into the internal version
Call the printfunc using reflect (The printfuncs are given to us as a slice of type Any)
Convert the object that is part of the row from the internal version to the external version and set the GVK along
the way, because:
Kubectl will refuse the entire list if any of the object keys does not have GVK set
Kubectl infers the namespace in case of namespaced objects from the embedded object, so we can not just omit it
// printInternal prints using an imported table printer . Because the tableprinters act on the internal version we have to : // * Convert into the internal version // * Call the printfunc using reflect ( The printfuncs are given to us as a slice of type Any ) // * Convert the object that is part of the row from the internal version to the external version and set the GVK along // the way because : // * Kubectl will refuse the entire list if any of the object keys does not have GVK set // * Kubectl infers the namespace in case of namespaced objects from the embedded object so we can not just omit it
func (ph *printHandler) printInternal(tableVersion string, o runtime.Object) (*metav1.Table, error) {
	internalVersion, err := legacyscheme.Scheme.New(schema.GroupVersionKind{Group: o.GetObjectKind().GroupVersionKind().Group, Kind: o.GetObjectKind().GroupVersionKind().Kind, Version: runtime.APIVersionInternal})
	if err != nil {
		return nil, nil
	}
	handler, ok := ph.handlers[reflect.TypeOf(internalVersion)]
	if !ok {
		ph.log.Info("Found no handler for type", zap.String("type", fmt.Sprintf("%T", internalVersion)))
		return nil, nil
	}
	ph.log.Info("Found handler for type", zap.String("type", fmt.Sprintf("%T", internalVersion)))
	if err := legacyscheme.Scheme.Convert(o, internalVersion, nil); err != nil {
		return nil, fmt.Errorf("failed to convert to internal version: %w", err)
	}
	generateOpts := printers.GenerateOptions{Wide: true}
	var result []reflect.Value
	switch argCount := reflect.TypeOf(handler.printFunc.Interface()).NumIn(); argCount {
	case 2:
		result = handler.printFunc.Call([]reflect.Value{
			reflect.ValueOf(internalVersion),
			reflect.ValueOf(generateOpts),
		})
	case 3:
		result = handler.printFunc.Call([]reflect.Value{
			reflect.ValueOf(context.Background()),
			reflect.ValueOf(internalVersion),
			reflect.Zero(reflect.TypeOf(&unstructured.Unstructured{})),
		})
	default:
		ph.log.Error("Unexpected argument count for print func, exepected to or three", zap.Int("arg_count", argCount))
		return nil, nil
	}
	rowsVal, errVal := result[0], result[1]
	if v := errVal.Interface(); v != nil {
		err := v.(error)
		return nil, fmt.Errorf("printFunc failed: %w", err)
	}
	var rows []metav1.TableRow
	switch v := rowsVal.Interface().(type) {
	case []metav1.TableRow:
		rows = v
	case *metav1.Table:
		rows = v.Rows
	default:
		return nil, fmt.Errorf("printFunc returned unexepcted type %T", v)
	}
	for idx := range rows {
		gvk := o.GetObjectKind().GroupVersionKind()
		gvk.Kind = strings.TrimSuffix(gvk.Kind, "List")
		externalVersion, err := legacyscheme.Scheme.New(gvk)
		if err != nil {
			return nil, fmt.Errorf("failed to get an object from scheme for %s: %w", gvk, err)
		}
		if err := legacyscheme.Scheme.Convert(rows[idx].Object.Object, externalVersion, nil); err != nil {
			return nil, fmt.Errorf("failed to convert embedded object to external version: %w", err)
		}
		externalVersion.(gvkSetter).SetGroupVersionKind(gvk)
		rows[idx].Object = runtime.RawExtension{Object: externalVersion}
	}
	return &metav1.Table{
		TypeMeta: metav1.TypeMeta{
			APIVersion: "meta.k8s.io/" + tableVersion,
			Kind:       "Table",
		},
		ColumnDefinitions: handler.columnDefinitions,
		Rows:              rows,
	}, nil
}
func ( ph * printHandler ) printInternal ( tableVersion string , o runtime . Object ) ( * metav1 . Table , error ) { internalVersion , err := legacyscheme . Scheme . New ( schema . GroupVersionKind { Group : o . GetObjectKind ( ) . GroupVersionKind ( ) . Group , Kind : o . GetObjectKind ( ) . GroupVersionKind ( ) . Kind , Version : runtime . APIVersionInternal } ) if err != nil { return nil , nil } handler , ok := ph . handlers [ reflect . TypeOf ( internalVersion ) ] if ! ok { ph . log . Info ( " " , zap . String ( " " , fmt . Sprintf ( " " , internalVersion ) ) ) return nil , nil } ph . log . Info ( " " , zap . String ( " " , fmt . Sprintf ( " " , internalVersion ) ) ) if err := legacyscheme . Scheme . Convert ( o , internalVersion , nil ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } generateOpts := printers . GenerateOptions { Wide : true } var result [ ] reflect . Value switch argCount := reflect . TypeOf ( handler . printFunc . Interface ( ) ) . NumIn ( ) ; argCount { case 2 : result = handler . printFunc . Call ( [ ] reflect . Value { reflect . ValueOf ( internalVersion ) , reflect . ValueOf ( generateOpts ) , } ) case 3 : result = handler . printFunc . Call ( [ ] reflect . Value { reflect . ValueOf ( context . Background ( ) ) , reflect . ValueOf ( internalVersion ) , reflect . Zero ( reflect . TypeOf ( & unstructured . Unstructured { } ) ) , } ) default : ph . log . Error ( " " , zap . Int ( " " , argCount ) ) return nil , nil } rowsVal , errVal := result [ 0 ] , result [ 1 ] if v := errVal . Interface ( ) ; v != nil { err := v . ( error ) return nil , fmt . Errorf ( " " , err ) } var rows [ ] metav1 . TableRow switch v := rowsVal . Interface ( ) . ( type ) { case [ ] metav1 . TableRow : rows = v case * metav1 . Table : rows = v . Rows default : return nil , fmt . Errorf ( " " , v ) } for idx := range rows { gvk := o . GetObjectKind ( ) . GroupVersionKind ( ) gvk . Kind = strings . TrimSuffix ( gvk . Kind , " " ) externalVersion , err := legacyscheme . Scheme . New ( gvk ) if err != nil { return nil , fmt . Errorf ( " " , gvk , err ) } if err := legacyscheme . Scheme . Convert ( rows [ idx ] . Object . Object , externalVersion , nil ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } externalVersion . ( gvkSetter ) . SetGroupVersionKind ( gvk ) rows [ idx ] . Object = runtime . RawExtension { Object : externalVersion } } return & metav1 . Table { TypeMeta : metav1 . TypeMeta { APIVersion : " " + tableVersion , Kind : " " , } , ColumnDefinitions : handler . columnDefinitions , Rows : rows , } , nil }
printInternal prints using an imported table printer.
printInternal prints using an imported table printer .
// Can be literally anything, but needs a concrete type, ValueOf(runtime.Object(nil) // results in a zero reflect.Value. // We have to convert the embedded object back to the external version