forked from dhall-lang/dhall-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkDeployment
More file actions
168 lines (129 loc) · 4.52 KB
/
Copy pathmkDeployment
File metadata and controls
168 lines (129 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
-- Prelude
let Prelude = ../../Prelude.dhall
in let map = Prelude.`List`.map
in let kv = Prelude.JSON.keyText
-- Kubernetes types and defaults
in let Types = ./RawTypes
in let default = ./RawDefaults
-- Types for dynamic records
in let KV = { mapKey : Text, mapValue : Text }
in let ListKV = List KV
in let mkProbe : ./Probe → Optional Types.Probe =
λ(probe : ./Probe) →
Some
(default.probe //
{ initialDelaySeconds = Some probe.initial
, periodSeconds = Some probe.period
, httpGet = Some
(default.httpGet
{ port = default.Int probe.port } //
{ path = Some probe.path
})
})
in let mkEnvVar : KV → Types.EnvVar =
λ(var : KV) →
default.envVar
{ name = var.mapKey } //
{ value = Some var.mapValue }
in let mkEmptyVolume : { name : Text } → Types.Volume =
λ(vol : { name : Text }) →
default.volume
{ name = vol.name } //
{ emptyDir = Some default.emptyVolume }
in let mkSecretVolume : { name : Text } → Types.Volume =
λ(vol : { name : Text }) →
default.volume
{ name = vol.name } //
{ secret = Some
(default.secretVolume // { secretName = Some vol.name } )
}
in let mkPathVolume : { name : Text, path : Text } → Types.Volume =
λ(vol : { name : Text, path : Text }) →
default.volume
{ name = vol.name } //
{ hostPath = Some
(default.pathVolume { path = vol.path })
}
in let mkMount : ./Mount → Types.Mount =
λ(mount : ./Mount) →
default.mount
{ mountPath = mount.mountPath
, name = mount.name
} //
{ readOnly = mount.readOnly }
in let mkContainer : ./Container → Types.Container =
λ(container : ./Container) →
default.container
{ name = container.name } //
{ image = Some "${container.imageName}:${container.imageTag}"
, imagePullPolicy = Some container.imagePullPolicy
, ports = Optional/fold
Natural
container.port
(Optional (List Types.ContainerPort))
(λ(port : Natural) → Some
[(default.containerPort { containerPort = port })])
(None (List Types.ContainerPort))
, resources = Some
{ limits = Some [kv "cpu" "${Natural/show container.maxCPU}m"]
, requests = Some [kv "cpu" "${Natural/show container.minCPU}m"]
}
, command = container.command
, volumeMounts = Some
(map ./Mount Types.Mount mkMount container.mounts)
-- Poll the container to see if the it's alive or we should restart it
, livenessProbe = Optional/fold
./Probe
container.livenessProbe
(Optional Types.Probe)
mkProbe
(None Types.Probe)
-- Poll the container to see that it's ready for requests
, readinessProbe = Optional/fold
./Probe
container.readinessProbe
(Optional Types.Probe)
mkProbe
(None Types.Probe)
, env = Some
(map { mapKey : Text , mapValue : Text } Types.EnvVar mkEnvVar container.envVars)
}
in let mkDeployment : ./Deployment → Types.Deployment =
λ(deployment : ./Deployment) →
let selector = Some [kv "app" deployment.name]
in let emptyVolumes = map { name : Text } Types.Volume mkEmptyVolume deployment.emptyVolumes
in let secretVolumes = map { name : Text } Types.Volume mkSecretVolume deployment.secretVolumes
in let pathVolumes = map { name : Text, path : Text } Types.Volume mkPathVolume deployment.pathVolumes
in let volumes = Some (emptyVolumes # secretVolumes # pathVolumes)
in let spec = default.spec
{ selector = default.selector // { matchLabels = selector }
, template = default.template
{ metadata = default.meta
{ name = deployment.name } // { labels = selector }
} //
{ spec = Some (default.podSpec
{ containers = map ./Container Types.Container mkContainer deployment.containers
} //
{ volumes = volumes
})
}
} //
{ replicas = Some deployment.replicas
-- Don't keep all the ReplicaSets
, revisionHistoryLimit = Some deployment.revisionHistoryLimit
, strategy = Some
-- Control the RollingUpdate so the app is always available. For more info see:
-- https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
{ type = Some "RollingUpdate"
, rollingUpdate = Some
{ maxSurge = Some (default.Int deployment.maxSurge)
, maxUnavailable = Some (default.Int deployment.maxUnavailable)
}
}
}
in default.deployment
{ metadata = default.meta { name = deployment.name }
} //
{ spec = Some spec
}
in mkDeployment