Hi,
I am switching codebase from using K8 Kustomize to Dhall.
I’m using https://github.com/dhall-lang/dhall-kubernetes for this, however, I’m having an issue with overriding env variables deep in K8 Deployment.
Basically, I cannot use with
to override env variables for a deployment, because deployment.spec
is Optional
. If I try using with
, I get: Error: ❰with❱ only works on records
Only working solution is to convert everything to lambda:
let mkContainer = \(envVars : List k8.EnvVar.Type) -> k8.Container :: {
name = "service_name",
image = Some "image_name",
command = Some ["python", "service_path"],
env = Some envVars,
}
let mkPodSpec = \(envVars : List k8.EnvVar.Type) -> k8.PodSpec :: {
serviceAccountName = Some "service_account",
containers = [mkContainer envVars]
}
let mkPodTemplateSpec = \(envVars : List k8.EnvVar.Type) -> k8.PodTemplateSpec::{
spec = Some (mkPodSpec envVars)
}
let selector = k8.LabelSelector :: {
matchLabels = Some [{
mapKey = "tier",
mapValue = "backend"
},
{
mapKey="name",
mapValue="service_name"
}]
}
let makeDeployment = \(envVars : List k8.EnvVar.Type) -> k8.Deployment :: {
metadata = k8.ObjectMeta::{
name = Some "serice_name",
labels = Some [{
mapKey="tier",
mapValue="backend"
},
{
mapKey="name",
mapValue="service_name"
}],
},
spec = Some k8.DeploymentSpec::{
replicas = Some +1,
strategy = Some strategy,
selector = selector,
template = mkPodTemplateSpec envVars,
}
}
in makeDeployment
However, this does not scale well, I am not sure what part of “default” deployment will need to be adjusted in the future.
Are there any best practices for updating such nested Optionals and Lists?