@@ -38,26 +38,22 @@ or the [full tutorial][dhall-tutorial].
3838Let's say we'd like to configure a Deployment exposing an ` nginx ` webserver.
3939
4040In the following example, we:
41- 1 . Import the Kubernetes definitions as Dhall Types (the ` types .dhall` file) from the local repo.
41+ 1 . Import the Kubernetes definitions as a Dhall package (the ` package .dhall` file) from the local repo.
4242 In your case you will want to replace the local path with a remote one, e.g.
43- ` https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/0a4f0b87fbdd4b679853c81ff804bde7b44336cf/types .dhall ` .
43+ ` https://raw.githubusercontent.com/dhall-lang/dhall-kubernetes/master/package .dhall `
4444 Note: the ` sha256:.. ` is applied to some imports so that:
4545 1 . the import is cached locally after the first evaluation, with great time savings (and avoiding network calls)
4646 2 . prevent execution if the content of the file changes. This is a security feature, and you
4747 can read more [ in Dhall's "Security Guarantees" document] [ security-hashes ]
48- 2 . Import the defaults for the above types.
49- Since _ most_ of the fields in any definition are optional, for better ergonomics while
50- coding Dhall we have generated default values for all types, so we can just use the ` // `
51- operator (right-biased record merge) to add our data to the default configuration.
52- The pattern looks something like this: ` defaultValue // { ourDataHere = ..} `
53- 3 . Define the [ Deployment] [ deployment ] using this pattern (see the default [ here] [ default-deployment ] )
54- and hardcoding the deployment details:
55-
56- ``` haskell
48+ Note: instead of using the ` package.dhall ` from the ` master ` branch, you may want to use a tagged release,
49+ as the contents of the ` master ` branch are liable to change without warning.
50+ 2 . Define the [ Deployment] [ deployment ] using the schema pattern and hardcoding the deployment details:
51+
52+ ``` dhall
5753-- examples/deploymentSimple.dhall
5854
5955let kubernetes =
60- ../ schemas . dhall sha256: 9704063 d1e2d17050cb18afae199a24f4cd1264e6c8e696ca94781309e213785
56+ ../ package . dhall sha256: 3 ea8628b704704de295261dfc7626c15247c589c10a266f970cade262543fdda
6157
6258let deployment =
6359 kubernetes. Deployment :: {
@@ -134,7 +130,7 @@ and reuse those objects for configuring other things (e.g. configuring the servi
134130templating documentation, configuring Terraform deployments, you name it).
135131
136132As an example of that, next we'll define an Ingress (an [ Nginx Ingress] [ nginx-ingress ] in this case),
137- containing stuff like TLS certs and routes for every service - see the [ type ] [ Ingress ] and [ default ] [ Ingress-default ] for it .
133+ containing stuff like TLS certs and routes for every service - see the [ schema ] [ Ingress ] .
138134
139135Things to note in the following example:
140136- we define the ` Service ` type inline in the file, but in your case you'll want to have a
@@ -145,7 +141,7 @@ Things to note in the following example:
145141 ` mkIngress ` function instead of applying it, so you can do something like
146142 ` dhall-to-yaml --omitEmpty <<< "./mkIngress.dhall ./myServices.dhall" `
147143
148- ``` haskell
144+ ``` dhall
149145-- examples/ingress.dhall
150146
151147let Prelude = ../ Prelude. dhall
@@ -154,33 +150,30 @@ let map = Prelude.List.map
154150
155151let kv = Prelude.JSON. keyText
156152
157- let types =
158- ../ types. dhall sha256: e48e21b807dad217a6c3e631fcaf3e950062310bfb4a8bbcecc330eb7b2f60ed
159-
160153let kubernetes =
161- ../ schemas . dhall sha256: 9704063 d1e2d17050cb18afae199a24f4cd1264e6c8e696ca94781309e213785
154+ ../ package . dhall sha256: 3 ea8628b704704de295261dfc7626c15247c589c10a266f970cade262543fdda
162155
163156let Service = { name : Text , host : Text , version : Text }
164157
165158let services = [ { name = " foo" , host = " foo.example.com" , version = " 2.3" } ]
166159
167160let makeTLS
168- : Service → types . IngressTLS
161+ : Service → kubernetes . IngressTLS. Type
169162 = λ(service : Service )
170163 → { hosts = [ service. host ]
171164 , secretName = Some " ${service.name}-certificate"
172165 }
173166
174167let makeRule
175- : Service → types . IngressRule
168+ : Service → kubernetes . IngressRule. Type
176169 = λ(service : Service )
177170 → { host = Some service. host
178171 , http =
179172 Some
180173 { paths =
181174 [ { backend =
182175 { serviceName = service. name
183- , servicePort = types . IntOrString. Int 80
176+ , servicePort = kubernetes . IntOrString. Int 80
184177 }
185178 , path = None Text
186179 }
@@ -189,7 +182,7 @@ let makeRule
189182 }
190183
191184let mkIngress
192- : List Service → types . Ingress
185+ : List Service → kubernetes . Ingress. Type
193186 = λ(inputServices : List Service )
194187 → let annotations =
195188 [ kv " kubernetes.io/ingress.class" " nginx"
@@ -206,8 +199,14 @@ let mkIngress
206199
207200 let spec =
208201 kubernetes. IngressSpec :: {
209- , tls = map Service types. IngressTLS makeTLS ingressServices
210- , rules = map Service types. IngressRule makeRule ingressServices
202+ , tls =
203+ map Service kubernetes. IngressTLS. Type makeTLS ingressServices
204+ , rules =
205+ map
206+ Service
207+ kubernetes. IngressRule. Type
208+ makeRule
209+ ingressServices
211210 }
212211
213212 in kubernetes. Ingress :: {
@@ -284,7 +283,7 @@ it's possible to use it together with the [union type of all k8s types that we g
284283
285284So if we want to deploy e.g. a Deployment and a Service together, we can do:
286285
287- ``` haskell
286+ ``` dhall
288287let k8s = ./ typesUnion. dhall
289288
290289in
@@ -344,10 +343,8 @@ to run this command afterwards.
344343[ kubernetes ] : https://kubernetes.io/
345344[ normalization ] : https://en.wikipedia.org/wiki/Normalization_property_(abstract_rewriting)
346345[ nginx-ingress ] : https://github.com/kubernetes/ingress-nginx
347- [ dhall-tutorial ] : http://hackage.haskell.org/package/dhall-1.21.0/docs/Dhall-Tutorial.html
348- [ default-deployment ] : ./defaults/io.k8s.api.apps.v1.Deployment.dhall
349- [ deployment ] : ./types/io.k8s.api.apps.v1.Deployment.dhall
350- [ Ingress ] : ./types/io.k8s.api.extensions.v1beta1.Ingress.dhall
351- [ Ingress-default ] : ./default/io.k8s.api.extensions.v1beta1.Ingress.dhall
346+ [ dhall-tutorial ] : http://hackage.haskell.org/package/dhall-1.28.0/docs/Dhall-Tutorial.html
347+ [ deployment ] : ./schemas/io.k8s.api.apps.v1.Deployment.dhall
348+ [ Ingress ] : ./schemas/io.k8s.api.extensions.v1beta1.Ingress.dhall
352349[ prometheus-operator ] : https://github.com/coreos/prometheus-operator
353350[ dhall-prometheus-operator ] : https://github.com/coralogix/dhall-prometheus-operator
0 commit comments