Sergiusz Bazanski | 610bec4 | 2019-06-19 14:31:19 +0200 | [diff] [blame] | 1 | local 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 Bazanski | 2d81427 | 2019-09-25 13:58:48 +0200 | [diff] [blame] | 34 | mounts: {}, |
| 35 | relays: {}, |
Sergiusz Bazanski | 610bec4 | 2019-06-19 14:31:19 +0200 | [diff] [blame] | 36 | }, |
| 37 | |
| 38 | tag: "latest", |
| 39 | image: "registry.k0.hswaw.net/app/radio:" + cfg.tag, |
| 40 | resources: { |
| 41 | requests: { |
Sergiusz Bazanski | c807f86 | 2019-06-19 16:18:28 +0200 | [diff] [blame] | 42 | cpu: "25m", |
| 43 | memory: "50Mi", |
Sergiusz Bazanski | 610bec4 | 2019-06-19 14:31:19 +0200 | [diff] [blame] | 44 | }, |
| 45 | limits: { |
Sergiusz Bazanski | c807f86 | 2019-06-19 16:18:28 +0200 | [diff] [blame] | 46 | cpu: "100m", |
Sergiusz Bazanski | 610bec4 | 2019-06-19 14:31:19 +0200 | [diff] [blame] | 47 | 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 Bazanski | f9281d8 | 2019-06-19 14:55:11 +0200 | [diff] [blame] | 58 | fallbackMount: null, |
Sergiusz Bazanski | 610bec4 | 2019-06-19 14:31:19 +0200 | [diff] [blame] | 59 | }, |
| 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 Bazanski | 9d6929f | 2019-06-20 12:52:38 +0200 | [diff] [blame] | 91 | ["relay-user", "relay"], |
Sergiusz Bazanski | 610bec4 | 2019-06-19 14:31:19 +0200 | [diff] [blame] | 92 | ["relay-password", cfg.icecast.authentication.relayPassword], |
Sergiusz Bazanski | 9d6929f | 2019-06-20 12:52:38 +0200 | [diff] [blame] | 93 | ["admin-user", "admin"], |
Sergiusz Bazanski | 610bec4 | 2019-06-19 14:31:19 +0200 | [diff] [blame] | 94 | ["admin-password", cfg.icecast.authentication.adminPassword], |
| 95 | ], |
| 96 | ["hostname", cfg.icecast.hostname], |
| 97 | ["listen-socket", |
| 98 | ["port", std.toString(cfg.icecast.listenPort)], |
| 99 | ], |
Sergiusz Bazanski | f9281d8 | 2019-06-19 14:55:11 +0200 | [diff] [blame] | 100 | ["fileserve", "1"], |
| 101 | ["paths", |
| 102 | ["webroot", "/usr/share/icecast/web"], |
Sergiusz Bazanski | 9d6929f | 2019-06-20 12:52:38 +0200 | [diff] [blame] | 103 | ["adminroot", "/usr/share/icecast/admin"], |
Sergiusz Bazanski | f9281d8 | 2019-06-19 14:55:11 +0200 | [diff] [blame] | 104 | ], |
Sergiusz Bazanski | 610bec4 | 2019-06-19 14:31:19 +0200 | [diff] [blame] | 105 | ["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 Bazanski | 9d6929f | 2019-06-20 12:52:38 +0200 | [diff] [blame] | 122 | ] + (if cfg.icecast.mounts[m].fallbackMount != null then [ |
| 123 | ["fallback-mount", cfg.icecast.mounts[m].fallbackMount], |
| 124 | ["fallback-override", "1"], |
| 125 | ] else []) |
Sergiusz Bazanski | 610bec4 | 2019-06-19 14:31:19 +0200 | [diff] [blame] | 126 | for m in std.objectFields(cfg.icecast.mounts) |
Sergiusz Bazanski | 2d81427 | 2019-09-25 13:58:48 +0200 | [diff] [blame] | 127 | ] + [ |
| 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], |
| 138 | ] else []) |
| 139 | for r in std.objectFields(cfg.icecast.relays) |
| 140 | ]), |
Sergiusz Bazanski | 610bec4 | 2019-06-19 14:31:19 +0200 | [diff] [blame] | 141 | }, |
| 142 | }, |
| 143 | |
| 144 | deployment: kube.Deployment(radio.makeName("icecast")) { |
| 145 | metadata+: radio.metadata, |
| 146 | spec+: { |
| 147 | replicas: 1, |
| 148 | template+: { |
| 149 | spec+: { |
| 150 | volumes_: { |
| 151 | config: kube.ConfigMapVolume(radio.configMap), |
| 152 | }, |
| 153 | containers_: { |
| 154 | radio: kube.Container(radio.makeName("radio")) { |
| 155 | image: cfg.image, |
| 156 | ports_: { |
| 157 | client: { containerPort: cfg.icecast.listenPort }, |
| 158 | }, |
| 159 | volumeMounts_: { |
| 160 | config: { mountPath: "/usr/share/icecast/icecast.xml", subPath: "icecast.xml" }, |
| 161 | }, |
| 162 | resources: cfg.resources, |
| 163 | }, |
| 164 | }, |
| 165 | }, |
| 166 | }, |
| 167 | }, |
| 168 | }, |
| 169 | svc: kube.Service(radio.makeName("icecast")) { |
| 170 | metadata+: radio.metadata, |
| 171 | target_pod:: radio.deployment.spec.template, |
| 172 | spec+: { |
| 173 | ports: [ |
| 174 | { name: "client", port: cfg.port, targetPort: cfg.icecast.listenPort, protocol: "TCP" }, |
Sergiusz Bazanski | 2d81427 | 2019-09-25 13:58:48 +0200 | [diff] [blame] | 175 | { name: "client80", port: 80, targetPort: cfg.icecast.listenPort, protocol: "TCP" }, |
Sergiusz Bazanski | 610bec4 | 2019-06-19 14:31:19 +0200 | [diff] [blame] | 176 | ], |
| 177 | type: "LoadBalancer", |
| 178 | }, |
| 179 | }, |
| 180 | } |