-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchart.pkl
82 lines (69 loc) · 2.32 KB
/
chart.pkl
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
//amends "PklProject"
module io.markrobinson.nginx
import "@k8s/K8sObject.pkl"
import "@k8s/api/apps/v1/Deployment.pkl"
import "@k8s/api/core/v1/ConfigMap.pkl"
import "@k8s/api/core/v1/Service.pkl"
import "@k8s/api/core/v1/ServiceAccount.pkl"
import "@k8s/api/networking/v1/Ingress.pkl"
import "version.pkl"
import "chart.pkl" as InternalChart
selectorLabels {
["app.kubernetes.io/name"] = "nginx"
["app.kubernetes.io/instance"] = version.name
}
image {
repository = "krewh/hardened-nginx"
tag = "1.1.3"
}
commonLabels {
["app.kubernetes.io/version"] = version.version
["app.kubernetes.io/managed-by"] = "Helm"
}
ingressEnabled = false
/// Creates an empty mapping from resource name to resource [type] that defaults `metadata.name` to the resource name.
function resourceMapping(type): Mapping<String, unknown> =
new Mapping { default = (key) -> (type) {
metadata {
name = key
labels {
for (k,v in module.commonLabels) {
[k] = v
}
for (k,v in module.selectorLabels) {
[k] = v
}
}
} } }
output {
renderer = new YamlRenderer {
isStream = true
converters = (K8sObject.output.renderer as YamlRenderer).converters
}
// Only emit Mappings
value = chart.toMap().values.filter( (x) -> (x is Mapping)).flatMap((it) -> it.toMap().values)
}
hidden config: Mixin<Config>
/// The actual configuration value
chart: Config = includes.fold(new Config {
configMaps = resourceMapping(ConfigMap)
deployments = resourceMapping(Deployment)
ingresses = resourceMapping(Ingress)
services = resourceMapping(Service)
serviceaccounts = resourceMapping(ServiceAccount)
}, (result, cfg) -> cfg.config.apply(result))
/// The underlying configuration
class Config {
services: Mapping<String, Service> //= resourceMapping(Service)
configMaps: Mapping<String, ConfigMap> //= resourceMapping(ConfigMap)
deployments: Mapping<String, Deployment> //= resourceMapping(Deployment)
ingresses: Mapping<String, Ingress> //= resourceMapping(Deployment)
serviceaccounts: Mapping<String, ServiceAccount> //= resourceMapping(Deployment)
}
local includes: Listing<InternalChart> = new {
import("service.pkl")
import("configmap.pkl")
import("deployment.pkl")
when (ingressEnabled) { import("ingress.pkl") }
import("serviceaccount.pkl")
}