Skip to content

Commit 7af2ab5

Browse files
gregzieganGabriella439
authored andcommitted
Prefer "schema" syntax for examples (#93)
* Also update to the latest version of `dhall` * Also fix `./scripts/generate.sh` to generate the `schemas*` files
1 parent fee24c0 commit 7af2ab5

File tree

1,444 files changed

+5407
-10193
lines changed

Some content is hidden

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

1,444 files changed

+5407
-10193
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ build: README.md
1111
dhall freeze --all --inplace ./types.dhall
1212
dhall freeze --all --inplace ./typesUnion.dhall
1313
dhall freeze --all --inplace ./defaults.dhall
14+
dhall freeze --all --inplace ./schemas.dhall
1415
check: build
1516
LC_ALL=en_US.UTF-8 ./scripts/check-source.py
1617
mkdir -p tmp
1718
LC_ALL=en_US.UTF-8 ./scripts/build-examples.py tmp
1819
install: build
19-
cp -r types defaults "${out}"
20-
cp types.dhall defaults.dhall typesUnion.dhall "${out}"
20+
cp -r types defaults schemas "${out}"
21+
cp types.dhall defaults.dhall typesUnion.dhall schemas.dhall "${out}"
2122
cp README.md "${out}"
2223

README.md

Lines changed: 109 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@ or the [full tutorial][dhall-tutorial].
3030

3131
## Prerequisites
3232

33-
**NOTE**: `dhall-kubernetes` requires at least version `1.23.0` of [the interpreter](https://github.com/dhall-lang/dhall-haskell)
34-
(version `7.0.0` of the language).
35-
36-
You can install the latest version with the following [stack][stack] command:
37-
```bash
38-
stack install dhall-1.23.0 dhall-json-1.2.8 --resolver=nightly-2019-05-13
39-
```
33+
**NOTE**: `dhall-kubernetes` requires at least version `1.27.0` of [the interpreter](https://github.com/dhall-lang/dhall-haskell)
34+
(version `11.0.0` of the language).
4035

4136
## Quickstart - a simple Deployment
4237

@@ -61,47 +56,37 @@ In the following example, we:
6156
```haskell
6257
-- examples/deploymentSimple.dhall
6358

64-
let types =
65-
../types.dhall sha256:e48e21b807dad217a6c3e631fcaf3e950062310bfb4a8bbcecc330eb7b2f60ed
66-
67-
let defaults =
68-
../defaults.dhall sha256:4450e23dc81975d111650e06c0238862944bf699537af6cbacac9c7e471dfabe
69-
70-
let deployment
71-
: types.Deployment
72-
= defaults.Deployment
73-
// { metadata =
74-
defaults.ObjectMeta // { name = "nginx" }
75-
, spec =
76-
Some
77-
( defaults.DeploymentSpec
78-
// { replicas =
79-
Some 2
80-
, template =
81-
defaults.PodTemplateSpec
82-
// { metadata =
83-
defaults.ObjectMeta // { name = "nginx" }
84-
, spec =
85-
Some
86-
( defaults.PodSpec
87-
// { containers =
88-
[ defaults.Container
89-
// { name =
90-
"nginx"
91-
, image =
92-
Some "nginx:1.15.3"
93-
, ports =
94-
[ defaults.ContainerPort
95-
// { containerPort = 80 }
96-
]
97-
}
98-
]
99-
}
100-
)
59+
let kubernetes =
60+
../schemas.dhall sha256:9704063d1e2d17050cb18afae199a24f4cd1264e6c8e696ca94781309e213785
61+
62+
let deployment =
63+
kubernetes.Deployment::{
64+
, metadata = kubernetes.ObjectMeta::{ name = "nginx" }
65+
, spec =
66+
Some
67+
kubernetes.DeploymentSpec::{
68+
, replicas = Some 2
69+
, template =
70+
kubernetes.PodTemplateSpec::{
71+
, metadata = kubernetes.ObjectMeta::{ name = "nginx" }
72+
, spec =
73+
Some
74+
kubernetes.PodSpec::{
75+
, containers =
76+
[ kubernetes.Container::{
77+
, name = "nginx"
78+
, image = Some "nginx:1.15.3"
79+
, ports =
80+
[ kubernetes.ContainerPort::{
81+
, containerPort = 80
82+
}
83+
]
10184
}
102-
}
103-
)
104-
}
85+
]
86+
}
87+
}
88+
}
89+
}
10590

10691
in deployment
10792

@@ -119,19 +104,19 @@ And we get:
119104

120105
apiVersion: apps/v1
121106
kind: Deployment
107+
metadata:
108+
name: nginx
122109
spec:
110+
replicas: 2
123111
template:
124-
spec:
125-
containers:
126-
- image: nginx:1.15.3
127-
name: nginx
128-
ports:
129-
- containerPort: 80
130112
metadata:
131113
name: nginx
132-
replicas: 2
133-
metadata:
134-
name: nginx
114+
spec:
115+
containers:
116+
- image: nginx:1.15.3
117+
name: nginx
118+
ports:
119+
- containerPort: 80
135120

136121
```
137122

@@ -165,84 +150,74 @@ Things to note in the following example:
165150

166151
let Prelude = ../Prelude.dhall
167152

168-
let map = Prelude.`List`.map
153+
let map = Prelude.List.map
169154

170155
let kv = Prelude.JSON.keyText
171156

172157
let types =
173158
../types.dhall sha256:e48e21b807dad217a6c3e631fcaf3e950062310bfb4a8bbcecc330eb7b2f60ed
174159

175-
let defaults =
176-
../defaults.dhall sha256:4450e23dc81975d111650e06c0238862944bf699537af6cbacac9c7e471dfabe
160+
let kubernetes =
161+
../schemas.dhall sha256:9704063d1e2d17050cb18afae199a24f4cd1264e6c8e696ca94781309e213785
177162

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

180165
let services = [ { name = "foo", host = "foo.example.com", version = "2.3" } ]
181166

182167
let makeTLS
183-
: Service -> types.IngressTLS
184-
= \(service : Service)
185-
-> { hosts =
186-
[ service.host ]
187-
, secretName =
188-
Some "${service.name}-certificate"
189-
}
168+
: Service types.IngressTLS
169+
= λ(service : Service)
170+
{ hosts = [ service.host ]
171+
, secretName = Some "${service.name}-certificate"
172+
}
190173

191174
let makeRule
192-
: Service -> types.IngressRule
193-
= \(service : Service)
194-
-> { host =
195-
Some service.host
196-
, http =
197-
Some
175+
: Service types.IngressRule
176+
= λ(service : Service)
177+
{ host = Some service.host
178+
, http =
179+
Some
198180
{ paths =
199181
[ { backend =
200-
{ serviceName =
201-
service.name
202-
, servicePort =
203-
types.IntOrString.Int 80
182+
{ serviceName = service.name
183+
, servicePort = types.IntOrString.Int 80
204184
}
205-
, path =
206-
None Text
185+
, path = None Text
207186
}
208187
]
209188
}
210-
}
189+
}
211190

212191
let mkIngress
213-
: List Service -> types.Ingress
214-
= \(inputServices : List Service)
215-
-> let annotations =
216-
[ kv "kubernetes.io/ingress.class" "nginx"
217-
, kv "kubernetes.io/ingress.allow-http" "false"
218-
]
219-
220-
let defaultService =
221-
{ name =
222-
"default"
223-
, host =
224-
"default.example.com"
225-
, version =
226-
" 1.0"
192+
: List Service types.Ingress
193+
= λ(inputServices : List Service)
194+
let annotations =
195+
[ kv "kubernetes.io/ingress.class" "nginx"
196+
, kv "kubernetes.io/ingress.allow-http" "false"
197+
]
198+
199+
let defaultService =
200+
{ name = "default"
201+
, host = "default.example.com"
202+
, version = " 1.0"
203+
}
204+
205+
let ingressServices = inputServices # [ defaultService ]
206+
207+
let spec =
208+
kubernetes.IngressSpec::{
209+
, tls = map Service types.IngressTLS makeTLS ingressServices
210+
, rules = map Service types.IngressRule makeRule ingressServices
211+
}
212+
213+
in kubernetes.Ingress::{
214+
, metadata =
215+
kubernetes.ObjectMeta::{
216+
, name = "nginx"
217+
, annotations = annotations
227218
}
228-
229-
let ingressServices = inputServices # [ defaultService ]
230-
231-
let spec =
232-
defaults.IngressSpec
233-
// { tls =
234-
map Service types.IngressTLS makeTLS ingressServices
235-
, rules =
236-
map Service types.IngressRule makeRule ingressServices
237-
}
238-
239-
in defaults.Ingress
240-
// { metadata =
241-
defaults.ObjectMeta
242-
// { name = "nginx", annotations = annotations }
243-
, spec =
244-
Some spec
245-
}
219+
, spec = Some spec
220+
}
246221

247222
in mkIngress services
248223

@@ -260,32 +235,32 @@ Result:
260235

261236
apiVersion: networking.k8s.io/v1beta1
262237
kind: Ingress
263-
spec:
264-
rules:
265-
- http:
266-
paths:
267-
- backend:
268-
servicePort: 80
269-
serviceName: foo
270-
host: foo.example.com
271-
- http:
272-
paths:
273-
- backend:
274-
servicePort: 80
275-
serviceName: default
276-
host: default.example.com
277-
tls:
278-
- hosts:
279-
- foo.example.com
280-
secretName: foo-certificate
281-
- hosts:
282-
- default.example.com
283-
secretName: default-certificate
284238
metadata:
285239
annotations:
240+
kubernetes.io/ingress.allow-http: "false"
286241
kubernetes.io/ingress.class: nginx
287-
kubernetes.io/ingress.allow-http: 'false'
288242
name: nginx
243+
spec:
244+
rules:
245+
- host: foo.example.com
246+
http:
247+
paths:
248+
- backend:
249+
serviceName: foo
250+
servicePort: 80
251+
- host: default.example.com
252+
http:
253+
paths:
254+
- backend:
255+
serviceName: default
256+
servicePort: 80
257+
tls:
258+
- hosts:
259+
- foo.example.com
260+
secretName: foo-certificate
261+
- hosts:
262+
- default.example.com
263+
secretName: default-certificate
289264

290265
```
291266

@@ -326,7 +301,7 @@ in
326301
## Projects Using `dhall-kubernetes`
327302

328303
* [dhall-prometheus-operator][dhall-prometheus-operator]: Provides types and default records for [Prometheus Operators][prometheus-operator].
329-
* [EarnestResearch/dhall-packages](https://github.com/EarnestResearch/dhall-packages): Provides dhall bindings for several dhall packages, including Kubernetes applications such as [argo](https://github.com/argoproj/argo), [argocd](https://github.com/argoproj/argo-cd), [ambassador](https://github.com/datawire/ambassador), [kubernetes-external-secrets](https://github.com/godaddy/kubernetes-external-secrets) and more.
304+
330305

331306
## Development
332307

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
{ apiVersion =
2-
"admissionregistration.k8s.io/v1beta1"
3-
, kind =
4-
"MutatingWebhookConfiguration"
5-
, metadata =
6-
./io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.dhall
1+
{ apiVersion = "admissionregistration.k8s.io/v1beta1"
2+
, kind = "MutatingWebhookConfiguration"
3+
, metadata = ./io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.dhall
74
, webhooks =
85
[] : List ./../types/io.k8s.api.admissionregistration.v1beta1.Webhook.dhall
96
}
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
{ apiVersion =
2-
"admissionregistration.k8s.io/v1beta1"
3-
, kind =
4-
"MutatingWebhookConfigurationList"
1+
{ apiVersion = "admissionregistration.k8s.io/v1beta1"
2+
, kind = "MutatingWebhookConfigurationList"
53
, items =
64
[] : List
7-
./../types/io.k8s.api.admissionregistration.v1beta1.MutatingWebhookConfiguration.dhall
8-
, metadata =
9-
./io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta.dhall
5+
./../types/io.k8s.api.admissionregistration.v1beta1.MutatingWebhookConfiguration.dhall
6+
, metadata = ./io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta.dhall
107
}
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
{ apiGroups =
2-
[] : List Text
3-
, apiVersions =
4-
[] : List Text
5-
, operations =
6-
[] : List Text
7-
, resources =
8-
[] : List Text
9-
, scope =
10-
None Text
1+
{ apiGroups = [] : List Text
2+
, apiVersions = [] : List Text
3+
, operations = [] : List Text
4+
, resources = [] : List Text
5+
, scope = None Text
116
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
{ apiVersion =
2-
"admissionregistration.k8s.io/v1beta1"
3-
, kind =
4-
"ValidatingWebhookConfiguration"
5-
, metadata =
6-
./io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.dhall
1+
{ apiVersion = "admissionregistration.k8s.io/v1beta1"
2+
, kind = "ValidatingWebhookConfiguration"
3+
, metadata = ./io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.dhall
74
, webhooks =
85
[] : List ./../types/io.k8s.api.admissionregistration.v1beta1.Webhook.dhall
96
}

0 commit comments

Comments
 (0)