diff --git a/examples/nginx-deployment/test.nix b/examples/nginx-deployment/test.nix index c4b80a9..63967bc 100644 --- a/examples/nginx-deployment/test.nix +++ b/examples/nginx-deployment/test.nix @@ -6,7 +6,6 @@ with lib; imports = [ kubenix.modules.test ./module.nix ]; test = { - distro = "k3s"; name = "nginx-deployment"; description = "Test testing nginx deployment"; testScript = '' diff --git a/modules/k3s-airgap-images.nix b/modules/k3s-airgap-images.nix deleted file mode 100644 index bd33841..0000000 --- a/modules/k3s-airgap-images.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ stdenv, fetchurl, k3s }: - -stdenv.mkDerivation rec { - pname = "k3s-airgap-images"; - version = k3s.version; - - src = - let - throwError = throw "Unsupported system ${stdenv.hostPlatform.system}"; - in - { - x86_64-linux = fetchurl { - url = "https://github.com/rancher/k3s/releases/download/v${version}/k3s-airgap-images-amd64.tar"; - sha256 = "sha256-6kQmlpNV+4cU1Kn5lyZhutXYK5qYdey0jubzYRRF3vA="; - }; - aarch64-linux = fetchurl { - url = "https://github.com/rancher/k3s/releases/download/v${version}/k3s-airgap-images-arm64.tar"; - sha256 = "sha256-OlqqdAmBN+azT0kfjZ/Bd0CFbbW5hTg9/8T9U05N0zE="; - }; - armv7l-linux = fetchurl { - url = "https://github.com/rancher/k3s/releases/download/v${version}/k3s-airgap-images-arm.tar"; - sha256 = "sha256-j/ARBtHDnfRk/7BpOvavoHe7L5dmsCZe5+wuZ5t4V/k="; - }; - }.${stdenv.hostPlatform.system} or throwError; - - preferLocalBuild = true; - dontUnpack = true; - installPhase = "cp $src $out"; - - meta = with stdenv.lib; { - description = "Lightweight Kubernetes. 5 less than k8s. Airgap images."; - homepage = https://k3s.io/; - license = licenses.asl20; - maintainers = [ maintainers.offline ]; - platforms = [ "x86_64-linux" "aarch64-linux" "armv7l-linux" ]; - }; -} diff --git a/modules/testing/default.nix b/modules/testing/default.nix index a09a9c3..ec324b8 100644 --- a/modules/testing/default.nix +++ b/modules/testing/default.nix @@ -23,6 +23,7 @@ in ./docker.nix ./driver/kubetest.nix ./runtime/local.nix + ./runtime/nixos-k8s.nix ]; options.testing = { diff --git a/modules/testing/docker.nix b/modules/testing/docker.nix index 2f060f8..ee46c19 100644 --- a/modules/testing/docker.nix +++ b/modules/testing/docker.nix @@ -5,7 +5,7 @@ with import ../../lib/docker.nix { inherit lib pkgs; }; let testing = config.testing; - allImages = flatten (map (t: t.evaled.config.docker.export or [ ]) testing.tests); + allImages = unique ( flatten (map (t: t.evaled.config.docker.export or [ ]) testing.tests)); cfg = config.testing.docker; diff --git a/modules/testing/runtime/nixos-k8s.nix b/modules/testing/runtime/nixos-k8s.nix index 33051de..fde5540 100644 --- a/modules/testing/runtime/nixos-k8s.nix +++ b/modules/testing/runtime/nixos-k8s.nix @@ -4,28 +4,34 @@ , config , pkgs , lib -, system ? "x86_64-linux" , ... }: with lib; let testing = config.testing; - kubeconfig = "/etc/${config.services.kubernetes.pki.etcClusterAdminKubeconfig}"; + # kubeconfig = "/etc/${config.services.kubernetes.pki.etcClusterAdminKubeconfig}"; + kubeconfig = "/etc/kubernetes/cluster-admin.kubeconfig"; + kubecerts = "/var/lib/kubernetes/secrets"; # how we differ from the standard configuration of mkKubernetesBaseTest extraConfiguration = { config, pkgs, lib, nodes, ... }: { - virtualisation.memorySize = mkDefault 2048; + + virtualisation = { + memorySize = 2048; + }; + networking = { nameservers = [ "10.0.0.254" ]; firewall = { trustedInterfaces = [ "docker0" "cni0" ]; }; }; + services.kubernetes = { - seedDockerImages = mkIf (elem "docker" config._m.features) config.docker.export; flannel.enable = false; kubelet = { + seedDockerImages = testing.docker.images; networkPlugin = "cni"; cni.config = [{ name = "mynet"; @@ -44,10 +50,14 @@ let }; }]; }; - systemd.extraConfig = "DefaultLimitNOFILE=1048576"; - systemd.services.copy-certs = { + }; + + systemd = { + extraConfig = "DefaultLimitNOFILE=1048576"; + # Host tools should have a chance to access guest's kube api + services.copy-certs = { description = "Share k8s certificates with host"; - script = "cp -rf /var/lib/kubernetes/secrets /tmp/xchg/"; + script = "cp -rf ${kubecerts} /tmp/xchg/; cp -f ${kubeconfig} /tmp/xchg/;"; after = [ "kubernetes.target" ]; wantedBy = [ "multi-user.target" ]; serviceConfig = { @@ -56,6 +66,7 @@ let }; }; }; + }; script = '' @@ -63,25 +74,23 @@ let ''; test = - with import "${nixosPath}/tests/kubernetes/base.nix" { inherit pkgs system; }; + with import "${nixosPath}/tests/kubernetes/base.nix" { inherit pkgs; inherit (pkgs) system; }; mkKubernetesSingleNodeTest { inherit extraConfiguration; - inherit (config) name; + inherit (config.testing) name; test = script; }; in { - options = { - runtime.nixos-k8s = { - driver = mkOption { - description = "Test driver"; - type = types.package; - internal = true; - }; + options.testing.runtime.nixos-k8s = { + driver = mkOption { + description = "Test driver"; + type = types.package; + internal = true; }; }; - runtime.nixos-k8s.driver = test.driver; + config.testing.runtime.nixos-k8s.driver = test.driver; }