Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go back to using --omitNull instead of --omitEmpty #110

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Go back to using --omitNull instead of --omitEmpty
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.
  • Loading branch information
Gabriella439 committed Jan 30, 2020
commit 80bc0021c5708af784ffcfe51a9dae145a9a673a
The diff you're trying to view is too large. We only load the first 3000 changed files.
56 changes: 34 additions & 22 deletions 1.12/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ In the following example, we:
-- examples/deploymentSimple.dhall

let kubernetes =
../package.dhall sha256:ce1e73deebf8c4eb513bfc736adfd924fe696ffee486f6f4bd81ed281bbf0f2a
../package.dhall sha256:d545c49903546ab1b4186886c78afec2c406200c42be38a33b15fd1c71acaa9d

let deployment =
kubernetes.Deployment::{
, metadata = kubernetes.ObjectMeta::{ name = "nginx" }
, spec = Some kubernetes.DeploymentSpec::{
, selector = kubernetes.LabelSelector::{
, matchLabels = Some (toMap { name = "nginx" })
}
, replicas = Some 2
, template = kubernetes.PodTemplateSpec::{
, metadata = kubernetes.ObjectMeta::{ name = "nginx" }
Expand All @@ -67,7 +70,8 @@ let deployment =
[ kubernetes.Container::{
, name = "nginx"
, image = Some "nginx:1.15.3"
, ports = [ kubernetes.ContainerPort::{ containerPort = 80 } ]
, ports = Some
[ kubernetes.ContainerPort::{ containerPort = 80 } ]
}
]
}
Expand All @@ -82,7 +86,7 @@ in deployment
We then run this through `dhall-to-yaml` to generate our Kubernetes definition:

```bash
dhall-to-yaml --omit-empty < examples/deploymentSimple.dhall
dhall-to-yaml < examples/deploymentSimple.dhall
```

And we get:
Expand All @@ -95,6 +99,9 @@ metadata:
name: nginx
spec:
replicas: 2
selector:
matchLabels:
name: nginx
template:
metadata:
name: nginx
Expand Down Expand Up @@ -130,7 +137,7 @@ Things to note in the following example:
them over the list of services.
- we also defined the list of `services` inline, but you should instead return the
`mkIngress` function instead of applying it, so you can do something like
`dhall-to-yaml --omit-empty <<< "./mkIngress.dhall ./myServices.dhall"`
`dhall-to-yaml <<< "./mkIngress.dhall ./myServices.dhall"`

```dhall
-- examples/ingress.dhall
Expand All @@ -140,10 +147,8 @@ let Prelude =

let map = Prelude.List.map

let kv = Prelude.JSON.keyText

let kubernetes =
../package.dhall sha256:ce1e73deebf8c4eb513bfc736adfd924fe696ffee486f6f4bd81ed281bbf0f2a
../package.dhall sha256:d545c49903546ab1b4186886c78afec2c406200c42be38a33b15fd1c71acaa9d

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

Expand All @@ -152,7 +157,7 @@ let services = [ { name = "foo", host = "foo.example.com", version = "2.3" } ]
let makeTLS
: Service → kubernetes.IngressTLS.Type
= λ(service : Service)
→ { hosts = [ service.host ]
→ { hosts = Some [ service.host ]
, secretName = Some "${service.name}-certificate"
}

Expand All @@ -176,9 +181,10 @@ let mkIngress
: List Service → kubernetes.Ingress.Type
= λ(inputServices : List Service)
→ let annotations =
[ kv "kubernetes.io/ingress.class" "nginx"
, kv "kubernetes.io/ingress.allow-http" "false"
]
toMap
{ `kubernetes.io/ingress.class` = "nginx"
, `kubernetes.io/ingress.allow-http` = "false"
}

let defaultService =
{ name = "default"
Expand All @@ -190,20 +196,26 @@ let mkIngress

let spec =
kubernetes.IngressSpec::{
, tls =
map Service kubernetes.IngressTLS.Type makeTLS ingressServices
, rules =
map
Service
kubernetes.IngressRule.Type
makeRule
ingressServices
, tls = Some
( map
Service
kubernetes.IngressTLS.Type
makeTLS
ingressServices
)
, rules = Some
( map
Service
kubernetes.IngressRule.Type
makeRule
ingressServices
)
}

in kubernetes.Ingress::{
, metadata = kubernetes.ObjectMeta::{
, name = "nginx"
, annotations = annotations
, annotations = Some annotations
}
, spec = Some spec
}
Expand All @@ -215,7 +227,7 @@ in mkIngress services
As before we get the yaml out by running:

```bash
dhall-to-yaml --omit-empty < examples/ingress.dhall
dhall-to-yaml < examples/ingress.dhall
```

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

```bash
dhall-to-yaml --documents --omit-empty <<< "let a = ./examples/deploymentSimple.dhall in [a, a]"
dhall-to-yaml --documents <<< "let a = ./examples/deploymentSimple.dhall in [a, a]"
```

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