1 { system ? builtins.currentSystem,
3 pkgs ? import ../../.. { inherit system config; }
6 with import ../../lib/testing-python.nix { inherit system pkgs; };
10 mkKubernetesBaseTest =
11 { name, domain ? "my.zyx", test, machines
12 , extraConfiguration ? null }:
14 masterName = head (filter (machineName: any (role: role == "master") machines.${machineName}.roles) (attrNames machines));
15 master = machines.${masterName};
17 ${master.ip} etcd.${domain}
18 ${master.ip} api.${domain}
19 ${concatMapStringsSep "\n" (machineName: "${machines.${machineName}.ip} ${machineName}.${domain}") (attrNames machines)}
21 wrapKubectl = with pkgs; runCommand "wrap-kubectl" { nativeBuildInputs = [ makeWrapper ]; } ''
23 makeWrapper ${pkgs.kubernetes}/bin/kubectl $out/bin/kubectl --set KUBECONFIG "/etc/kubernetes/cluster-admin.kubeconfig"
28 nodes = mapAttrs (machineName: machine:
29 { config, pkgs, lib, nodes, ... }:
32 boot.postBootCommands = "rm -fr /var/lib/kubernetes/secrets /tmp/shared/*";
33 virtualisation.memorySize = mkDefault 1536;
34 virtualisation.diskSize = mkDefault 4096;
36 inherit domain extraHosts;
37 primaryIPAddress = mkForce machine.ip;
43 trustedInterfaces = ["mynet"];
45 extraCommands = concatMapStrings (node: ''
46 iptables -A INPUT -s ${node.networking.primaryIPAddress} -j ACCEPT
47 '') (attrValues nodes);
50 programs.bash.completion.enable = true;
51 environment.systemPackages = [ wrapKubectl ];
52 services.flannel.iface = "eth1";
53 services.kubernetes = {
54 proxy.hostname = "${masterName}.${domain}";
57 inherit (machine) roles;
60 advertiseAddress = master.ip;
62 # NOTE: what featureGates are useful for testing might change in
63 # the future, see link below to find new ones
64 # https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/
65 featureGates = {AnonymousAuthConfigurableEndpoints = true; ConsistentListFromCache = false;};
66 masterAddress = "${masterName}.${config.networking.domain}";
69 (optionalAttrs (any (role: role == "master") machine.roles) {
70 networking.firewall.allowedTCPPorts = [
71 443 # kubernetes apiserver
74 (optionalAttrs (machine ? extraConfiguration) (machine.extraConfiguration { inherit config pkgs lib nodes; }))
75 (optionalAttrs (extraConfiguration != null) (extraConfiguration { inherit config pkgs lib nodes; }))
84 mkKubernetesMultiNodeTest = attrs: mkKubernetesBaseTest ({
96 name = "kubernetes-${attrs.name}-multinode";
99 mkKubernetesSingleNodeTest = attrs: mkKubernetesBaseTest ({
102 roles = ["master" "node"];
107 name = "kubernetes-${attrs.name}-singlenode";
110 inherit mkKubernetesBaseTest mkKubernetesSingleNodeTest mkKubernetesMultiNodeTest;