1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/pkg/utils/policy/mashal.go
Charles-Edouard Brétéché 4984c5c878
feat: create a policy utils package (#5473)
* feat: create a policy utils package

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* added comment

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2022-11-25 13:46:02 +01: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)
}