Skip to content

Commit fee24c0

Browse files
authored
Add dhall-kubernetes support for "schemas" (#84)
For lack of a better term, I'm calling the `{ Type = …, default = … }` record that the record completion operator expects a "schema". This change adds `dhall-kubernetes` support for auto-generating these schemas for ease of use with the new `::` operator. See the included example for how this would be used
1 parent 2fb32a4 commit fee24c0

File tree

608 files changed

+3935
-0
lines changed

Some content is hidden

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

608 files changed

+3935
-0
lines changed

dhall-kubernetes-generator/src/Dhall/Kubernetes/Convert.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Dhall.Kubernetes.Convert
22
( toTypes
33
, toDefault
44
, getImportsMap
5+
, mkImport
56
) where
67

78
import qualified Data.List as List

dhall-kubernetes-generator/src/Main.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE OverloadedLists #-}
2+
13
module Main (main) where
24

35
import qualified Data.Map.Strict as Data.Map
@@ -74,15 +76,32 @@ main = do
7476
let path = "./defaults" Turtle.</> Turtle.fromText (name <> ".dhall")
7577
writeDhall path expr
7678

79+
let toSchema (ModelName key) _ _ =
80+
Dhall.RecordLit
81+
[ ("Type", Dhall.Embed (Convert.mkImport ["types", ".."] (key <> ".dhall")))
82+
, ("default", Dhall.Embed (Convert.mkImport ["defaults", ".."] (key <> ".dhall")))
83+
]
84+
85+
let schemas = Data.Map.intersectionWithKey toSchema types defaults
86+
87+
-- Output schemas that combine both the types and defaults
88+
Turtle.mktree "schemas"
89+
for_ (Data.Map.toList schemas) $ \(ModelName name, expr) -> do
90+
let path = "./schemas" Turtle.</> Turtle.fromText (name <> ".dhall")
91+
writeDhall path expr
92+
7793
-- Output the types record, the defaults record, and the giant union type
7894
let objectNames = Data.Map.keys types
7995
typesMap = Convert.getImportsMap objectNames "types" $ Data.Map.keys types
8096
defaultsMap = Convert.getImportsMap objectNames "defaults" $ Data.Map.keys defaults
97+
schemasMap = Convert.getImportsMap objectNames "schemas" $ Data.Map.keys schemas
8198

8299
typesRecordPath = "./types.dhall"
83100
typesUnionPath = "./typesUnion.dhall"
84101
defaultsRecordPath = "./defaults.dhall"
102+
schemasRecordPath = "./schemas.dhall"
85103

86104
writeDhall typesUnionPath (Dhall.Union $ fmap Just typesMap)
87105
writeDhall typesRecordPath (Dhall.RecordLit typesMap)
88106
writeDhall defaultsRecordPath (Dhall.RecordLit defaultsMap)
107+
writeDhall schemasRecordPath (Dhall.RecordLit schemasMap)
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
let kubernetes = ../schemas.dhall
2+
3+
let release = "wintering-rodent"
4+
5+
let name = "aws-iam-authenticator"
6+
7+
let fullName = "${release}-${name}"
8+
9+
let version = "0.1.1"
10+
11+
let chart = "${name}-${version}"
12+
13+
let heritage = "dhall"
14+
15+
in kubernetes.DaemonSet::{
16+
, metadata = kubernetes.ObjectMeta::{
17+
, name = fullName
18+
, labels = toMap
19+
{ app = name
20+
, chart = chart
21+
, release = release
22+
, heritage = heritage
23+
}
24+
}
25+
, spec = Some kubernetes.DaemonSetSpec::{
26+
, updateStrategy = Some kubernetes.DaemonSetUpdateStrategy::{
27+
, type = Some "RollingUpdate"
28+
}
29+
, template = kubernetes.PodTemplateSpec::{
30+
, metadata = kubernetes.ObjectMeta::{
31+
, name = name
32+
, annotations = toMap
33+
{ `scheduler.alpha.kubernetes.io/critical-pod` = ""
34+
}
35+
, labels = toMap
36+
{ app = name
37+
, release = release
38+
}
39+
}
40+
, spec = Some kubernetes.PodSpec::{
41+
, hostNetwork = Some True
42+
, nodeSelector = toMap
43+
{ `node-role.kubernetes.io/master` = ""
44+
}
45+
, tolerations =
46+
[ kubernetes.Toleration::{
47+
, effect = Some "NoSchedule"
48+
, key = Some "node-role.kubernetes.io/master"
49+
}
50+
, kubernetes.Toleration::{
51+
, effect = Some "CriticalAddonsOnly"
52+
, key = Some "Exists"
53+
}
54+
]
55+
, containers =
56+
[ kubernetes.Container::{
57+
, name = fullName
58+
, image = Some "gcr.io/heptio-images/authenticator:v0.1.0"
59+
, args =
60+
[ "server"
61+
, "--config=/etc/aws-iam-authenticator/config.yaml"
62+
, "--state-dir=/var/aws-iam-authenticator"
63+
, "--generate-kubeconfig=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml"
64+
]
65+
, volumeMounts =
66+
[ kubernetes.VolumeMount::{
67+
, name = "config"
68+
, mountPath = "/etc/aws-iam-authenticator/"
69+
}
70+
, kubernetes.VolumeMount::{
71+
, name = "state"
72+
, mountPath = "/var/aws-iam-authenticator/"
73+
}
74+
, kubernetes.VolumeMount::{
75+
, name = "output"
76+
, mountPath = "/etc/kubernetes/aws-iam-authenticator/"
77+
}
78+
]
79+
}
80+
]
81+
, volumes =
82+
[ kubernetes.Volume::{
83+
, name = "config"
84+
, configMap = Some kubernetes.ConfigMapVolumeSource::{
85+
, name = Some fullName
86+
}
87+
}
88+
, kubernetes.Volume::{
89+
, name = "output"
90+
, hostPath = Some kubernetes.HostPathVolumeSource::{
91+
, path = "/srv/kubernetes/aws-iam-authenticator/"
92+
}
93+
}
94+
, kubernetes.Volume::{
95+
, name = "state"
96+
, hostPath = Some kubernetes.HostPathVolumeSource::{
97+
, path = "/srv/kubernetes/aws-iam-authenticator/"
98+
}
99+
}
100+
]
101+
}
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)