Closed DreamingRaven closed 10 months ago
/kind support
Controller-Runtime does not support using yaml encoding when communicating with the k8s apiserver, it uses protobuf or json in the case of CRDs.
How you do or do not serialize your types outside of controller-runtime is your decision. Given that json is valid yaml however, I strongly recommend to not use custom yaml de/encoding logic, as it will silently do the wrong thing when reading a json-serialized object.
Thanks for following up, unfortunately I have had to do just this. I now have to treat the blueprints from authentik as multi line strings to avoid them being mutated outside of my code since they require these custom yaml tags as is much to my chagrin. I wish it wasn't the case unfortunately, handling custom yaml tags in go is a bit of a nightmare.
I wanted to properly unmarshal into non strings to provide more structure to end users but as you say it fails silently. Thanks again for the follow up.
I have an issue where I want to support custom YAML tags for a library I am creating an operator for (https://gitlab.com/GeorgeRaven/authentik-manager).
To do so I created a custom type so I could handle the custom logic required for these yaml tags like !Find:
My custom type is called Raw and its only purpose is to maintain the yaml tags as strings so that they can be given to authentik. To do so I base Raw on yaml.v3 nodes since these allow finer grained control to handle these tags which AFAIK yaml.v2 which the k8s forks based on https://github.com/ghodss/yaml do not.
Unmarshalling and marshalling of my API type works almost as expected with yaml.v3 funcs as you'd expect since it's based off of yaml.Nodes (minus a subslice that I need to add support for, and the k8s specific object meta):
produces:
However using the k8s sigs yaml "sigs.k8s.io/yaml" used in the kubebuilder controller (mocked in tests):
Results in losing the !Find custom yaml tags:
What is the best way to incorporate the yaml.v3 node functionality in a controller-runtime based controller so that I can handle custom Yaml tags? Thanks, any information would be much appreciated!
Edit: I realise there may be a lot of context missing here but it is quite a multi-level problem as I see it, if you would like any information on specifics please let me know, but broadly I want to handle Yaml tags myself or by go-yaml v3 without having the controller runtime mutate them on Get.