blob: c13e82d129ec145bcf639e56c69c5497ee8aa0be [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: {
Sergiusz Bazanskic807f862019-06-19 16:18:28 +020041 cpu: "25m",
42 memory: "50Mi",
Sergiusz Bazanski610bec42019-06-19 14:31:19 +020043 },
44 limits: {
Sergiusz Bazanskic807f862019-06-19 16:18:28 +020045 cpu: "100m",
Sergiusz Bazanski610bec42019-06-19 14:31:19 +020046 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,
Sergiusz Bazanskif9281d82019-06-19 14:55:11 +020057 fallbackMount: null,
Sergiusz Bazanski610bec42019-06-19 14:31:19 +020058 },
59
60 makeName(suffix):: cfg.prefix + suffix,
61
62 metadata:: {
63 namespace: cfg.namespace,
64 labels: {
65 "app.kubernetes.io/name": cfg.appName,
66 "app.kubernetes.io/managed-by": "kubecfg",
67 "app.kubernetes.io/component": "radio",
68 },
69 },
70
71 configMap: kube.ConfigMap(radio.makeName("icecast")) {
72 metadata+: radio.metadata,
73 data: {
74 "icecast.xml": std.manifestXmlJsonml(["icecast",
75 ["location", cfg.icecast.location],
76 ["admin", cfg.icecast.admin],
77 ["limits",
78 ["clients", std.toString(cfg.icecast.limits.clients)],
79 ["sources", std.toString(cfg.icecast.limits.sources)],
80 ["threadpool", std.toString(cfg.icecast.limits.threadpool)],
81 ["queue-size", std.toString(cfg.icecast.limits.queueSize)],
82 ["client-timeout", std.toString(cfg.icecast.limits.clientTimeout)],
83 ["header-timeout", std.toString(cfg.icecast.limits.headerTimeout)],
84 ["source-timeout", std.toString(cfg.icecast.limits.sourceTimeout)],
85 ["burst-on-connect", if cfg.icecast.limits.burstOnConnect then "1" else "0"],
86 ["burst-size", std.toString(cfg.icecast.limits.burstSize)],
87 ],
88 ["authentication",
89 ["source-password", cfg.icecast.authentication.sourcePassword],
Sergiusz Bazanski9d6929f2019-06-20 12:52:38 +020090 ["relay-user", "relay"],
Sergiusz Bazanski610bec42019-06-19 14:31:19 +020091 ["relay-password", cfg.icecast.authentication.relayPassword],
Sergiusz Bazanski9d6929f2019-06-20 12:52:38 +020092 ["admin-user", "admin"],
Sergiusz Bazanski610bec42019-06-19 14:31:19 +020093 ["admin-password", cfg.icecast.authentication.adminPassword],
94 ],
95 ["hostname", cfg.icecast.hostname],
96 ["listen-socket",
97 ["port", std.toString(cfg.icecast.listenPort)],
98 ],
Sergiusz Bazanskif9281d82019-06-19 14:55:11 +020099 ["fileserve", "1"],
100 ["paths",
101 ["webroot", "/usr/share/icecast/web"],
Sergiusz Bazanski9d6929f2019-06-20 12:52:38 +0200102 ["adminroot", "/usr/share/icecast/admin"],
Sergiusz Bazanskif9281d82019-06-19 14:55:11 +0200103 ],
Sergiusz Bazanski610bec42019-06-19 14:31:19 +0200104 ["logging",
105 ["accesslog", "-"],
106 ["errorlog", "-"],
107 ["loglevel", "2"],
108 ],
109 ["security",
110 ["chroot", "0"],
111 ],
112 ] + [
113 ["mount", {type: "normal"},
114 ["mount-name", m],
115 ["username", cfg.icecast.mounts[m].username],
116 ["password", cfg.icecast.mounts[m].password],
117 ["public", if cfg.icecast.mounts[m].public then "1" else "0"],
118 ["genre", cfg.icecast.mounts[m].genre],
119 ["bitrate", std.toString(cfg.icecast.mounts[m].bitrate)],
120 ["hidden", if cfg.icecast.mounts[m].hidden then "1" else "0"],
Sergiusz Bazanski9d6929f2019-06-20 12:52:38 +0200121 ] + (if cfg.icecast.mounts[m].fallbackMount != null then [
122 ["fallback-mount", cfg.icecast.mounts[m].fallbackMount],
123 ["fallback-override", "1"],
124 ] else [])
Sergiusz Bazanski610bec42019-06-19 14:31:19 +0200125 for m in std.objectFields(cfg.icecast.mounts)
126 ]),
127 },
128 },
129
130 deployment: kube.Deployment(radio.makeName("icecast")) {
131 metadata+: radio.metadata,
132 spec+: {
133 replicas: 1,
134 template+: {
135 spec+: {
136 volumes_: {
137 config: kube.ConfigMapVolume(radio.configMap),
138 },
139 containers_: {
140 radio: kube.Container(radio.makeName("radio")) {
141 image: cfg.image,
142 ports_: {
143 client: { containerPort: cfg.icecast.listenPort },
144 },
145 volumeMounts_: {
146 config: { mountPath: "/usr/share/icecast/icecast.xml", subPath: "icecast.xml" },
147 },
148 resources: cfg.resources,
149 },
150 },
151 },
152 },
153 },
154 },
155 svc: kube.Service(radio.makeName("icecast")) {
156 metadata+: radio.metadata,
157 target_pod:: radio.deployment.spec.template,
158 spec+: {
159 ports: [
160 { name: "client", port: cfg.port, targetPort: cfg.icecast.listenPort, protocol: "TCP" },
161 ],
162 type: "LoadBalancer",
163 },
164 },
165}