-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkubernetes-job.nix
86 lines (81 loc) · 3.45 KB
/
kubernetes-job.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
78
79
80
81
82
83
84
85
86
topLevel@{ flake-parts-lib, inputs, ... }: {
imports = [
./jobs.nix
./kubernetes.nix
./nixpkgs.nix
inputs.flake-parts.flakeModules.flakeModules
];
flake.flakeModules.kubernetesJob = {
imports = [
topLevel.config.flake.flakeModules.jobs
topLevel.config.flake.flakeModules.kubernetes
topLevel.config.flake.flakeModules.nixpkgs
];
options.perSystem = flake-parts-lib.mkPerSystemOption (perSystem@{ lib, config, pkgs, system, ... }: {
ml-ops.job = job: {
launcher = launcher: {
options.kubernetes = lib.mkOption {
type = lib.types.submoduleWith {
modules = [
(
kubernetes: {
options.helmTemplates = lib.mkOption {
type = lib.types.submoduleWith {
modules = [
{
options.job = lib.attrsets.mapAttrsRecursive
(path: value: lib.mkOption { default = value; })
{
apiVersion = "batch/v1";
kind = "Job";
spec.backoffLimit = 0;
spec.template.metadata.labels."app.kubernetes.io/name" = "${job.config._module.args.name}-${launcher.config._module.args.name}";
spec.template.spec.restartPolicy = "Never";
spec.template.spec.volumes = kubernetes.config.volumes;
};
}
{
options.job.metadata.name = lib.mkOption {
default = "${job.config._module.args.name}-${launcher.config._module.args.name}-${builtins.replaceStrings ["+"] ["-"] job.config.version}";
defaultText = lib.literalExpression ''
"''${job.config._module.args.name}-''${launcher.config._module.args.name}-''${builtins.replaceStrings ["+"] ["-"] job.config.version}"
'';
};
config.job.spec.template.spec.containers =
lib.mapAttrs
(containerName: container: container.manifest)
kubernetes.config.containers;
options.job.spec.template.spec.containers = lib.mkOption {
type = lib.types.attrsOf (lib.types.submoduleWith {
modules = [
kubernetes.config.containerManifest
];
});
apply = lib.attrsets.mapAttrsToList (name: value:
value // {
inherit name;
}
);
};
}
];
};
};
}
)
];
};
};
};
};
ml-ops.devcontainer.devenvShellModule = {
packages = lib.mkAfter [
pkgs.kubernetes-helm
];
};
packages =
topLevel.config.flake.lib.findKubernetesPackages
perSystem.config.ml-ops.jobs;
});
};
}