1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 07:57:07 +00:00
kyverno/ext/resource/convert/convert.go
Charles-Edouard Brétéché 32d16059be
refactor: move resource/convert in ext (#8769)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-10-29 10:39:39 +01:00

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
}