I'm attempting to migrate a helm/kubernetes codebase to dhall-kubernetes. Dhall is typed, so I need to provide full records with optional fields set to null if there were not set. So I'm looking for something like kubectl get objname id -o yaml
, but I need it to output all optional fields like fieldName: null
. Is there a way to accomplish this? I don't know how to do it, so as a plan B I wrote dhall-default and I attempt to approach it in a different way.
Is it possible to get a kubernetes object in json or yaml with all optional fields explicitly set to null?
1k Views Asked by dredozubov At
1
I'll turn @sjakobi's solution into an answer like @dredozubov suggested
You can pass the desired type from
dhall-kubernetes
toyaml-to-dhall
and it will generate the equivalent Dhall code, albeit without any simplifications.As an example, suppose that you have the following Kubernetes resource:
... and the following Dhall type for a Kubernetes deployment:
Then you can translate the YAML to Dhall by running:
The output is a bit large (~1300 lines), because
yaml-to-dhall
doesn't yet take advantage of support for default values, so I won't include the output here.If you pipe the result back into
dhall-to-yaml
then you will get the original Resource (albeit with fields sorted):... and if you supply the
--preserve-null
option todhall-to-yaml
it will preserve allnull
fields as the question requests: