blob: 83e0f43e774e09f83202aa87cc3d624a52d7659c [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],
90 ["relay-password", cfg.icecast.authentication.relayPassword],
91 ["admin-password", cfg.icecast.authentication.adminPassword],
92 ],
93 ["hostname", cfg.icecast.hostname],
94 ["listen-socket",
95 ["port", std.toString(cfg.icecast.listenPort)],
96 ],
Sergiusz Bazanskif9281d82019-06-19 14:55:11 +020097 ["fileserve", "1"],
98 ["paths",
99 ["webroot", "/usr/share/icecast/web"],
100 ],
Sergiusz Bazanski610bec42019-06-19 14:31:19 +0200101 ["logging",
102 ["accesslog", "-"],
103 ["errorlog", "-"],
104 ["loglevel", "2"],
105 ],
106 ["security",
107 ["chroot", "0"],
108 ],
109 ] + [
110 ["mount", {type: "normal"},
111 ["mount-name", m],
112 ["username", cfg.icecast.mounts[m].username],
113 ["password", cfg.icecast.mounts[m].password],
114 ["public", if cfg.icecast.mounts[m].public then "1" else "0"],
115 ["genre", cfg.icecast.mounts[m].genre],
116 ["bitrate", std.toString(cfg.icecast.mounts[m].bitrate)],
117 ["hidden", if cfg.icecast.mounts[m].hidden then "1" else "0"],
Sergiusz Bazanskif9281d82019-06-19 14:55:11 +0200118 ] + (if cfg.icecast.mounts[m].fallbackMount != null then
119 [["fallback-mount", cfg.icecast.mounts[m].fallbackMount]] else []
120 )
Sergiusz Bazanski610bec42019-06-19 14:31:19 +0200121 for m in std.objectFields(cfg.icecast.mounts)
122 ]),
123 },
124 },
125
126 deployment: kube.Deployment(radio.makeName("icecast")) {
127 metadata+: radio.metadata,
128 spec+: {
129 replicas: 1,
130 template+: {
131 spec+: {
132 volumes_: {
133 config: kube.ConfigMapVolume(radio.configMap),
134 },
135 containers_: {
136 radio: kube.Container(radio.makeName("radio")) {
137 image: cfg.image,
138 ports_: {
139 client: { containerPort: cfg.icecast.listenPort },
140 },
141 volumeMounts_: {
142 config: { mountPath: "/usr/share/icecast/icecast.xml", subPath: "icecast.xml" },
143 },
144 resources: cfg.resources,
145 },
146 },
147 },
148 },
149 },
150 },
151 svc: kube.Service(radio.makeName("icecast")) {
152 metadata+: radio.metadata,
153 target_pod:: radio.deployment.spec.template,
154 spec+: {
155 ports: [
156 { name: "client", port: cfg.port, targetPort: cfg.icecast.listenPort, protocol: "TCP" },
157 ],
158 type: "LoadBalancer",
159 },
160 },
161}