blob: 08a7ffbb159d80dc01908e614fe19cd5ffef9292 [file] [log] [blame]
Sergiusz Bazanski610bec42019-06-19 14:31:19 +02001local kube = import "../../../kube/kube.libsonnet";
2
3{
4 local radio = self,
5 local cfg = radio.cfg,
6
7 cfg:: {
8 namespace: error "namespace must be set",
9 appName: "radio",
10 prefix: "", # if set, should be 'foo-'
11 port: 2137,
12
13 icecast: {
14 location: error "location must be set",
15 admin: error "admin must be set",
16 limits: {
17 clients: 100,
18 sources: 2,
19 threadpool: 5,
20 queueSize: 524288,
21 clientTimeout: 30,
22 headerTimeout: 15,
23 sourceTimeout: 10,
24 burstOnConnect: true,
25 burstSize: 65535,
26 },
27 authentication: {
28 sourcePassword: error "source password must be set",
29 relayPassword: error "relay password must be set",
30 adminPassword: error "admin password must be set",
31 },
32 hostname: "localhost",
33 listenPort: 8080,
34 mounts: [],
35 },
36
37 tag: "latest",
38 image: "registry.k0.hswaw.net/app/radio:" + cfg.tag,
39 resources: {
40 requests: {
41 cpu: "100m",
42 memory: "100Mi",
43 },
44 limits: {
45 cpu: "300m",
46 memory: "200Mi",
47 },
48 },
49 },
50
51 mount:: {
52 username: error "mount username must be defined",
53 password: error "mount password must be defined",
54 genre: "Classical",
55 bitrate: 128,
56 hidden: false,
57 },
58
59 makeName(suffix):: cfg.prefix + suffix,
60
61 metadata:: {
62 namespace: cfg.namespace,
63 labels: {
64 "app.kubernetes.io/name": cfg.appName,
65 "app.kubernetes.io/managed-by": "kubecfg",
66 "app.kubernetes.io/component": "radio",
67 },
68 },
69
70 configMap: kube.ConfigMap(radio.makeName("icecast")) {
71 metadata+: radio.metadata,
72 data: {
73 "icecast.xml": std.manifestXmlJsonml(["icecast",
74 ["location", cfg.icecast.location],
75 ["admin", cfg.icecast.admin],
76 ["limits",
77 ["clients", std.toString(cfg.icecast.limits.clients)],
78 ["sources", std.toString(cfg.icecast.limits.sources)],
79 ["threadpool", std.toString(cfg.icecast.limits.threadpool)],
80 ["queue-size", std.toString(cfg.icecast.limits.queueSize)],
81 ["client-timeout", std.toString(cfg.icecast.limits.clientTimeout)],
82 ["header-timeout", std.toString(cfg.icecast.limits.headerTimeout)],
83 ["source-timeout", std.toString(cfg.icecast.limits.sourceTimeout)],
84 ["burst-on-connect", if cfg.icecast.limits.burstOnConnect then "1" else "0"],
85 ["burst-size", std.toString(cfg.icecast.limits.burstSize)],
86 ],
87 ["authentication",
88 ["source-password", cfg.icecast.authentication.sourcePassword],
89 ["relay-password", cfg.icecast.authentication.relayPassword],
90 ["admin-password", cfg.icecast.authentication.adminPassword],
91 ],
92 ["hostname", cfg.icecast.hostname],
93 ["listen-socket",
94 ["port", std.toString(cfg.icecast.listenPort)],
95 ],
96 ["logging",
97 ["accesslog", "-"],
98 ["errorlog", "-"],
99 ["loglevel", "2"],
100 ],
101 ["security",
102 ["chroot", "0"],
103 ],
104 ] + [
105 ["mount", {type: "normal"},
106 ["mount-name", m],
107 ["username", cfg.icecast.mounts[m].username],
108 ["password", cfg.icecast.mounts[m].password],
109 ["public", if cfg.icecast.mounts[m].public then "1" else "0"],
110 ["genre", cfg.icecast.mounts[m].genre],
111 ["bitrate", std.toString(cfg.icecast.mounts[m].bitrate)],
112 ["hidden", if cfg.icecast.mounts[m].hidden then "1" else "0"],
113 ]
114 for m in std.objectFields(cfg.icecast.mounts)
115 ]),
116 },
117 },
118
119 deployment: kube.Deployment(radio.makeName("icecast")) {
120 metadata+: radio.metadata,
121 spec+: {
122 replicas: 1,
123 template+: {
124 spec+: {
125 volumes_: {
126 config: kube.ConfigMapVolume(radio.configMap),
127 },
128 containers_: {
129 radio: kube.Container(radio.makeName("radio")) {
130 image: cfg.image,
131 ports_: {
132 client: { containerPort: cfg.icecast.listenPort },
133 },
134 volumeMounts_: {
135 config: { mountPath: "/usr/share/icecast/icecast.xml", subPath: "icecast.xml" },
136 },
137 resources: cfg.resources,
138 },
139 },
140 },
141 },
142 },
143 },
144 svc: kube.Service(radio.makeName("icecast")) {
145 metadata+: radio.metadata,
146 target_pod:: radio.deployment.spec.template,
147 spec+: {
148 ports: [
149 { name: "client", port: cfg.port, targetPort: cfg.icecast.listenPort, protocol: "TCP" },
150 ],
151 type: "LoadBalancer",
152 },
153 },
154}