-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmutatingWebhookTemplate.dhall
177 lines (166 loc) · 6.53 KB
/
mutatingWebhookTemplate.dhall
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
169
170
171
172
173
174
175
176
177
let k8s =
https://raw.githubusercontent.com/EarnestResearch/dhall-packages/master/kubernetes/k8s/1.14.dhall
let cert-manager =
https://raw.githubusercontent.com/EarnestResearch/dhall-packages/master/kubernetes/cert-manager/package.dhall
let certsPath = "/certs"
let Config = ./Config.dhall
let labels = \(config : Config) -> toMap { app = config.name }
let deployment =
\(config : Config)
-> k8s.Deployment::{
, metadata = k8s.ObjectMeta::{ name = config.name }
, spec =
Some
k8s.DeploymentSpec::{
, selector = k8s.LabelSelector::{ matchLabels = labels config }
, template =
k8s.PodTemplateSpec::{
, metadata =
k8s.ObjectMeta::{
, name = config.name
, labels = labels config
}
, spec =
Some
k8s.PodSpec::{
, containers =
[ k8s.Container::{
, name = config.name
, image = Some config.imageName
, ports =
[ k8s.ContainerPort::{
, containerPort = config.port
}
]
, env =
[ k8s.EnvVar::{
, name = "CERTIFICATE_FILE"
, value = Some "${certsPath}/tls.crt"
}
, k8s.EnvVar::{
, name = "KEY_FILE"
, value = Some "${certsPath}/tls.key"
}
]
, volumeMounts =
[ k8s.VolumeMount::{
, name = "certs"
, mountPath = certsPath
, readOnly = Some True
}
]
}
]
, volumes =
[ k8s.Volume::{
, name = "certs"
, secret =
Some
k8s.SecretVolumeSource::{
, secretName = Some config.name
}
}
]
}
}
}
}
let service =
\(config : Config)
-> k8s.Service::{
, metadata = k8s.ObjectMeta::{ name = config.name }
, spec =
Some
k8s.ServiceSpec::{
, selector = labels config
, ports =
[ k8s.ServicePort::{
, targetPort = Some (k8s.IntOrString.Int config.port)
, port = 443
}
]
}
}
let issuer =
\(config : Config)
-> cert-manager.Issuer::{
, metadata = k8s.ObjectMeta::{ name = config.name }
, spec =
cert-manager.IssuerSpec.SelfSigned
cert-manager.SelfSignedIssuerSpec::{=}
}
let certificate =
\(config : Config)
-> cert-manager.Certificate::{
, metadata = k8s.ObjectMeta::{ name = config.name }
, spec =
cert-manager.CertificateSpec::{
, secretName = config.name
, issuerRef = { name = config.name, kind = (issuer config).kind }
, commonName = Some "${config.name}.${config.namespace}.svc"
, dnsNames =
Some
[ config.name
, "${config.name}.${config.namespace}"
, "${config.name}.${config.namespace}.svc"
, "${config.name}.${config.namespace}.svc.cluster.local"
, "${config.name}:443"
, "${config.name}.${config.namespace}:443"
, "${config.name}.${config.namespace}.svc:443"
, "${config.name}.${config.namespace}.svc.cluster.local:443"
, "localhost:8080"
]
, usages = Some [ "any" ]
, isCA = Some False
}
}
let mutatingWebhookConfiguration =
\(config : Config)
-> k8s.MutatingWebhookConfiguration::{
, metadata =
k8s.ObjectMeta::{
, name = config.name
, labels = labels config
, annotations =
toMap
{ `cert-manager.io/inject-ca-from` =
"${config.namespace}/${config.name}"
}
}
, webhooks =
[ k8s.Webhook::{
, name = "${config.name}.${config.namespace}.svc"
, clientConfig =
k8s.WebhookClientConfig::{
, service =
Some
{ name = config.name
, namespace = config.namespace
, path = Some config.path
}
}
, failurePolicy = config.failurePolicy
, admissionReviewVersions = [ "v1beta1" ]
, rules = config.rules
, namespaceSelector = config.namespaceSelector
}
]
}
let union =
< Deployment : k8s.Deployment.Type
| Service : k8s.Service.Type
| MWH : k8s.MutatingWebhookConfiguration.Type
| Certificate : cert-manager.Certificate.Type
| ClusterIssuer : cert-manager.ClusterIssuer.Type
>
in \(config : Config)
-> { apiVersion = "v1"
, kind = "List"
, items =
[ union.Deployment (deployment config)
, union.Service (service config)
, union.MWH (mutatingWebhookConfiguration config)
, union.Certificate (certificate config)
, union.ClusterIssuer (issuer config)
]
}