1
0
Fork 0
mirror of https://git.sr.ht/~goorzhel/turboprop synced 2024-12-14 11:37:37 +00:00
turboprop/lib/app-template.nix

73 lines
1.5 KiB
Nix
Raw Normal View History

{
charts,
kubelib,
pkgs,
vars,
}: rec {
strToImageAttrs = string:
with builtins; let
vals = split ":" string;
in {
repository = elemAt vals 0;
tag = elemAt vals 2;
};
mkExistingClaim = pvc: subPath: {
2023-11-18 10:29:24 +00:00
existingClaim = pvc;
inherit subPath;
};
mkSimpleHTTPRoute = namespace: name: port: {
2023-11-18 10:08:23 +00:00
service.main.ports.http.port = port;
route.main = {
enabled = true;
2023-11-18 22:16:53 +00:00
hostnames = ["${name}.${vars.svcGateway.domain}"];
2023-11-18 10:08:23 +00:00
parentRefs = [
{
inherit namespace;
2023-11-18 22:16:53 +00:00
name = vars.svcGateway.name;
2023-11-18 10:08:23 +00:00
sectionName = "https";
}
];
rules = [
{backendRefs = [{inherit name namespace port;}];}
];
};
};
appTemplate = {
namespace,
name,
mainImage,
nfsConfigVolume ? false,
httpPort ? false,
extraValues ? {},
}: let
configVolume = {
persistence.config =
if nfsConfigVolume
then mkExistingClaim "svc" name
else
# TODO: There' room here to chain other types, like
# if longhornVolume then {...} else ...
{};
};
httpRoute =
if httpPort != false
then mkSimpleHTTPRoute namespace name httpPort
else {};
in
kubelib.buildHelmChart {
inherit name namespace;
chart = charts.bjw-s.app-template;
values =
pkgs.lib.attrsets.recursiveUpdate
(configVolume
// httpRoute
// {
controllers.main.containers.main.image = strToImageAttrs mainImage;
})
extraValues;
};
2023-11-18 10:08:23 +00:00
}