1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-05 15:37:19 +00:00
kyverno/pkg/utils/policy/marshal.go
Charles-Edouard Brétéché 1efcd40d04
fix: file name (#6523)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-03-09 22:17:26 +00:00

24 lines
656 B
Go

package policy
import (
"encoding/json"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
"sigs.k8s.io/yaml"
)
// ToJson marshals a policy into corresponding json bytes.
func ToJson(policy kyvernov1.PolicyInterface) ([]byte, error) {
return json.Marshal(policy)
}
// ToYaml marshals a policy into corresponding yaml bytes.
// If firsts converts the policy to json because some internal structures have
// custom json marshalling functions, then it converts json to yaml.
func ToYaml(policy kyvernov1.PolicyInterface) ([]byte, error) {
jsonBytes, err := ToJson(policy)
if err != nil {
return nil, err
}
return yaml.JSONToYAML(jsonBytes)
}