copy object meta to new object
When copy from an unstructured to an object type, copy the object
metadata explicitly
re
@@ -10,6 +10,8 @@ import (
"github.com/heptio/developer-dash/internal/printers"
"github.com/heptio/developer-dash/internal/view"
"github.com/pkg/errors"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/clock"
@@ -85,7 +87,7 @@ func (d *ListDescriber) Describe(ctx context.Context, prefix, namespace string,
return emptyContentResponse, err
}
- setItemName(item, object.GetName())
+ copyObjectMeta(item, object)
newSlice := reflect.Append(f, reflect.ValueOf(item).Elem())
f.Set(newSlice)
@@ -157,8 +159,9 @@ func (d *ObjectDescriber) Describe(ctx context.Context, prefix, namespace string
return emptyContentResponse, err
}
+ copyObjectMeta(item, object)
+
objectName := object.GetName()
- setItemName(item, objectName)
var title string
@@ -217,6 +220,39 @@ func setItemName(item interface{}, name string) {
setName(name)
}
+func copyObjectMeta(to interface{}, from *unstructured.Unstructured) error {
+ object, ok := to.(metav1.Object)
+ if !ok {
+ return errors.Errorf("%T is not an object", to)
+ }
+
+ typeMeta := metav1.TypeMeta{
+ Kind: from.GetKind(),
+ APIVersion: from.GetAPIVersion(),
+ }
+
+ reflect.ValueOf(object).Elem().FieldByName("TypeMeta").Set(reflect.ValueOf(typeMeta))
+
+ object.SetNamespace(from.GetNamespace())
+ object.SetName(from.GetName())
+ object.SetGenerateName(from.GetGenerateName())
+ object.SetUID(from.GetUID())
+ object.SetResourceVersion(from.GetResourceVersion())
+ object.SetGeneration(from.GetGeneration())
+ object.SetSelfLink(from.GetSelfLink())
+ object.SetCreationTimestamp(from.GetCreationTimestamp())
+ object.SetDeletionTimestamp(from.GetDeletionTimestamp())
+ object.SetDeletionGracePeriodSeconds(from.GetDeletionGracePeriodSeconds())
+ object.SetLabels(from.GetLabels())
+ object.SetAnnotations(from.GetAnnotations())
+ object.SetInitializers(from.GetInitializers())
+ object.SetOwnerReferences(from.GetOwnerReferences())
+ object.SetClusterName(from.GetClusterName())
+ object.SetFinalizers(from.GetFinalizers())
+
+ return nil
+}
+
func printObject(object runtime.Object, transformFunc func(*metav1beta1.Table) error) error {
options := kprinters.PrintOptions{
Wide: true,
