Skip to content

Commit

Permalink
Export informer Restructure and Destruct functions
Browse files Browse the repository at this point in the history
  • Loading branch information
guicassolato committed Jul 15, 2024
1 parent 08c079e commit e3be302
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions controller/informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ func For[T RuntimeObject](resource schema.GroupVersionResource, namespace string
controller.delete(obj)
},
})
informer.SetTransform(restructure[T])
informer.SetTransform(Restructure[T])
return informer
}
}

func restructure[T any](obj any) (any, error) {
func Restructure[T any](obj any) (any, error) {
unstructuredObj, ok := obj.(*unstructured.Unstructured)
if !ok {
return nil, fmt.Errorf("unexpected object type: %T", obj)
Expand All @@ -107,3 +107,11 @@ func restructure[T any](obj any) (any, error) {
}
return o, nil
}

func Destruct[T any](obj T) (*unstructured.Unstructured, error) {
u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&obj)
if err != nil {
return nil, err
}
return &unstructured.Unstructured{Object: u}, nil
}

0 comments on commit e3be302

Please sign in to comment.