Fix k8s validation

This commit is contained in:
Cyber MacGeddon 2024-09-06 23:04:07 +01:00
parent bf32118e6c
commit dde52ba6a3
9 changed files with 134 additions and 61 deletions

View file

@ -29,10 +29,15 @@ local images = import "values/images.jsonnet";
"prometheus", [ container ] "prometheus", [ container ]
); );
local service =
engine.service(containerSet)
.with_port(9090, 9090, "http");
engine.resources([ engine.resources([
cfgVol, cfgVol,
vol, vol,
containerSet, containerSet,
service,
]) ])
}, },
@ -87,6 +92,10 @@ local images = import "values/images.jsonnet";
"grafana", [ container ] "grafana", [ container ]
); );
local service =
engine.service(containerSet)
.with_port(3000, 3000, "http");
engine.resources([ engine.resources([
provVol, provVol,
dashVol, dashVol,

View file

@ -27,8 +27,8 @@ local images = import "values/images.jsonnet";
local service = local service =
engine.service(containerSet) engine.service(containerSet)
.with_port(9527, 9527) .with_port(9527, 9527, "api")
.with_port(7750, 7750); .with_port(7750, 7750, "api2);
engine.resources([ engine.resources([
containerSet, containerSet,

View file

@ -13,7 +13,7 @@ local images = import "values/images.jsonnet";
local container = local container =
engine.container("pulsar") engine.container("pulsar")
.with_image(images.pulsar) .with_image(images.pulsar)
.with_command("bin/pulsar standalone") .with_command(["bin/pulsar", "standalone"])
.with_environment({ .with_environment({
"PULSAR_MEM": "-Xms700M -Xmx700M" "PULSAR_MEM": "-Xms700M -Xmx700M"
}) })
@ -44,8 +44,8 @@ local images = import "values/images.jsonnet";
local service = local service =
engine.service(containerSet) engine.service(containerSet)
.with_port(6650, 6650) .with_port(6650, 6650, "bookie")
.with_port(8080, 8080); .with_port(8080, 8080, "http");
engine.resources([ engine.resources([
confVolume, confVolume,

View file

@ -9,6 +9,16 @@ local config = import "config.json";
// Produce patterns from config // Produce patterns from config
local patterns = decode(config); local patterns = decode(config);
local ns = {
apiVersion: "v1",
kind: "Namespace",
metadata: {
name: "trustgraph",
},
"spec": {
},
};
// Extract resources usnig the engine // Extract resources usnig the engine
local resources = std.foldl( local resources = std.foldl(
function(state, p) state + p.create(engine), 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)

View file

@ -17,10 +17,10 @@
with_environment:: function(x) self + { environment: x }, 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:: with_reservations::
function(c, m) self + { reservations: { cpus: c, memory: m } }, function(c, m) self + { reservations: { cpu: c, memory: m } },
with_volume_mount:: with_volume_mount::
function(vol, mnt) function(vol, mnt)
@ -56,54 +56,53 @@
matchLabels: { matchLabels: {
app: container.name, app: container.name,
} }
}
},
template: {
metadata: {
labels: {
app: container.name,
}
}, },
spec: { template: {
containers: [ metadata: {
{ labels: {
name: container.name, app: container.name,
image: container.image, }
resources: { },
requests: container.reservations, spec: {
limits: container.limits containers: [
}, {
} + ( name: container.name,
if std.length(container.ports) > 0 then image: container.image,
{ resources: {
ports: [ requests: container.reservations,
{ limits: container.limits
hostPort: port.src, },
containerPort: port.dest, } + (
} if std.length(container.ports) > 0 then
for port in container.ports {
] ports: [
} else {
{}) + hostPort: port.src,
containerPort: port.dest,
(if std.objectHas(container, "command") then }
{ command: container.command } for port in container.ports
else {}) +
(if std.objectHas(container, "environment") then
{ environment: [ {
name: e.key, value: e.value
}
for e in
std.objectKeysValues(
container.environment
)
] ]
} 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 (if std.length(container.volumes) > 0 then
{ {
volumes: [ volumeMounts: [
{ {
mountPath: vol.mount, mountPath: vol.mount,
name: vol.volume.name, name: vol.volume.name,
@ -123,7 +122,9 @@
] ]
} }
}, },
} + {} } + {}
}
} }
} }
@ -137,9 +138,39 @@
name: containers.name, 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() { 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" ], accessModes: [ "ReadWriteOnce" ],
hostPath: { hostPath: {
path: "/mnt/" + volume.name, path: "/data/k8s/" + volume.name,
} }
} }
}, },
@ -180,6 +211,7 @@
kind: "PersistentVolumeClaim", kind: "PersistentVolumeClaim",
metadata: { metadata: {
name: volume.name, name: volume.name,
namespace: "trustgraph",
}, },
spec: { spec: {
storageClassName: "manual", storageClassName: "manual",
@ -197,7 +229,7 @@
volRef:: function() { volRef:: function() {
name: volume.name, name: volume.name,
persistentVolumeClaim: { name: volume.name + "-pvc" }, persistentVolumeClaim: { claimName: volume.name + "-pvc" },
} }
}, },
@ -250,7 +282,10 @@
name: volume.name, name: volume.name,
namespace: "trustgraph", namespace: "trustgraph",
}, },
data: parts data: {
[item.key]: std.base64(item.value)
for item in std.objectKeysValues(parts)
}
}, },
} }
}, },
@ -279,6 +314,7 @@
}, },
resources:: function(res) resources:: function(res)
std.foldl( std.foldl(
function(state, c) state + c.add(), function(state, c) state + c.add(),
res, res,

View file

@ -26,7 +26,7 @@ local images = import "values/images.jsonnet";
local service = local service =
engine.service(containerSet) engine.service(containerSet)
.with_port(9042, 9042); .with_port(9042, 9042, "api");
engine.resources([ engine.resources([
vol, vol,

View file

@ -37,7 +37,7 @@ local images = import "values/images.jsonnet";
local service = local service =
engine.service(containerSet) engine.service(containerSet)
.with_port(2379, 2379); .with_port(2379, 2379, "api");
engine.resources([ engine.resources([
vol, vol,
@ -78,7 +78,7 @@ local images = import "values/images.jsonnet";
local service = local service =
engine.service(containerSet) engine.service(containerSet)
.with_port(9001, 9001); .with_port(9001, 9001, "api");
engine.resources([ engine.resources([
vol, vol,
@ -116,8 +116,8 @@ local images = import "values/images.jsonnet";
local service = local service =
engine.service(containerSet) engine.service(containerSet)
.with_port(9091, 9091) .with_port(9091, 9091, "api")
.with_port(19530, 19530); .with_port(19530, 19530, "api2);
engine.resources([ engine.resources([
vol, vol,

View file

@ -28,10 +28,16 @@ local images = import "values/images.jsonnet";
"neo4j", [ container ] "neo4j", [ container ]
); );
local service =
engine.service(containerSet)
.with_port(7474, 7474, "api")
.with_port(7687, 7687, "api2);
engine.resources([ engine.resources([
vol, vol,
containerSet, containerSet,
]) service,
])
}, },

View file

@ -22,9 +22,15 @@ local images = import "values/images.jsonnet";
"qdrant", [ container ] "qdrant", [ container ]
); );
local service =
engine.service(containerSet)
.with_port(6333, 6333, "api")
.with_port(6334, 6334, "api2");
engine.resources([ engine.resources([
vol, vol,
containerSet, containerSet,
service,
]) ])
}, },