1 { system ? builtins.currentSystem, pkgs ? import ../../.. { inherit system; } }:
2 with import ./base.nix { inherit system; };
6 redisPod = pkgs.writeText "redis-pod.json" (builtins.toJSON {
9 metadata.name = "redis";
10 metadata.labels.name = "redis";
14 args = ["--bind" "0.0.0.0"];
15 imagePullPolicy = "Never";
17 name = "redis-server";
23 redisService = pkgs.writeText "redis-service.json" (builtins.toJSON {
26 metadata.name = "redis";
28 ports = [{port = 6379; targetPort = 6379;}];
29 selector = {name = "redis";};
33 redisImage = pkgs.dockerTools.buildImage {
36 copyToRoot = pkgs.buildEnv {
38 pathsToLink = [ "/bin" ];
39 paths = [ pkgs.redis pkgs.bind.host ];
41 config.Entrypoint = ["/bin/redis-server"];
44 probePod = pkgs.writeText "probe-pod.json" (builtins.toJSON {
47 metadata.name = "probe";
48 metadata.labels.name = "probe";
54 imagePullPolicy = "Never";
58 probeImage = pkgs.dockerTools.buildImage {
61 copyToRoot = pkgs.buildEnv {
63 pathsToLink = [ "/bin" ];
64 paths = [ pkgs.bind.host pkgs.busybox ];
66 config.Entrypoint = ["/bin/tail"];
69 extraConfiguration = { config, pkgs, lib, ... }: {
70 environment.systemPackages = [ pkgs.bind.host ];
71 services.dnsmasq.enable = true;
72 services.dnsmasq.servers = [
73 "/cluster.local/${config.services.kubernetes.addons.dns.clusterIp}#53"
79 inherit domain extraConfiguration;
84 # prepare machine1 for test
85 machine1.wait_until_succeeds("kubectl get node machine1.${domain} | grep -w Ready")
86 machine1.wait_until_succeeds(
87 "${pkgs.gzip}/bin/zcat ${redisImage} | ${pkgs.containerd}/bin/ctr -n k8s.io image import -"
89 machine1.wait_until_succeeds(
90 "kubectl create -f ${redisPod}"
92 machine1.wait_until_succeeds(
93 "kubectl create -f ${redisService}"
95 machine1.wait_until_succeeds(
96 "${pkgs.gzip}/bin/zcat ${probeImage} | ${pkgs.containerd}/bin/ctr -n k8s.io image import -"
98 machine1.wait_until_succeeds(
99 "kubectl create -f ${probePod}"
102 # check if pods are running
103 machine1.wait_until_succeeds("kubectl get pod redis | grep Running")
104 machine1.wait_until_succeeds("kubectl get pod probe | grep Running")
105 machine1.wait_until_succeeds("kubectl get pods -n kube-system | grep 'coredns.*1/1'")
107 # check dns on host (dnsmasq)
108 machine1.succeed("host redis.default.svc.cluster.local")
110 # check dns inside the container
111 machine1.succeed("kubectl exec probe -- /bin/host redis.default.svc.cluster.local")
117 # Node token exchange
118 machine1.wait_until_succeeds(
119 "cp -f /var/lib/cfssl/apitoken.secret /tmp/shared/apitoken.secret"
121 machine2.wait_until_succeeds(
122 "cat /tmp/shared/apitoken.secret | nixos-kubernetes-node-join"
125 # prepare machines for test
126 machine1.wait_until_succeeds("kubectl get node machine2.${domain} | grep -w Ready")
127 machine2.wait_until_succeeds(
128 "${pkgs.gzip}/bin/zcat ${redisImage} | ${pkgs.containerd}/bin/ctr -n k8s.io image import -"
130 machine1.wait_until_succeeds(
131 "kubectl create -f ${redisPod}"
133 machine1.wait_until_succeeds(
134 "kubectl create -f ${redisService}"
136 machine2.wait_until_succeeds(
137 "${pkgs.gzip}/bin/zcat ${probeImage} | ${pkgs.containerd}/bin/ctr -n k8s.io image import -"
139 machine1.wait_until_succeeds(
140 "kubectl create -f ${probePod}"
143 # check if pods are running
144 machine1.wait_until_succeeds("kubectl get pod redis | grep Running")
145 machine1.wait_until_succeeds("kubectl get pod probe | grep Running")
146 machine1.wait_until_succeeds("kubectl get pods -n kube-system | grep 'coredns.*1/1'")
148 # check dns on hosts (dnsmasq)
149 machine1.succeed("host redis.default.svc.cluster.local")
150 machine2.succeed("host redis.default.svc.cluster.local")
152 # check dns inside the container
153 machine1.succeed("kubectl exec probe -- /bin/host redis.default.svc.cluster.local")
157 singlenode = mkKubernetesSingleNodeTest (base // singleNodeTest);
158 multinode = mkKubernetesMultiNodeTest (base // multiNodeTest);