diff --git a/templates/components/grafana.jsonnet b/templates/components/grafana.jsonnet index 81364f72..7dfa75ad 100644 --- a/templates/components/grafana.jsonnet +++ b/templates/components/grafana.jsonnet @@ -29,10 +29,15 @@ local images = import "values/images.jsonnet"; "prometheus", [ container ] ); + local service = + engine.service(containerSet) + .with_port(9090, 9090, "http"); + engine.resources([ cfgVol, vol, containerSet, + service, ]) }, @@ -87,6 +92,10 @@ local images = import "values/images.jsonnet"; "grafana", [ container ] ); + local service = + engine.service(containerSet) + .with_port(3000, 3000, "http"); + engine.resources([ provVol, dashVol, diff --git a/templates/components/pulsar-manager.jsonnet b/templates/components/pulsar-manager.jsonnet index 12ce99da..9a0b59b2 100644 --- a/templates/components/pulsar-manager.jsonnet +++ b/templates/components/pulsar-manager.jsonnet @@ -27,8 +27,8 @@ local images = import "values/images.jsonnet"; local service = engine.service(containerSet) - .with_port(9527, 9527) - .with_port(7750, 7750); + .with_port(9527, 9527, "api") + .with_port(7750, 7750, "api2); engine.resources([ containerSet, diff --git a/templates/components/pulsar.jsonnet b/templates/components/pulsar.jsonnet index 562e2819..fd1d437c 100644 --- a/templates/components/pulsar.jsonnet +++ b/templates/components/pulsar.jsonnet @@ -13,7 +13,7 @@ local images = import "values/images.jsonnet"; local container = engine.container("pulsar") .with_image(images.pulsar) - .with_command("bin/pulsar standalone") + .with_command(["bin/pulsar", "standalone"]) .with_environment({ "PULSAR_MEM": "-Xms700M -Xmx700M" }) @@ -44,8 +44,8 @@ local images = import "values/images.jsonnet"; local service = engine.service(containerSet) - .with_port(6650, 6650) - .with_port(8080, 8080); + .with_port(6650, 6650, "bookie") + .with_port(8080, 8080, "http"); engine.resources([ confVolume, diff --git a/templates/config-to-k8s.jsonnet b/templates/config-to-k8s.jsonnet index 4ee9d22a..ef39a5bd 100644 --- a/templates/config-to-k8s.jsonnet +++ b/templates/config-to-k8s.jsonnet @@ -9,6 +9,16 @@ local config = import "config.json"; // Produce patterns from config local patterns = decode(config); +local ns = { + apiVersion: "v1", + kind: "Namespace", + metadata: { + name: "trustgraph", + }, + "spec": { + }, +}; + // Extract resources usnig the engine local resources = std.foldl( function(state, p) state + p.create(engine), @@ -16,4 +26,10 @@ local resources = std.foldl( {} ); -std.manifestYamlDoc(resources, quote_keys=false) +local resourceList = { + apiVersion: "v1", + kind: "List", + items: [ns] + std.objectValues(resources.resources), +}; + +std.manifestYamlDoc(resourceList, quote_keys=false) diff --git a/templates/k8s.jsonnet b/templates/k8s.jsonnet index 7d275aa1..3934b492 100644 --- a/templates/k8s.jsonnet +++ b/templates/k8s.jsonnet @@ -17,10 +17,10 @@ with_environment:: function(x) self + { environment: x }, - with_limits:: function(c, m) self + { limits: { cpus: c, memory: m } }, + with_limits:: function(c, m) self + { limits: { cpu: c, memory: m } }, with_reservations:: - function(c, m) self + { reservations: { cpus: c, memory: m } }, + function(c, m) self + { reservations: { cpu: c, memory: m } }, with_volume_mount:: function(vol, mnt) @@ -56,54 +56,53 @@ matchLabels: { app: container.name, } - } - }, - template: { - metadata: { - labels: { - app: container.name, - } }, - spec: { - containers: [ - { - name: container.name, - image: container.image, - resources: { - requests: container.reservations, - limits: container.limits - }, - } + ( - if std.length(container.ports) > 0 then - { - ports: [ - { - hostPort: port.src, - containerPort: port.dest, - } - for port in container.ports - ] - } else - {}) + - - (if std.objectHas(container, "command") then - { command: container.command } - else {}) + - (if std.objectHas(container, "environment") then - { environment: [ { - name: e.key, value: e.value - } - for e in - std.objectKeysValues( - container.environment - ) + template: { + metadata: { + labels: { + app: container.name, + } + }, + spec: { + containers: [ + { + name: container.name, + image: container.image, + resources: { + requests: container.reservations, + limits: container.limits + }, + } + ( + if std.length(container.ports) > 0 then + { + ports: [ + { + hostPort: port.src, + containerPort: port.dest, + } + for port in container.ports ] + } else + {}) + + + (if std.objectHas(container, "command") then + { command: container.command } + else {}) + + (if std.objectHas(container, "environment") then + { env: [ { + name: e.key, value: e.value } - else {}) + + for e in + std.objectKeysValues( + container.environment + ) + ] + } + else {}) + (if std.length(container.volumes) > 0 then { - volumes: [ + volumeMounts: [ { mountPath: vol.mount, name: vol.volume.name, @@ -123,7 +122,9 @@ ] } }, - } + {} + } + {} + + } } } @@ -137,9 +138,39 @@ name: containers.name, - with_port:: function(src, dest) self + { port: [src, dest] }, + ports: [], + + with_port:: + function(src, dest, name) self + { + ports: super.ports + [ + { src: src, dest: dest, name: name } + ] + }, add:: function() { + resources +: { + [service.name + "-service"]: { + apiVersion: "v1", + kind: "Service", + metadata: { + name: service.name, + namespace: "trustgraph", + }, + spec: { + selector: { + app: service.name, + }, + ports: [ + { + port: port.src, + targetPort: port.dest, + name: port.name, + } + for port in service.ports + ], + } + } + } } }, @@ -171,7 +202,7 @@ }, accessModes: [ "ReadWriteOnce" ], hostPath: { - path: "/mnt/" + volume.name, + path: "/data/k8s/" + volume.name, } } }, @@ -180,6 +211,7 @@ kind: "PersistentVolumeClaim", metadata: { name: volume.name, + namespace: "trustgraph", }, spec: { storageClassName: "manual", @@ -197,7 +229,7 @@ volRef:: function() { name: volume.name, - persistentVolumeClaim: { name: volume.name + "-pvc" }, + persistentVolumeClaim: { claimName: volume.name + "-pvc" }, } }, @@ -250,7 +282,10 @@ name: volume.name, namespace: "trustgraph", }, - data: parts + data: { + [item.key]: std.base64(item.value) + for item in std.objectKeysValues(parts) + } }, } }, @@ -279,6 +314,7 @@ }, resources:: function(res) + std.foldl( function(state, c) state + c.add(), res, diff --git a/templates/stores/cassandra.jsonnet b/templates/stores/cassandra.jsonnet index f3d27025..c501e1f9 100644 --- a/templates/stores/cassandra.jsonnet +++ b/templates/stores/cassandra.jsonnet @@ -26,7 +26,7 @@ local images = import "values/images.jsonnet"; local service = engine.service(containerSet) - .with_port(9042, 9042); + .with_port(9042, 9042, "api"); engine.resources([ vol, diff --git a/templates/stores/milvus.jsonnet b/templates/stores/milvus.jsonnet index eef91172..02ca1bc0 100644 --- a/templates/stores/milvus.jsonnet +++ b/templates/stores/milvus.jsonnet @@ -37,7 +37,7 @@ local images = import "values/images.jsonnet"; local service = engine.service(containerSet) - .with_port(2379, 2379); + .with_port(2379, 2379, "api"); engine.resources([ vol, @@ -78,7 +78,7 @@ local images = import "values/images.jsonnet"; local service = engine.service(containerSet) - .with_port(9001, 9001); + .with_port(9001, 9001, "api"); engine.resources([ vol, @@ -116,8 +116,8 @@ local images = import "values/images.jsonnet"; local service = engine.service(containerSet) - .with_port(9091, 9091) - .with_port(19530, 19530); + .with_port(9091, 9091, "api") + .with_port(19530, 19530, "api2); engine.resources([ vol, diff --git a/templates/stores/neo4j.jsonnet b/templates/stores/neo4j.jsonnet index 4d74d73d..37f09e36 100644 --- a/templates/stores/neo4j.jsonnet +++ b/templates/stores/neo4j.jsonnet @@ -28,10 +28,16 @@ local images = import "values/images.jsonnet"; "neo4j", [ container ] ); + local service = + engine.service(containerSet) + .with_port(7474, 7474, "api") + .with_port(7687, 7687, "api2); + engine.resources([ vol, containerSet, - ]) + service, + ]) }, diff --git a/templates/stores/qdrant.jsonnet b/templates/stores/qdrant.jsonnet index 4e2ce40a..e8443b73 100644 --- a/templates/stores/qdrant.jsonnet +++ b/templates/stores/qdrant.jsonnet @@ -22,9 +22,15 @@ local images = import "values/images.jsonnet"; "qdrant", [ container ] ); + local service = + engine.service(containerSet) + .with_port(6333, 6333, "api") + .with_port(6334, 6334, "api2"); + engine.resources([ vol, containerSet, + service, ]) },