Modularize k8s configs
This commit is contained in:
132
lib/default.nix
132
lib/default.nix
@@ -11,70 +11,76 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
# hostCerts = builtins.foldl'
|
||||
# (a: x: a // { ${x.name} = pki.gencert {
|
||||
# cn = x.name;
|
||||
# ca = x.ca;
|
||||
# o = cfg.clusterName;
|
||||
# };
|
||||
# }) {} cfg.hosts;
|
||||
hostCerts = builtins.foldl'
|
||||
(a: x: a // { ${x.name} = pki.gencert {
|
||||
cn = x.name;
|
||||
ca = x.ca;
|
||||
o = cfg.clusterName;
|
||||
};
|
||||
}) {} cfg.hosts;
|
||||
|
||||
# mkHost = host: self: {
|
||||
# deployment.targetHost = host.address;
|
||||
# require = [
|
||||
# (baseNixos host.name)
|
||||
# ];
|
||||
# };
|
||||
mkHost = host: self: {
|
||||
deployment.targetHost = host.address;
|
||||
require = [
|
||||
(baseNixos host.name)
|
||||
];
|
||||
};
|
||||
|
||||
# baseDeployment = nodes: attrs:
|
||||
# let
|
||||
# hosts =
|
||||
# builtins.foldl'
|
||||
# (a: x: a // { ${x.name} = mkHost x _; }) {} nodes;
|
||||
# hosts' = lib.recursiveUpdate hosts attrs;
|
||||
# names = builtins.attrNames hosts;
|
||||
# in
|
||||
# builtins.foldl' (a: x: a // { ${x} = self: hosts'.${x}; }) {} names;
|
||||
baseDeployment = nodes: attrs:
|
||||
let
|
||||
hosts =
|
||||
builtins.foldl'
|
||||
(a: x: a // { ${x.name} = mkHost x _; }) {} nodes;
|
||||
hosts' = lib.recursiveUpdate hosts attrs;
|
||||
names = builtins.attrNames hosts;
|
||||
in
|
||||
builtins.foldl' (a: x: a // { ${x} = self: hosts'.${x}; }) {} names;
|
||||
|
||||
in {
|
||||
k8s = rec {
|
||||
master = host: self: {
|
||||
deployment.targetHost = host.address;
|
||||
|
||||
# k8s = import ./k8s.nix { inherit pgks lib config; };
|
||||
cluster = cfg // {
|
||||
hostName = host.name;
|
||||
cert = mkCert host.name;
|
||||
k8s.master.enable = true;
|
||||
k8s.node.enable = true;
|
||||
};
|
||||
|
||||
# k8s = rec {
|
||||
# apiserver = host: self: {
|
||||
# deployment.targetHost = host.address;
|
||||
# require = [
|
||||
# (os.baseNixos host.name)
|
||||
# k8s.kubeMaster
|
||||
# ];
|
||||
# };
|
||||
imports = [ host.hw ./k8s.nix ];
|
||||
};
|
||||
|
||||
# node = host: self: {
|
||||
# deployment.targetHost = host.address;
|
||||
# require = [
|
||||
# (os.baseNixos host.name)
|
||||
# k8s.kubeWorker
|
||||
# ];
|
||||
# };
|
||||
node = host: self: {
|
||||
deployment.targetHost = host.address;
|
||||
|
||||
# deployment = masterNode: workerNodes:
|
||||
# let
|
||||
# master = { "${master.name}" = apiserver masterNode; };
|
||||
# in
|
||||
# builtins.foldl' (a: x:
|
||||
# a // { "${x.name}" = mkWorker x; }) master workerNodes;
|
||||
# };
|
||||
cluster = cfg // {
|
||||
hostName = host.name;
|
||||
cert = mkCert host.name;
|
||||
k8s.node.enable = true;
|
||||
};
|
||||
|
||||
imports = [ host.hw ./k8s.nix ];
|
||||
};
|
||||
|
||||
mkDeployment = masterNode: workerNodes:
|
||||
let
|
||||
apiserver = { "${master.name}" = apiserver masterNode; };
|
||||
in
|
||||
builtins.foldl' (a: x:
|
||||
a // { "${x.name}" = mkWorker x; }) apiserver workerNodes;
|
||||
};
|
||||
|
||||
fs = rec {
|
||||
mkNode = host: self: {
|
||||
deployment.targetHost = host.address;
|
||||
|
||||
imports = [ host.hw ./fs.nix ];
|
||||
|
||||
cluster = cfg // {
|
||||
hostName = host.name;
|
||||
cert = mkCert host.name;
|
||||
};
|
||||
|
||||
imports = [ host.hw ./fs.nix ];
|
||||
};
|
||||
|
||||
mkDeployment = nodes:
|
||||
@@ -82,19 +88,23 @@ in {
|
||||
a // { "${x.name}" = mkNode x; }) {} nodes;
|
||||
} ;
|
||||
|
||||
# host = rec {
|
||||
# node = host: self: {
|
||||
# deployment.targetHost = host.address;
|
||||
# require = [
|
||||
# (os.baseNixos host.name)
|
||||
# ];
|
||||
# };
|
||||
host = rec {
|
||||
node = host: self: {
|
||||
deployment.targetHost = host.address;
|
||||
|
||||
# deployment = masterNode: workerNodes:
|
||||
# let
|
||||
# master = { "${master.name}" = apiserver masterNode; };
|
||||
# in
|
||||
# builtins.foldl' (a: x:
|
||||
# a // { "${x.name}" = mkWorker x; }) master workerNodes;
|
||||
# };
|
||||
cluster = cfg // {
|
||||
hostName = host.name;
|
||||
cert = mkCert host.name;
|
||||
};
|
||||
|
||||
imports = [ host.hw ./os.nix ];
|
||||
};
|
||||
|
||||
mkDeployment = masterNode: workerNodes:
|
||||
let
|
||||
master = { "${master.name}" = apiserver masterNode; };
|
||||
in
|
||||
builtins.foldl' (a: x:
|
||||
a // { "${x.name}" = mkWorker x; }) master workerNodes;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user