Skip to content

Commit

Permalink
set APIVersion/Kind if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
dprotaso committed Jun 9, 2021
1 parent 1bd0419 commit 29933b1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions injection/clients/dynamicclient/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ func ToUnstructured(sch *runtime.Scheme, objs []runtime.Object) (us []runtime.Ob
for _, obj := range objs {
// Don't mess with the primary copy
obj = obj.DeepCopyObject()
// Determine and set the TypeMeta for this object based on our test scheme.
gvks, _, err := sch.ObjectKinds(obj)
if err != nil {
panic("Unable to determine kind for type: " + err.Error())
}
apiv, k := gvks[0].ToAPIVersionAndKind()

ta, err := meta.TypeAccessor(obj)
if err != nil {
panic("Unable to create type accessor: " + err.Error())
}
ta.SetAPIVersion(apiv)
ta.SetKind(k)
if ta.GetAPIVersion() == "" || ta.GetKind() == "" {
// Determine and set the TypeMeta for this object based on our test scheme.
gvks, _, err := sch.ObjectKinds(obj)
if err != nil {
panic("Unable to determine kind for type: " + err.Error())
}
apiv, k := gvks[0].ToAPIVersionAndKind()
ta.SetAPIVersion(apiv)
ta.SetKind(k)
}

b, err := json.Marshal(obj)
if err != nil {
Expand Down

0 comments on commit 29933b1

Please sign in to comment.