Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 1 | local kube = import "../../../kube/kube.libsonnet"; |
Serge Bazanski | cdba291 | 2020-08-24 19:11:10 +0000 | [diff] [blame] | 2 | |
| 3 | { |
| 4 | AppServiceIrc(name):: { |
| 5 | local bridge = self, |
| 6 | local cfg = bridge.cfg, |
| 7 | cfg:: { |
| 8 | metadata: {}, |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame] | 9 | config: std.native("parseYaml")(importstr "appservice/appservice-irc.yaml")[0], |
Serge Bazanski | cdba291 | 2020-08-24 19:11:10 +0000 | [diff] [blame] | 10 | image: error "image must be set", |
| 11 | storageClassName: error "storageClassName must be set", |
| 12 | }, |
| 13 | |
| 14 | config: kube.ConfigMap("appservice-irc-%s" % [name]) { |
| 15 | metadata+: cfg.metadata, |
| 16 | data: { |
| 17 | "config.yaml": std.manifestJsonEx(cfg.config, ""), |
| 18 | }, |
| 19 | }, |
| 20 | |
| 21 | dataVolume: kube.PersistentVolumeClaim("appservice-irc-%s" % [name]) { |
| 22 | metadata+: cfg.metadata, |
| 23 | spec+: { |
| 24 | storageClassName: cfg.storageClassName, |
| 25 | accessModes: [ "ReadWriteOnce" ], |
| 26 | resources: { |
| 27 | requests: { |
| 28 | storage: "10Gi", |
| 29 | }, |
| 30 | }, |
| 31 | }, |
| 32 | }, |
| 33 | |
| 34 | bootstrapJob: kube.Job("appservice-irc-%s-bootstrap" % [name]) { |
| 35 | metadata+: cfg.metadata { |
| 36 | labels: { |
| 37 | "job-name": "appservice-irc-%s-bootstrap" % [name], |
| 38 | }, |
| 39 | }, |
| 40 | spec+: { |
| 41 | template+: { |
| 42 | spec+: { |
| 43 | volumes_: { |
| 44 | config: kube.ConfigMapVolume(bridge.config), |
| 45 | }, |
| 46 | containers_: { |
| 47 | bootstrap: kube.Container("appservice-irc-%s-bootstrap" % [name]) { |
| 48 | image: cfg.image, |
| 49 | command: ["sh", "-c", "node app.js -r -u http://appservice-irc-%s:9999 -c /config/config.yaml -f /tmp/registration.yaml && cat /tmp/registration.yaml" % [name]], |
| 50 | volumeMounts_: { |
| 51 | config: { mountPath: "/config" }, |
| 52 | }, |
| 53 | }, |
| 54 | }, |
| 55 | }, |
| 56 | }, |
| 57 | }, |
| 58 | }, |
| 59 | |
| 60 | deployment: kube.Deployment("appservice-irc-%s" % [name]) { |
| 61 | metadata+: cfg.metadata, |
| 62 | spec+: { |
| 63 | replicas: 1, |
| 64 | template+: { |
| 65 | spec+: { |
| 66 | volumes_: { |
| 67 | config: kube.ConfigMapVolume(bridge.config), |
| 68 | data: kube.PersistentVolumeClaimVolume(bridge.dataVolume), |
| 69 | registration: { secret: { secretName: "appservice-irc-%s-registration" % [name] } }, |
| 70 | }, |
| 71 | nodeSelector: cfg.nodeSelector, |
| 72 | containers_: { |
| 73 | appserviceIrc: kube.Container("appservice-irc-%s" % [name]) { |
| 74 | image: cfg.image, |
| 75 | command: ["node", "app.js", "-c", "/config/config.yaml", "-f", "/registration/registration.yaml", "-p", "9999"], |
| 76 | ports_: { |
| 77 | http: { containerPort: 9999 }, |
| 78 | }, |
| 79 | volumeMounts_: { |
| 80 | registration: { mountPath: "/registration", }, |
| 81 | config: { mountPath: "/config", }, |
| 82 | data: { mountPath: "/data" }, |
| 83 | }, |
| 84 | }, |
| 85 | }, |
| 86 | }, |
| 87 | }, |
| 88 | }, |
| 89 | }, |
| 90 | |
| 91 | svc: kube.Service("appservice-irc-%s" % [name]) { |
| 92 | metadata+: cfg.metadata, |
| 93 | target_pod:: bridge.deployment.spec.template, |
| 94 | }, |
| 95 | }, |
| 96 | } |