You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In porch and Nephio projects we utilize the kpt-fn-sdk to manipulate KRM objects stored in YAML files, but we also rely on sigs.k8s.io/kustomize/kyaml, especially sigs.k8s.io/kustomize/kyaml/kio to read/write the YAML data to various abstractions.
That requires us to convert back and forth between fn.KubeObject and yaml.RNode, however this conversion is not natively supported by either libraries. We have to use workarounds, like round-trip Marshall/Unmarshall, e.g.:
// AsRNode converts a KubeObject to a yaml.RNode
func AsRNode(obj *fn.KubeObject) (*yaml.RNode, error) {
// TODO: remove the need for this unnecessary round-trip marshalling by adding a direct conversion method to KubeObject
return yaml.Parse(obj.String())
}
This is both inefficient and also sometimes inadvertently changes the YAML formatting . Having native KubeObject methods and SDK functions for these conversions would help our projects to write better code.
The text was updated successfully, but these errors were encountered:
I already have an implementation proposal to solve this problem that you can cherry-pick from here: nokia/kpt-functions-sdk@08ebcb3 (I cannot send a PR, since my employer doesn't allow me to sign the CLA)
My implementation provides two sets of conversion functions:
copy-style conversions (NewKubeObjectFromResourceNode, CopyToResourceNode) do a deep copy of the internal yaml nodes, thus preventing the RNode and the KubeObject to modify each other's internal state
move-style conversions (MoveToResourceNode, MoveToKubeObject) transfer the internal YAML nodes from the source object to the destination, and clear the source object by setting it to empty, thus preventing the RNode and the KubeObject to modify each other's internal state
In porch and Nephio projects we utilize the kpt-fn-sdk to manipulate KRM objects stored in YAML files, but we also rely on sigs.k8s.io/kustomize/kyaml, especially sigs.k8s.io/kustomize/kyaml/kio to read/write the YAML data to various abstractions.
That requires us to convert back and forth between
fn.KubeObject
andyaml.RNode
, however this conversion is not natively supported by either libraries. We have to use workarounds, like round-trip Marshall/Unmarshall, e.g.:This is both inefficient and also sometimes inadvertently changes the YAML formatting . Having native KubeObject methods and SDK functions for these conversions would help our projects to write better code.
The text was updated successfully, but these errors were encountered: