Skip to content

Commit 381306b

Browse files
authored
Go back to using --omitNull instead of --omitEmpty (#110)
Fixes #86 The motivation of this is to more accurately model the Kubernetes API semantics by not auto-omitting empty fields. This is because a field set to `Some ([] : List T)` is not necessarily the same as `None (List T)`. This makes the typical case a bit more verbose (more `Some`s), but the difference to the `./examples` shows that it's not too bad.
1 parent 3e160f4 commit 381306b

File tree

3,808 files changed

+15397
-17685
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,808 files changed

+15397
-17685
lines changed

1.12/README.md

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ In the following example, we:
5353
-- examples/deploymentSimple.dhall
5454

5555
let kubernetes =
56-
../package.dhall sha256:ce1e73deebf8c4eb513bfc736adfd924fe696ffee486f6f4bd81ed281bbf0f2a
56+
../package.dhall sha256:d545c49903546ab1b4186886c78afec2c406200c42be38a33b15fd1c71acaa9d
5757

5858
let deployment =
5959
kubernetes.Deployment::{
6060
, metadata = kubernetes.ObjectMeta::{ name = "nginx" }
6161
, spec = Some kubernetes.DeploymentSpec::{
62+
, selector = kubernetes.LabelSelector::{
63+
, matchLabels = Some (toMap { name = "nginx" })
64+
}
6265
, replicas = Some 2
6366
, template = kubernetes.PodTemplateSpec::{
6467
, metadata = kubernetes.ObjectMeta::{ name = "nginx" }
@@ -67,7 +70,8 @@ let deployment =
6770
[ kubernetes.Container::{
6871
, name = "nginx"
6972
, image = Some "nginx:1.15.3"
70-
, ports = [ kubernetes.ContainerPort::{ containerPort = 80 } ]
73+
, ports = Some
74+
[ kubernetes.ContainerPort::{ containerPort = 80 } ]
7175
}
7276
]
7377
}
@@ -82,7 +86,7 @@ in deployment
8286
We then run this through `dhall-to-yaml` to generate our Kubernetes definition:
8387

8488
```bash
85-
dhall-to-yaml --omit-empty < examples/deploymentSimple.dhall
89+
dhall-to-yaml < examples/deploymentSimple.dhall
8690
```
8791

8892
And we get:
@@ -95,6 +99,9 @@ metadata:
9599
name: nginx
96100
spec:
97101
replicas: 2
102+
selector:
103+
matchLabels:
104+
name: nginx
98105
template:
99106
metadata:
100107
name: nginx
@@ -130,7 +137,7 @@ Things to note in the following example:
130137
them over the list of services.
131138
- we also defined the list of `services` inline, but you should instead return the
132139
`mkIngress` function instead of applying it, so you can do something like
133-
`dhall-to-yaml --omit-empty <<< "./mkIngress.dhall ./myServices.dhall"`
140+
`dhall-to-yaml <<< "./mkIngress.dhall ./myServices.dhall"`
134141

135142
```dhall
136143
-- examples/ingress.dhall
@@ -140,10 +147,8 @@ let Prelude =
140147

141148
let map = Prelude.List.map
142149

143-
let kv = Prelude.JSON.keyText
144-
145150
let kubernetes =
146-
../package.dhall sha256:ce1e73deebf8c4eb513bfc736adfd924fe696ffee486f6f4bd81ed281bbf0f2a
151+
../package.dhall sha256:d545c49903546ab1b4186886c78afec2c406200c42be38a33b15fd1c71acaa9d
147152

148153
let Service = { name : Text, host : Text, version : Text }
149154

@@ -152,7 +157,7 @@ let services = [ { name = "foo", host = "foo.example.com", version = "2.3" } ]
152157
let makeTLS
153158
: Service kubernetes.IngressTLS.Type
154159
= λ(service : Service)
155-
{ hosts = [ service.host ]
160+
{ hosts = Some [ service.host ]
156161
, secretName = Some "${service.name}-certificate"
157162
}
158163

@@ -176,9 +181,10 @@ let mkIngress
176181
: List Service kubernetes.Ingress.Type
177182
= λ(inputServices : List Service)
178183
let annotations =
179-
[ kv "kubernetes.io/ingress.class" "nginx"
180-
, kv "kubernetes.io/ingress.allow-http" "false"
181-
]
184+
toMap
185+
{ `kubernetes.io/ingress.class` = "nginx"
186+
, `kubernetes.io/ingress.allow-http` = "false"
187+
}
182188

183189
let defaultService =
184190
{ name = "default"
@@ -190,20 +196,26 @@ let mkIngress
190196

191197
let spec =
192198
kubernetes.IngressSpec::{
193-
, tls =
194-
map Service kubernetes.IngressTLS.Type makeTLS ingressServices
195-
, rules =
196-
map
197-
Service
198-
kubernetes.IngressRule.Type
199-
makeRule
200-
ingressServices
199+
, tls = Some
200+
( map
201+
Service
202+
kubernetes.IngressTLS.Type
203+
makeTLS
204+
ingressServices
205+
)
206+
, rules = Some
207+
( map
208+
Service
209+
kubernetes.IngressRule.Type
210+
makeRule
211+
ingressServices
212+
)
201213
}
202214

203215
in kubernetes.Ingress::{
204216
, metadata = kubernetes.ObjectMeta::{
205217
, name = "nginx"
206-
, annotations = annotations
218+
, annotations = Some annotations
207219
}
208220
, spec = Some spec
209221
}
@@ -215,7 +227,7 @@ in mkIngress services
215227
As before we get the yaml out by running:
216228

217229
```bash
218-
dhall-to-yaml --omit-empty < examples/ingress.dhall
230+
dhall-to-yaml < examples/ingress.dhall
219231
```
220232

221233
Result:
@@ -264,7 +276,7 @@ If the objects have the same type, this is very easy: you return a Dhall list co
264276
objects, and use the `--documents` flag, e.g.:
265277

266278
```bash
267-
dhall-to-yaml --documents --omit-empty <<< "let a = ./examples/deploymentSimple.dhall in [a, a]"
279+
dhall-to-yaml --documents <<< "let a = ./examples/deploymentSimple.dhall in [a, a]"
268280
```
269281

270282
If the objects are of different type, it's not possible to have separate documents in the same YAML file.

0 commit comments

Comments
 (0)