Unverified Commit e963fce1 authored by azey's avatar azey
Browse files

nixos/tests/rke2: merge into nixos/tests/k3s

Follow-up on ac4abf7f.
parent 2f5bd8e6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1346,7 +1346,7 @@ in
  restic-rest-server = runTest ./restic-rest-server.nix;
  retroarch = runTest ./retroarch.nix;
  ringboard = runTest ./ringboard.nix;
  rke2 = handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./rke2 { };
  rke2 = handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./rancher { rancherDistro = "rke2"; };
  rkvm = handleTest ./rkvm { };
  rmfakecloud = runTest ./rmfakecloud.nix;
  robustirc-bridge = runTest ./robustirc-bridge.nix;
+9 −5
Original line number Diff line number Diff line
# A test that imports k3s airgapped images and verifies that all expected images are present
import ../make-test-python.nix (
  {
    pkgs,
    lib,
    rancherDistro,
    rancherPackage,
    serviceName,
    disabledComponents,
    coreImages,
    vmResources,
    ...
  }:
  {
    name = "${rancherPackage.name}-airgap-images";
    meta.maintainers = lib.teams.k3s.members;

    nodes.machine = _: {
      # k3s uses enough resources the default vm fails.
      virtualisation.memorySize = 1536;
      virtualisation.diskSize = 4096;
      virtualisation = vmResources;

      services.${rancherDistro} = {
        enable = true;
@@ -23,8 +23,10 @@ import ../make-test-python.nix (
        package = rancherPackage;
        disable = disabledComponents;
        images =
          {
          coreImages
          ++ {
            k3s = [ rancherPackage.airgap-images ];
            rke2 = [ ]; # RKE2 already includes its airgap-images in coreImages
          }
          .${rancherDistro};
      };
@@ -34,5 +36,7 @@ import ../make-test-python.nix (
      machine.wait_for_unit("${serviceName}")
      machine.wait_until_succeeds("journalctl -r --no-pager -u ${serviceName} | grep \"Imported images from /var/lib/rancher/${rancherDistro}/agent/images/\"")
    '';

    meta.maintainers = lib.teams.k3s.members ++ pkgs.rke2.meta.maintainers;
  }
)
+37 −23
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ import ../make-test-python.nix (
    rancherPackage,
    serviceName,
    disabledComponents,
    coreImages,
    vmResources,
    ...
  }:
  let
@@ -97,16 +99,18 @@ import ../make-test-python.nix (
  in
  {
    name = "${rancherPackage.name}-auto-deploy-helm";
    meta.maintainers = lib.teams.k3s.members;

    nodes.machine =
      { pkgs, ... }:
      {
        # k3s uses enough resources the default vm fails.
        virtualisation = {
          memorySize = 1536;
          diskSize = 4096;
        };
        environment.systemPackages = [ pkgs.yq-go ];
        environment.systemPackages = with pkgs; [
          kubectl
          yq-go
        ];
        environment.sessionVariables.KUBECONFIG = "/etc/rancher/${rancherDistro}/${rancherDistro}.yaml";

        virtualisation = vmResources;

        services.${rancherDistro} = {
          enable = true;
          package = rancherPackage;
@@ -116,14 +120,11 @@ import ../make-test-python.nix (
              rke2 = lib.remove "rke2-ingress-nginx" disabledComponents;
            }
            .${rancherDistro};
          images = [
            {
          images =
            coreImages
            # Provides the k3s Helm controller
              k3s = rancherPackage.airgap-images;
              rke2 = rancherPackage.images-core-linux-amd64-tar-zst;
            }
            .${rancherDistro}

            ++ lib.optional (rancherDistro == "k3s") rancherPackage.airgap-images
            ++ [
              testImage
            ];
          autoDeployCharts = {
@@ -180,17 +181,25 @@ import ../make-test-python.nix (
      };

    testScript = # python
      let
        manifestFormat =
          {
            k3s = "yaml";
            rke2 = "json";
          }
          .${rancherDistro};
      in
      ''
        import json

        machine.wait_for_unit("${serviceName}")
        # check existence/absence of chart manifest files
        machine.succeed("test -e /var/lib/rancher/${rancherDistro}/server/manifests/hello.yaml")
        machine.succeed("test ! -e /var/lib/rancher/${rancherDistro}/server/manifests/disabled.yaml")
        machine.succeed("test -e /var/lib/rancher/${rancherDistro}/server/manifests/values-file.yaml")
        machine.succeed("test -e /var/lib/rancher/${rancherDistro}/server/manifests/advanced.yaml")
        # check that the timeout is set correctly, select only the first doc in advanced.yaml
        advancedManifest = json.loads(machine.succeed("yq -o json '.items[0]' /var/lib/rancher/${rancherDistro}/server/manifests/advanced.yaml"))
        machine.succeed("test -e /var/lib/rancher/${rancherDistro}/server/manifests/hello.${manifestFormat}")
        machine.succeed("test ! -e /var/lib/rancher/${rancherDistro}/server/manifests/disabled.${manifestFormat}")
        machine.succeed("test -e /var/lib/rancher/${rancherDistro}/server/manifests/values-file.${manifestFormat}")
        machine.succeed("test -e /var/lib/rancher/${rancherDistro}/server/manifests/advanced.${manifestFormat}")
        # check that the timeout is set correctly, select only the first item in advanced.yaml
        advancedManifest = json.loads(machine.succeed("yq -o json '.items[0]' /var/lib/rancher/${rancherDistro}/server/manifests/advanced.${manifestFormat}"))
        t.assertEqual(advancedManifest["spec"]["timeout"], "69s", "unexpected value for spec.timeout")
        # wait for test jobs to complete
        machine.wait_until_succeeds("kubectl wait --for=condition=complete job/hello", timeout=180)
@@ -210,9 +219,14 @@ import ../make-test-python.nix (
            k3s = ''
              machine.wait_until_succeeds("kubectl -n kube-system rollout status deployment traefik", timeout=180)
            '';
            rke2 = ''
              machine.wait_until_succeeds("kubectl -n kube-system rollout status daemonset rke2-ingress-nginx-controller", timeout=180)
            '';
          }
          .${rancherDistro}
        }
      '';

    meta.maintainers = lib.teams.k3s.members ++ pkgs.rke2.meta.maintainers;
  }
)
+24 −12
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ import ../make-test-python.nix (
    rancherPackage,
    serviceName,
    disabledComponents,
    coreImages,
    vmResources,
    ...
  }:
  let
@@ -35,6 +37,13 @@ import ../make-test-python.nix (
      copyToRoot = pkgs.hello;
      config.Entrypoint = [ "${pkgs.hello}/bin/hello" ];
    };

    manifestFormat =
      {
        k3s = "yaml";
        rke2 = "json";
      }
      .${rancherDistro};
  in
  {
    name = "${rancherPackage.name}-auto-deploy";
@@ -42,11 +51,13 @@ import ../make-test-python.nix (
    nodes.machine =
      { pkgs, ... }:
      {
        environment.systemPackages = [ rancherPackage ];
        environment.systemPackages = with pkgs; [
          kubectl
          cri-tools
        ];
        environment.sessionVariables.KUBECONFIG = "/etc/rancher/${rancherDistro}/${rancherDistro}.yaml";

        # k3s uses enough resources the default vm fails.
        virtualisation.memorySize = 1536;
        virtualisation.diskSize = 4096;
        virtualisation = vmResources;

        services.${rancherDistro} = {
          enable = true;
@@ -56,7 +67,7 @@ import ../make-test-python.nix (
          extraFlags = [
            "--pause-image test.local/pause:local"
          ];
          images = [
          images = coreImages ++ [
            pauseImage
            helloImage
          ];
@@ -71,7 +82,7 @@ import ../make-test-python.nix (
            };

            present = {
              target = "foo-namespace.yaml";
              target = "foo-namespace.${manifestFormat}";
              content = {
                apiVersion = "v1";
                kind = "Namespace";
@@ -105,13 +116,14 @@ import ../make-test-python.nix (

        machine.wait_for_unit("${serviceName}")
        # check existence of the manifest files
        machine.fail("ls /var/lib/rancher/${rancherDistro}/server/manifests/absent.yaml")
        machine.succeed("ls /var/lib/rancher/${rancherDistro}/server/manifests/foo-namespace.yaml")
        machine.succeed("ls /var/lib/rancher/${rancherDistro}/server/manifests/hello.yaml")
        machine.fail("ls /var/lib/rancher/${rancherDistro}/server/manifests/absent.${manifestFormat}")
        machine.succeed("ls /var/lib/rancher/${rancherDistro}/server/manifests/foo-namespace.${manifestFormat}")
        machine.succeed("ls /var/lib/rancher/${rancherDistro}/server/manifests/hello.${manifestFormat}")

        # check if container images got imported
        machine.wait_until_succeeds("crictl img | grep 'test\.local/pause'")
        machine.wait_until_succeeds("crictl img | grep 'test\.local/hello'")
        # for some reason, RKE2 also uses /run/k3s
        machine.wait_until_succeeds("crictl -r /run/k3s/containerd/containerd.sock img | grep 'test\.local/pause'")
        machine.wait_until_succeeds("crictl -r /run/k3s/containerd/containerd.sock img | grep 'test\.local/hello'")

        # check if resources of manifests got created
        machine.wait_until_succeeds("kubectl get ns foo")
@@ -119,6 +131,6 @@ import ../make-test-python.nix (
        machine.fail("kubectl get ns absent")
      '';

    meta.maintainers = lib.teams.k3s.members;
    meta.maintainers = lib.teams.k3s.members ++ pkgs.rke2.meta.maintainers;
  }
)
+11 −5
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ import ../make-test-python.nix (
    rancherPackage,
    serviceName,
    disabledComponents,
    coreImages,
    vmResources,
    ...
  }:
  let
@@ -17,15 +19,19 @@ import ../make-test-python.nix (
    nodes.machine =
      { ... }:
      {
        environment.systemPackages = [ pkgs.jq ];
        # k3s uses enough resources the default vm fails.
        virtualisation.memorySize = 1536;
        virtualisation.diskSize = 4096;
        environment.systemPackages = with pkgs; [
          kubectl
          jq
        ];
        environment.sessionVariables.KUBECONFIG = "/etc/rancher/${rancherDistro}/${rancherDistro}.yaml";

        virtualisation = vmResources;

        services.${rancherDistro} = {
          enable = true;
          package = rancherPackage;
          disable = disabledComponents;
          images = coreImages;
          inherit nodeName;
          containerdConfigTemplate = ''
            # Base ${rancherDistro} config
@@ -50,6 +56,6 @@ import ../make-test-python.nix (
        t.assertIn("MAGIC COMMENT", out, "the containerd config does not contain the magic comment")
      '';

    meta.maintainers = lib.teams.k3s.members;
    meta.maintainers = lib.teams.k3s.members ++ pkgs.rke2.meta.maintainers;
  }
)
Loading