blob: 51e4f2c4c7a71a50068e6c14ae29e14f41003c28 [file] [log] [blame]
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,
},
},
}