1 { system ? builtins.currentSystem, pkgs ? import ../../.. { inherit system; } }:
2 with import ./base.nix { inherit system; };
5 roServiceAccount = pkgs.writeText "ro-service-account.json" (builtins.toJSON {
6 kind = "ServiceAccount";
10 namespace = "default";
14 roRoleBinding = pkgs.writeText "ro-role-binding.json" (builtins.toJSON {
15 apiVersion = "rbac.authorization.k8s.io/v1";
19 namespace = "default";
22 apiGroup = "rbac.authorization.k8s.io";
27 kind = "ServiceAccount";
29 namespace = "default";
33 roRole = pkgs.writeText "ro-role.json" (builtins.toJSON {
34 apiVersion = "rbac.authorization.k8s.io/v1";
38 namespace = "default";
43 verbs = ["get" "list" "watch"];
47 kubectlPod = pkgs.writeText "kubectl-pod.json" (builtins.toJSON {
50 metadata.name = "kubectl";
51 metadata.namespace = "default";
52 metadata.labels.name = "kubectl";
53 spec.serviceAccountName = "read-only";
56 image = "kubectl:latest";
57 command = ["/bin/tail" "-f"];
58 imagePullPolicy = "Never";
63 kubectlPod2 = pkgs.writeTextDir "kubectl-pod-2.json" (builtins.toJSON {
66 metadata.name = "kubectl-2";
67 metadata.namespace = "default";
68 metadata.labels.name = "kubectl-2";
69 spec.serviceAccountName = "read-only";
72 image = "kubectl:latest";
73 command = ["/bin/tail" "-f"];
74 imagePullPolicy = "Never";
79 copyKubectl = pkgs.runCommand "copy-kubectl" { } ''
81 cp ${pkgs.kubernetes}/bin/kubectl $out/bin/kubectl
84 kubectlImage = pkgs.dockerTools.buildImage {
87 copyToRoot = pkgs.buildEnv {
89 pathsToLink = [ "/bin" ];
90 paths = [ copyKubectl pkgs.busybox kubectlPod2 ];
92 config.Entrypoint = ["/bin/sh"];
99 singlenode = base // {
101 machine1.wait_until_succeeds("kubectl get node machine1.my.zyx | grep -w Ready")
103 machine1.wait_until_succeeds(
104 "${pkgs.gzip}/bin/zcat ${kubectlImage} | ${pkgs.containerd}/bin/ctr -n k8s.io image import -"
107 machine1.wait_until_succeeds(
108 "kubectl apply -f ${roServiceAccount}"
110 machine1.wait_until_succeeds(
111 "kubectl apply -f ${roRole}"
113 machine1.wait_until_succeeds(
114 "kubectl apply -f ${roRoleBinding}"
116 machine1.wait_until_succeeds(
117 "kubectl create -f ${kubectlPod}"
120 machine1.wait_until_succeeds("kubectl get pod kubectl | grep Running")
122 machine1.wait_until_succeeds("kubectl exec kubectl -- kubectl get pods")
123 machine1.fail("kubectl exec kubectl -- kubectl create -f /kubectl-pod-2.json")
124 machine1.fail("kubectl exec kubectl -- kubectl delete pods -l name=kubectl")
128 multinode = base // {
130 # Node token exchange
131 machine1.wait_until_succeeds(
132 "cp -f /var/lib/cfssl/apitoken.secret /tmp/shared/apitoken.secret"
134 machine2.wait_until_succeeds(
135 "cat /tmp/shared/apitoken.secret | nixos-kubernetes-node-join"
138 machine1.wait_until_succeeds("kubectl get node machine2.my.zyx | grep -w Ready")
140 machine2.wait_until_succeeds(
141 "${pkgs.gzip}/bin/zcat ${kubectlImage} | ${pkgs.containerd}/bin/ctr -n k8s.io image import -"
144 machine1.wait_until_succeeds(
145 "kubectl apply -f ${roServiceAccount}"
147 machine1.wait_until_succeeds(
148 "kubectl apply -f ${roRole}"
150 machine1.wait_until_succeeds(
151 "kubectl apply -f ${roRoleBinding}"
153 machine1.wait_until_succeeds(
154 "kubectl create -f ${kubectlPod}"
157 machine1.wait_until_succeeds("kubectl get pod kubectl | grep Running")
159 machine1.wait_until_succeeds("kubectl exec kubectl -- kubectl get pods")
160 machine1.fail("kubectl exec kubectl -- kubectl create -f /kubectl-pod-2.json")
161 machine1.fail("kubectl exec kubectl -- kubectl delete pods -l name=kubectl")
166 singlenode = mkKubernetesSingleNodeTest singlenode;
167 multinode = mkKubernetesMultiNodeTest multinode;