2017-09-09 02:00:35 +02:00
|
|
|
{ system ? builtins.currentSystem, pkgs ? import <nixpkgs> { inherit system; } }:
|
|
|
|
with import ./base.nix { inherit system; };
|
2017-05-03 01:20:32 +02:00
|
|
|
let
|
2017-09-09 02:00:35 +02:00
|
|
|
domain = "my.zyx";
|
2017-05-03 01:20:32 +02:00
|
|
|
|
2017-09-09 02:00:35 +02:00
|
|
|
redisPod = pkgs.writeText "redis-pod.json" (builtins.toJSON {
|
2017-05-03 01:20:32 +02:00
|
|
|
kind = "Pod";
|
|
|
|
apiVersion = "v1";
|
|
|
|
metadata.name = "redis";
|
|
|
|
metadata.labels.name = "redis";
|
|
|
|
spec.containers = [{
|
|
|
|
name = "redis";
|
|
|
|
image = "redis";
|
|
|
|
args = ["--bind" "0.0.0.0"];
|
|
|
|
imagePullPolicy = "Never";
|
|
|
|
ports = [{
|
|
|
|
name = "redis-server";
|
|
|
|
containerPort = 6379;
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
});
|
|
|
|
|
|
|
|
redisService = pkgs.writeText "redis-service.json" (builtins.toJSON {
|
|
|
|
kind = "Service";
|
|
|
|
apiVersion = "v1";
|
|
|
|
metadata.name = "redis";
|
|
|
|
spec = {
|
|
|
|
ports = [{port = 6379; targetPort = 6379;}];
|
|
|
|
selector = {name = "redis";};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
redisImage = pkgs.dockerTools.buildImage {
|
|
|
|
name = "redis";
|
|
|
|
tag = "latest";
|
2017-09-09 02:00:35 +02:00
|
|
|
contents = [ pkgs.redis pkgs.bind.host ];
|
2017-05-03 01:20:32 +02:00
|
|
|
config.Entrypoint = "/bin/redis-server";
|
|
|
|
};
|
|
|
|
|
2017-09-09 02:00:35 +02:00
|
|
|
probePod = pkgs.writeText "probe-pod.json" (builtins.toJSON {
|
|
|
|
kind = "Pod";
|
|
|
|
apiVersion = "v1";
|
|
|
|
metadata.name = "probe";
|
|
|
|
metadata.labels.name = "probe";
|
|
|
|
spec.containers = [{
|
|
|
|
name = "probe";
|
|
|
|
image = "probe";
|
|
|
|
args = [ "-f" ];
|
|
|
|
tty = true;
|
|
|
|
imagePullPolicy = "Never";
|
|
|
|
}];
|
|
|
|
});
|
|
|
|
|
|
|
|
probeImage = pkgs.dockerTools.buildImage {
|
|
|
|
name = "probe";
|
|
|
|
tag = "latest";
|
|
|
|
contents = [ pkgs.bind.host pkgs.busybox ];
|
|
|
|
config.Entrypoint = "/bin/tail";
|
|
|
|
};
|
|
|
|
|
2018-07-20 22:56:59 +02:00
|
|
|
extraConfiguration = { config, pkgs, ... }: {
|
2017-09-09 02:00:35 +02:00
|
|
|
environment.systemPackages = [ pkgs.bind.host ];
|
|
|
|
# virtualisation.docker.extraOptions = "--dns=${config.services.kubernetes.addons.dns.clusterIp}";
|
|
|
|
services.dnsmasq.enable = true;
|
|
|
|
services.dnsmasq.servers = [
|
|
|
|
"/cluster.local/${config.services.kubernetes.addons.dns.clusterIp}#53"
|
|
|
|
];
|
2017-05-03 01:20:32 +02:00
|
|
|
};
|
|
|
|
|
2017-09-09 02:00:35 +02:00
|
|
|
base = {
|
|
|
|
name = "dns";
|
2018-07-22 13:14:20 +02:00
|
|
|
inherit domain extraConfiguration;
|
2017-09-09 02:00:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
singleNodeTest = {
|
|
|
|
test = ''
|
|
|
|
# prepare machine1 for test
|
2020-05-14 15:14:02 +02:00
|
|
|
machine1.wait_until_succeeds("kubectl get node machine1.${domain} | grep -w Ready")
|
|
|
|
machine1.wait_until_succeeds(
|
|
|
|
"docker load < ${redisImage}"
|
|
|
|
)
|
|
|
|
machine1.wait_until_succeeds(
|
|
|
|
"kubectl create -f ${redisPod}"
|
|
|
|
)
|
|
|
|
machine1.wait_until_succeeds(
|
|
|
|
"kubectl create -f ${redisService}"
|
|
|
|
)
|
|
|
|
machine1.wait_until_succeeds(
|
|
|
|
"docker load < ${probeImage}"
|
|
|
|
)
|
|
|
|
machine1.wait_until_succeeds(
|
|
|
|
"kubectl create -f ${probePod}"
|
|
|
|
)
|
2017-09-09 02:00:35 +02:00
|
|
|
|
|
|
|
# check if pods are running
|
2020-05-14 15:14:02 +02:00
|
|
|
machine1.wait_until_succeeds("kubectl get pod redis | grep Running")
|
|
|
|
machine1.wait_until_succeeds("kubectl get pod probe | grep Running")
|
|
|
|
machine1.wait_until_succeeds("kubectl get pods -n kube-system | grep 'coredns.*1/1'")
|
2017-09-09 02:00:35 +02:00
|
|
|
|
|
|
|
# check dns on host (dnsmasq)
|
2020-05-14 15:14:02 +02:00
|
|
|
machine1.succeed("host redis.default.svc.cluster.local")
|
2017-09-09 02:00:35 +02:00
|
|
|
|
|
|
|
# check dns inside the container
|
2020-05-14 15:14:02 +02:00
|
|
|
machine1.succeed("kubectl exec -ti probe -- /bin/host redis.default.svc.cluster.local")
|
2017-09-09 02:00:35 +02:00
|
|
|
'';
|
|
|
|
};
|
2017-05-03 01:20:32 +02:00
|
|
|
|
2017-09-09 02:00:35 +02:00
|
|
|
multiNodeTest = {
|
|
|
|
test = ''
|
2018-07-22 13:14:20 +02:00
|
|
|
# Node token exchange
|
2020-05-14 15:14:02 +02:00
|
|
|
machine1.wait_until_succeeds(
|
|
|
|
"cp -f /var/lib/cfssl/apitoken.secret /tmp/shared/apitoken.secret"
|
|
|
|
)
|
|
|
|
machine2.wait_until_succeeds(
|
|
|
|
"cat /tmp/shared/apitoken.secret | nixos-kubernetes-node-join"
|
|
|
|
)
|
2018-07-22 13:14:20 +02:00
|
|
|
|
2017-09-09 02:00:35 +02:00
|
|
|
# prepare machines for test
|
2020-05-14 15:14:02 +02:00
|
|
|
machine1.wait_until_succeeds("kubectl get node machine2.${domain} | grep -w Ready")
|
|
|
|
machine2.wait_until_succeeds(
|
|
|
|
"docker load < ${redisImage}"
|
|
|
|
)
|
|
|
|
machine1.wait_until_succeeds(
|
|
|
|
"kubectl create -f ${redisPod}"
|
|
|
|
)
|
|
|
|
machine1.wait_until_succeeds(
|
|
|
|
"kubectl create -f ${redisService}"
|
|
|
|
)
|
|
|
|
machine2.wait_until_succeeds(
|
|
|
|
"docker load < ${probeImage}"
|
|
|
|
)
|
|
|
|
machine1.wait_until_succeeds(
|
|
|
|
"kubectl create -f ${probePod}"
|
|
|
|
)
|
2017-09-09 02:00:35 +02:00
|
|
|
|
|
|
|
# check if pods are running
|
2020-05-14 15:14:02 +02:00
|
|
|
machine1.wait_until_succeeds("kubectl get pod redis | grep Running")
|
|
|
|
machine1.wait_until_succeeds("kubectl get pod probe | grep Running")
|
|
|
|
machine1.wait_until_succeeds("kubectl get pods -n kube-system | grep 'coredns.*1/1'")
|
2017-09-09 02:00:35 +02:00
|
|
|
|
|
|
|
# check dns on hosts (dnsmasq)
|
2020-05-14 15:14:02 +02:00
|
|
|
machine1.succeed("host redis.default.svc.cluster.local")
|
|
|
|
machine2.succeed("host redis.default.svc.cluster.local")
|
2017-09-09 02:00:35 +02:00
|
|
|
|
|
|
|
# check dns inside the container
|
2020-05-14 15:14:02 +02:00
|
|
|
machine1.succeed("kubectl exec -ti probe -- /bin/host redis.default.svc.cluster.local")
|
2017-09-09 02:00:35 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
singlenode = mkKubernetesSingleNodeTest (base // singleNodeTest);
|
|
|
|
multinode = mkKubernetesMultiNodeTest (base // multiNodeTest);
|
2017-05-03 01:20:32 +02:00
|
|
|
}
|