matrix: split up appservice to separate file
This is in preparation for adding a Telegram bridge appservice. The main
jsonnet file was getting quite chonky.
This does not affect production, and is just a refactor.
Change-Id: I7cdee2bd71aedb40a9f6c3e5148f829023171dcb
diff --git a/app/matrix/appservice-irc.libsonnet b/app/matrix/appservice-irc.libsonnet
new file mode 100644
index 0000000..51e4f2c
--- /dev/null
+++ b/app/matrix/appservice-irc.libsonnet
@@ -0,0 +1,96 @@
+local kube = import "../../kube/kube.libsonnet";
+
+{
+ AppServiceIrc(name):: {
+ local bridge = self,
+ local cfg = bridge.cfg,
+ cfg:: {
+ metadata: {},
+ config: std.native("parseYaml")(importstr "appservice-irc.yaml")[0],
+ image: error "image must be set",
+ storageClassName: error "storageClassName must be set",
+ },
+
+ config: kube.ConfigMap("appservice-irc-%s" % [name]) {
+ metadata+: cfg.metadata,
+ data: {
+ "config.yaml": std.manifestJsonEx(cfg.config, ""),
+ },
+ },
+
+ dataVolume: kube.PersistentVolumeClaim("appservice-irc-%s" % [name]) {
+ metadata+: cfg.metadata,
+ spec+: {
+ storageClassName: cfg.storageClassName,
+ accessModes: [ "ReadWriteOnce" ],
+ resources: {
+ requests: {
+ storage: "10Gi",
+ },
+ },
+ },
+ },
+
+ bootstrapJob: kube.Job("appservice-irc-%s-bootstrap" % [name]) {
+ metadata+: cfg.metadata {
+ labels: {
+ "job-name": "appservice-irc-%s-bootstrap" % [name],
+ },
+ },
+ spec+: {
+ template+: {
+ spec+: {
+ volumes_: {
+ config: kube.ConfigMapVolume(bridge.config),
+ },
+ containers_: {
+ bootstrap: kube.Container("appservice-irc-%s-bootstrap" % [name]) {
+ image: cfg.image,
+ 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]],
+ volumeMounts_: {
+ config: { mountPath: "/config" },
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+
+ deployment: kube.Deployment("appservice-irc-%s" % [name]) {
+ metadata+: cfg.metadata,
+ spec+: {
+ replicas: 1,
+ template+: {
+ spec+: {
+ volumes_: {
+ config: kube.ConfigMapVolume(bridge.config),
+ data: kube.PersistentVolumeClaimVolume(bridge.dataVolume),
+ registration: { secret: { secretName: "appservice-irc-%s-registration" % [name] } },
+ },
+ nodeSelector: cfg.nodeSelector,
+ containers_: {
+ appserviceIrc: kube.Container("appservice-irc-%s" % [name]) {
+ image: cfg.image,
+ command: ["node", "app.js", "-c", "/config/config.yaml", "-f", "/registration/registration.yaml", "-p", "9999"],
+ ports_: {
+ http: { containerPort: 9999 },
+ },
+ volumeMounts_: {
+ registration: { mountPath: "/registration", },
+ config: { mountPath: "/config", },
+ data: { mountPath: "/data" },
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+
+ svc: kube.Service("appservice-irc-%s" % [name]) {
+ metadata+: cfg.metadata,
+ target_pod:: bridge.deployment.spec.template,
+ },
+ },
+}