github.com/k8snetworkplumbingwg/sriov-network-operator@v1.2.1-0.20240408194816-2d2e5a45d453/doc/testing-kind.md (about)

     1  ## E2E test with KinD
     2  Kubernetes IN Docker (KIND) is a tool to deploy Kubernetes inside Docker containers. It is used to test multi nodes scenarios on a single baremetal node.
     3  To run the E2E tests inside a KIND cluster, `./hack/run-e2e-test-kind.sh` can be used. The script performs the following operations:
     4  
     5   * Deploys a 2 node KIND cluster (master and worker)
     6   * Moves the specified SR-IOV capable PCI net device to KIND worker namespace
     7   * Deploys the operator
     8   * Runs E2E tests
     9  
    10  There are two modes of moving the specified SR-IOV capable PCI net device to the KIND worker namespace:
    11  
    12   * `test-suite` (default): In this mode, the E2E test suite handle the PF and its VFs switching to the test namespace.
    13   * `system-service` mode: In this mode a dedicated system service is used to switch the PF and VFs to the test namespace.
    14  
    15  The mode can be selected using the `INTERFACES_SWITCHER` environment variable, or by passing the mode to the `./hack/run-e2e-test-kind.sh` script using the `--device-netns-switcher` flag.
    16  
    17  ### How to test
    18  To execute E2E tests, a SR-IOV Physical Function device is required and will be added to a KinD workers network namespace, depending on the device netns switcher method, the testing steps can defer.  
    19  
    20  Note: Test device will remain in KinD worker node until cluster is terminated.
    21  
    22  #### Device netns switcher mode `test-suite`
    23  ```
    24  $ git clone https://github.com/k8snetworkplumbingwg/sriov-network-operator.git
    25  $ cd sriov-network-operator/
    26  $ source hack/get-e2e-kind-tools.sh
    27  $ export TEST_PCI_DEVICE=0000:02:00.0
    28  $ sudo ./hack/run-e2e-test-kind.sh --pf-pci-address $TEST_PCI_DEVICE
    29  ```
    30  
    31  #### Device netns switcher mode `system-service`
    32  The `system-service` mode uses a linux service to handle the interface switching. To prepare the service, the following needs to be done as root:
    33  ```
    34  cp ./hack/vf-netns-switcher.sh /usr/bin/
    35  cp ./hack/vf-switcher.service /etc/systemd/system/
    36  systemctl daemon-reload
    37  ```
    38  For the service to work properly the `jq` tool is needed.
    39  
    40  To run the E2E tests do:
    41  ```
    42  $ git clone https://github.com/k8snetworkplumbingwg/sriov-network-operator.git
    43  $ cd sriov-network-operator/
    44  $ source hack/get-e2e-kind-tools.sh
    45  $ KUBECONFIG=/etc/kubernetes/admin.conf
    46  $ INTERFACES_SWITCHER=system-service
    47  $ ./hack/run-e2e-test-kind.sh --pf-pci-address <interface pci>
    48  ```
    49  
    50  ### How to repeat test using existing KinD cluster
    51  Export test PCI device used to set up KinD cluster and export KinD worker network namespace path:
    52  ```
    53  $ export KUBECONFIG="${HOME}/.kube/config"
    54  $ export TEST_PCI_DEVICE=0000:02:00.0
    55  $ export TEST_NETNS_PATH=$(docker inspect "$(docker ps --filter 'name=kind-worker' -q)" --format "{{ .NetworkSettings.SandboxKey }}")
    56  $ sudo make test-e2e-k8s
    57  ```
    58  
    59  ### How to teardown
    60  
    61  ```
    62  $ ./hack/teardown-e2e-kind-cluster.sh
    63  ```
    64  
    65  #### Cleaning up the `system-service` service files
    66  ```
    67  $ sudo rm -f /etc/systemd/system/vf-switcher.service
    68  $ sudo rm -f /usr/bin/vf-netns-switcher.sh
    69  $ sudo systemctl daemon-reload
    70  ```
    71  
    72  ### Known limitations / issues
    73  * Webhooks are disabled by default when testing