mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 07:57:07 +00:00
18 lines
482 B
Go
18 lines
482 B
Go
package convert
|
|
|
|
import (
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
)
|
|
|
|
func Into[T any](untyped unstructured.Unstructured, result *T) error {
|
|
return runtime.DefaultUnstructuredConverter.FromUnstructuredWithValidation(untyped.UnstructuredContent(), result, true)
|
|
}
|
|
|
|
func To[T any](untyped unstructured.Unstructured) (*T, error) {
|
|
var result T
|
|
if err := Into(untyped, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|