2 system ? builtins.currentSystem,
3 pkgs ? import ../../.. { inherit system; },
5 with import ./base.nix { inherit system; };
8 roServiceAccount = pkgs.writeText "ro-service-account.json" (
10 kind = "ServiceAccount";
14 namespace = "default";
19 roRoleBinding = pkgs.writeText "ro-role-binding.json" (
21 apiVersion = "rbac.authorization.k8s.io/v1";
25 namespace = "default";
28 apiGroup = "rbac.authorization.k8s.io";
34 kind = "ServiceAccount";
36 namespace = "default";
42 roRole = pkgs.writeText "ro-role.json" (
44 apiVersion = "rbac.authorization.k8s.io/v1";
48 namespace = "default";
53 resources = [ "pods" ];
64 kubectlPod = pkgs.writeText "kubectl-pod.json" (
68 metadata.name = "kubectl";
69 metadata.namespace = "default";
70 metadata.labels.name = "kubectl";
71 spec.serviceAccountName = "read-only";
75 image = "kubectl:latest";
80 imagePullPolicy = "Never";
87 kubectlPod2 = pkgs.writeTextDir "kubectl-pod-2.json" (
91 metadata.name = "kubectl-2";
92 metadata.namespace = "default";
93 metadata.labels.name = "kubectl-2";
94 spec.serviceAccountName = "read-only";
98 image = "kubectl:latest";
103 imagePullPolicy = "Never";
110 copyKubectl = pkgs.runCommand "copy-kubectl" { } ''
112 cp ${pkgs.kubernetes}/bin/kubectl $out/bin/kubectl
115 kubectlImage = pkgs.dockerTools.buildImage {
118 copyToRoot = pkgs.buildEnv {
120 pathsToLink = [ "/bin" ];
127 config.Entrypoint = [ "/bin/sh" ];
134 singlenode = base // {
136 machine1.wait_until_succeeds("kubectl get node machine1.my.zyx | grep -w Ready")
138 machine1.wait_until_succeeds(
139 "${pkgs.gzip}/bin/zcat ${kubectlImage} | ${pkgs.containerd}/bin/ctr -n k8s.io image import -"
142 machine1.wait_until_succeeds(
143 "kubectl apply -f ${roServiceAccount}"
145 machine1.wait_until_succeeds(
146 "kubectl apply -f ${roRole}"
148 machine1.wait_until_succeeds(
149 "kubectl apply -f ${roRoleBinding}"
151 machine1.wait_until_succeeds(
152 "kubectl create -f ${kubectlPod}"
155 machine1.wait_until_succeeds("kubectl get pod kubectl | grep Running")
157 machine1.wait_until_succeeds("kubectl exec kubectl -- kubectl get pods")
158 machine1.fail("kubectl exec kubectl -- kubectl create -f /kubectl-pod-2.json")
159 machine1.fail("kubectl exec kubectl -- kubectl delete pods -l name=kubectl")
163 multinode = base // {
165 # Node token exchange
166 machine1.wait_until_succeeds(
167 "cp -f /var/lib/cfssl/apitoken.secret /tmp/shared/apitoken.secret"
169 machine2.wait_until_succeeds(
170 "cat /tmp/shared/apitoken.secret | nixos-kubernetes-node-join"
173 machine1.wait_until_succeeds("kubectl get node machine2.my.zyx | grep -w Ready")
175 machine2.wait_until_succeeds(
176 "${pkgs.gzip}/bin/zcat ${kubectlImage} | ${pkgs.containerd}/bin/ctr -n k8s.io image import -"
179 machine1.wait_until_succeeds(
180 "kubectl apply -f ${roServiceAccount}"
182 machine1.wait_until_succeeds(
183 "kubectl apply -f ${roRole}"
185 machine1.wait_until_succeeds(
186 "kubectl apply -f ${roRoleBinding}"
188 machine1.wait_until_succeeds(
189 "kubectl create -f ${kubectlPod}"
192 machine1.wait_until_succeeds("kubectl get pod kubectl | grep Running")
194 machine1.wait_until_succeeds("kubectl exec kubectl -- kubectl get pods")
195 machine1.fail("kubectl exec kubectl -- kubectl create -f /kubectl-pod-2.json")
196 machine1.fail("kubectl exec kubectl -- kubectl delete pods -l name=kubectl")
202 singlenode = mkKubernetesSingleNodeTest singlenode;
203 multinode = mkKubernetesMultiNodeTest multinode;