1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-10 09:56:55 +00:00
kyverno/cmd/cli/kubectl-kyverno/resource/convert/convert.go
Charles-Edouard Brétéché 4046315dac
feat: add a package to convert unstructured into typed (#8484)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-21 09:34:38 +00: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
}