I have a file: blueprint.dhall
which contains a default kubernetes.Pod
according to the types in dhall-kubernetes/package.dhall at v6.0.0 · dhall-lang/dhall-kubernetes · GitHub
I have several files that will modify this default pod, e.g. by adding another container to it.
This means to update a list inside the optional spec
field in the pod
record, dhall-kubernetes/io.k8s.api.core.v1.Pod.dhall at v6.0.0 · dhall-lang/dhall-kubernetes · GitHub.
This is my approach:
let addOrMergeContainerToPod : kubernetes.Container.Type -> kubernetes.Pod.Type -> kubernetes.Pod.Type =
\(c : kubernetes.Container.Type) ->
\(p : kubernetes.Pod.Type) ->
p with spec =
(
if Prelude.Optional.null kubernetes.PodSpec.Type p.spec != True
then Prelude.Optional.map kubernetes.PodSpec.Type kubernetes.PodSpec.Type (\(spec : kubernetes.PodSpec.Type) -> spec with containers = [c] # spec.containers) p.spec
else Some kubernetes.PodSpec::{containers = [c] }
)
But this feels cumbersome.
Is there a smarter approach?