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 ]
);
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,

View file

@ -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,

View file

@ -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,

View file

@ -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)

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,
])
},

View file

@ -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,
])
},