Use TypeAccessor to access object type metadata
@@ -10,6 +10,7 @@ import (
"github.com/heptio/developer-dash/internal/printers"
"github.com/heptio/developer-dash/internal/view"
"github.com/pkg/errors"
+ "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
@@ -159,7 +160,9 @@ func (d *ObjectDescriber) Describe(ctx context.Context, prefix, namespace string
return emptyContentResponse, err
}
- copyObjectMeta(item, object)
+ if err := copyObjectMeta(item, object); err != nil {
+ return emptyContentResponse, errors.Wrapf(err, "copying object metadata")
+ }
objectName := object.GetName()
@@ -226,12 +229,12 @@ func copyObjectMeta(to interface{}, from *unstructured.Unstructured) error {
return errors.Errorf("%T is not an object", to)
}
- typeMeta := metav1.TypeMeta{
- Kind: from.GetKind(),
- APIVersion: from.GetAPIVersion(),
+ t, err := meta.TypeAccessor(object)
+ if err != nil {
+ return errors.Wrapf(err, "accessing type meta")
}
-
- reflect.ValueOf(object).Elem().FieldByName("TypeMeta").Set(reflect.ValueOf(typeMeta))
+ t.SetAPIVersion(from.GetAPIVersion())
+ t.SetKind(from.GetObjectKind().GroupVersionKind().Kind)
object.SetNamespace(from.GetNamespace())
object.SetName(from.GetName())
