-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.nix
77 lines (66 loc) · 1.91 KB
/
service.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ lib, k8s, options, config, pkgs, ...}:
with lib;
let
convox-options = pkgs.callPackage ./options.nix {};
mkDeployment = pkgs.callPackage ./mkDeployment.nix { k8s = k8s; };
in {
kubernetes.moduleDefinitions.convox-service.prefixResources = true;
kubernetes.moduleDefinitions.convox-service.module = { name, config, ... }: {
imports = [];
options = (convox-options.service {
inherit name config;
}).options;
config =
let
name = config.name;
labels = {
system = "convox-nix";
service = name;
} // config.labels;
in {
kubernetes.resources.deployments.${name} = mkDeployment {
inherit name labels config;
};
kubernetes.resources.services.${name} = {
metadata.name = name;
metadata.labels = labels;
spec = {
type = "ClusterIP";
ports = mapAttrsToList (name: port: {
name = name;
port = port;
targetPort = port;
}) config.port;
selector = labels;
};
};
kubernetes.resources.ingresses = mkIf (length config.domains > 0) {
${name} = {
metadata.name = name;
metadata.labels = labels;
metadata.annotations = {
"kubernetes.io/tls-acme" = "true";
};
spec = {
tls = [
{
secretName = "${name}-tls";
hosts = config.domains;
}
];
rules = map (domain: {
host = domain;
http.paths = [
{
path = "/";
backend.serviceName = name;
backend.servicePort = config.port.http;
}
];
}) config.domains;
};
};
};
};
};
}