blob: d4c186c9fdca20de6d67b4b82812a50e2fd2a4e9 [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,
Sergiusz Bazanski2d814272019-09-25 13:58:48 +020034 mounts: {},
35 relays: {},
Sergiusz Bazanski610bec42019-06-19 14:31:19 +020036 },
37
38 tag: "latest",
39 image: "registry.k0.hswaw.net/app/radio:" + cfg.tag,
40 resources: {
41 requests: {
Sergiusz Bazanskic807f862019-06-19 16:18:28 +020042 cpu: "25m",
43 memory: "50Mi",
Sergiusz Bazanski610bec42019-06-19 14:31:19 +020044 },
45 limits: {
Sergiusz Bazanskic807f862019-06-19 16:18:28 +020046 cpu: "100m",
Sergiusz Bazanski610bec42019-06-19 14:31:19 +020047 memory: "200Mi",
48 },
49 },
50 },
51
52 mount:: {
53 username: error "mount username must be defined",
54 password: error "mount password must be defined",
55 genre: "Classical",
56 bitrate: 128,
57 hidden: false,
Sergiusz Bazanskif9281d82019-06-19 14:55:11 +020058 fallbackMount: null,
Sergiusz Bazanski610bec42019-06-19 14:31:19 +020059 },
60
61 makeName(suffix):: cfg.prefix + suffix,
62
63 metadata:: {
64 namespace: cfg.namespace,
65 labels: {
66 "app.kubernetes.io/name": cfg.appName,
67 "app.kubernetes.io/managed-by": "kubecfg",
68 "app.kubernetes.io/component": "radio",
69 },
70 },
71
72 configMap: kube.ConfigMap(radio.makeName("icecast")) {
73 metadata+: radio.metadata,
74 data: {
75 "icecast.xml": std.manifestXmlJsonml(["icecast",
76 ["location", cfg.icecast.location],
77 ["admin", cfg.icecast.admin],
78 ["limits",
79 ["clients", std.toString(cfg.icecast.limits.clients)],
80 ["sources", std.toString(cfg.icecast.limits.sources)],
81 ["threadpool", std.toString(cfg.icecast.limits.threadpool)],
82 ["queue-size", std.toString(cfg.icecast.limits.queueSize)],
83 ["client-timeout", std.toString(cfg.icecast.limits.clientTimeout)],
84 ["header-timeout", std.toString(cfg.icecast.limits.headerTimeout)],
85 ["source-timeout", std.toString(cfg.icecast.limits.sourceTimeout)],
86 ["burst-on-connect", if cfg.icecast.limits.burstOnConnect then "1" else "0"],
87 ["burst-size", std.toString(cfg.icecast.limits.burstSize)],
88 ],
89 ["authentication",
90 ["source-password", cfg.icecast.authentication.sourcePassword],
Sergiusz Bazanski9d6929f2019-06-20 12:52:38 +020091 ["relay-user", "relay"],
Sergiusz Bazanski610bec42019-06-19 14:31:19 +020092 ["relay-password", cfg.icecast.authentication.relayPassword],
Sergiusz Bazanski9d6929f2019-06-20 12:52:38 +020093 ["admin-user", "admin"],
Sergiusz Bazanski610bec42019-06-19 14:31:19 +020094 ["admin-password", cfg.icecast.authentication.adminPassword],
95 ],
96 ["hostname", cfg.icecast.hostname],
97 ["listen-socket",
98 ["port", std.toString(cfg.icecast.listenPort)],
99 ],
Sergiusz Bazanskif9281d82019-06-19 14:55:11 +0200100 ["fileserve", "1"],
101 ["paths",
102 ["webroot", "/usr/share/icecast/web"],
Sergiusz Bazanski9d6929f2019-06-20 12:52:38 +0200103 ["adminroot", "/usr/share/icecast/admin"],
Sergiusz Bazanskif9281d82019-06-19 14:55:11 +0200104 ],
Sergiusz Bazanski610bec42019-06-19 14:31:19 +0200105 ["logging",
106 ["accesslog", "-"],
107 ["errorlog", "-"],
108 ["loglevel", "2"],
109 ],
110 ["security",
111 ["chroot", "0"],
112 ],
113 ] + [
114 ["mount", {type: "normal"},
115 ["mount-name", m],
116 ["username", cfg.icecast.mounts[m].username],
117 ["password", cfg.icecast.mounts[m].password],
118 ["public", if cfg.icecast.mounts[m].public then "1" else "0"],
119 ["genre", cfg.icecast.mounts[m].genre],
120 ["bitrate", std.toString(cfg.icecast.mounts[m].bitrate)],
121 ["hidden", if cfg.icecast.mounts[m].hidden then "1" else "0"],
Sergiusz Bazanski9d6929f2019-06-20 12:52:38 +0200122 ] + (if cfg.icecast.mounts[m].fallbackMount != null then [
123 ["fallback-mount", cfg.icecast.mounts[m].fallbackMount],
124 ["fallback-override", "1"],
125 ] else [])
Sergiusz Bazanski610bec42019-06-19 14:31:19 +0200126 for m in std.objectFields(cfg.icecast.mounts)
Sergiusz Bazanski2d814272019-09-25 13:58:48 +0200127 ] + [
128 ["relay",
129 ["server", cfg.icecast.relays[r].server],
130 ["port", std.toString(cfg.icecast.relays[r].port)],
131 ["mount", cfg.icecast.relays[r].mount],
132 ["local-mount", r],
133 ["on-demand", "0"],
134 ] + (if cfg.icecast.relays[r].username != null then [
135 ["username", cfg.icecast.relays[r].username]
136 ] else []) + (if cfg.icecast.relays[r].password != null then [
137 ["password", cfg.icecast.relays[r].password],
Serge Bazanski6f0d8522023-02-28 01:16:27 +0000138 ] else []) + (if cfg.icecast.relays[r].masterUsername != null then [
139 ["master-username", cfg.icecast.relays[r].masterUsername]
140 ] else []) + (if cfg.icecast.relays[r].masterPassword != null then [
141 ["master-password", cfg.icecast.relays[r].masterPassword],
Sergiusz Bazanski2d814272019-09-25 13:58:48 +0200142 ] else [])
143 for r in std.objectFields(cfg.icecast.relays)
144 ]),
Sergiusz Bazanski610bec42019-06-19 14:31:19 +0200145 },
146 },
147
148 deployment: kube.Deployment(radio.makeName("icecast")) {
149 metadata+: radio.metadata,
150 spec+: {
151 replicas: 1,
152 template+: {
153 spec+: {
154 volumes_: {
155 config: kube.ConfigMapVolume(radio.configMap),
156 },
157 containers_: {
158 radio: kube.Container(radio.makeName("radio")) {
159 image: cfg.image,
160 ports_: {
161 client: { containerPort: cfg.icecast.listenPort },
162 },
163 volumeMounts_: {
164 config: { mountPath: "/usr/share/icecast/icecast.xml", subPath: "icecast.xml" },
165 },
166 resources: cfg.resources,
167 },
168 },
169 },
170 },
171 },
172 },
173 svc: kube.Service(radio.makeName("icecast")) {
174 metadata+: radio.metadata,
175 target_pod:: radio.deployment.spec.template,
176 spec+: {
177 ports: [
178 { name: "client", port: cfg.port, targetPort: cfg.icecast.listenPort, protocol: "TCP" },
Sergiusz Bazanski2d814272019-09-25 13:58:48 +0200179 { name: "client80", port: 80, targetPort: cfg.icecast.listenPort, protocol: "TCP" },
Sergiusz Bazanski610bec42019-06-19 14:31:19 +0200180 ],
181 type: "LoadBalancer",
182 },
183 },
184}