-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkDeployment.nix
More file actions
77 lines (67 loc) · 2 KB
/
Copy pathmkDeployment.nix
File metadata and controls
77 lines (67 loc) · 2 KB
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, config, pkgs, ...}:
with lib;
{ name, labels, config, ... }: let
buildEnvVar = var: if (strings.hasInfix "=" var)
then let parts = splitString "=" var; in {
name = head parts;
value = toString (tail parts);
} else {
name = var;
valueFrom.secretKeyRef = {
name = config.environmentSecret; key = var;
};
};
buildEnvVars = vars: (map buildEnvVar vars);
in {
metadata.name = name;
metadata.labels = labels;
spec = {
replicas = config.scale.count;
selector.matchLabels = labels;
template = {
metadata.name = name;
metadata.labels = labels;
spec.serviceAccountName = mkIf (config.serviceAccount != null) config.serviceAccount;
spec.containers."${name}" = {
image = mkIf (config.image != null) config.image;
imagePullPolicy = "Always";
command = mkIf (config.command != null) config.command;
ports = mapAttrsToList (name: port: {
name = name;
containerPort = port;
}) config.port;
resources = {
requests = {
memory = mkIf (config.scale.memory != null)
"${toString config.scale.memory}Mi";
cpu = mkIf (config.scale.cpu != null)
"${toString config.scale.cpu}m";
};
};
# readinessProbe = mkIf (
# config.health != null &&
# (hasAttr "http" config.port)
# ) {
# httpGet = {
# path = if isString config.health
# then config.health
# else config.health.path;
# port = config.port.http;
# };
# };
# livenessProbe = mkIf (
# config.health != null &&
# (hasAttr "http" config.port)
# ) {
# httpGet = {
# path = if isString config.health
# then config.health
# else config.health.path;
# port = config.port.http;
# };
# };
env = (buildEnvVars config.environment);
};
};
};
}