Project: KubeAdmiral (Orchestration & Management / Scheduling & Orchestration)
File: e2e-tests.md

This guide provides instructions on how to run and write end-to-end tests for KubeAdmiral. Make sure you have the following installed: : KubeAdmiral uses Ginkgo to run its e2e test suite or : certain e2e tests require cluster provisioning which is performed by either Kind or Kwok The KubeAdmiral e2e test suite is designed to run against an existing KubeAdmiral control plane so that an existing federation of clusters can be tested for both its health and compatibility. You may use our Make command to run the e2e test suite. The Make command reads the path to the host cluster's kubeconfig from the `KUBECONFIG` environment variable. ```console $ make e2e ``` The command above will run the e2e test suite with a set of default flag values. These flags may be modified if required. You may modify the flags using our Make command as such. ```console $ EXTRAGINKGOFLAGS='' EXTRAE2EFLAGS='' make e2e ``` We can configure the way Ginkgo runs our tests by passing Ginkgo flags to the Ginkgo CLI. Refer to the for more details. Some useful flags are: `--focus`: used to filter test specs to run `--nodes`: used to run test specs in parallel In addition to Ginkgo flags, our test suite also exposes its own set of flags to configure its behavior. The available flags are: `--master`: the address of the host Kubernetes cluster `--kubeconfig`: the kubeconfig of the host Kubernetes cluster `--kube-api-qps`: the maximum QPS of each cluster's client (default: 500) `--kube-api-burst`: the maximum burst for throttling requests for each cluster's client (default: 1000) `--cluster-provider`: `kwok` or `kind`, selects the cluster provider to use (default: kwok) `--kind-node-image`: the node image to use if Kind is selected as the cluster provider (default: kindest/node:v1.20.15@sha256:a32bf55309294120616886b5338f95dd98a2f7231519c7dedcec32ba29699394) `--kwok-image-prefix`: the image prefix used by Kwok to pull Kubernetes images (default: registry.k8s.io) `--kwok-kube-version`: the kubernetes version to use when creating Kwok member clusters (default: v1.20.15) `--preserve-clusters`: if true, clusters created during the tests are preserved (default: false) `--preserve-namespaces`: if true, namespaces created during the tests are preserved (default: false) `--default-pod-image`: the default pod image to use when generating container templates The KubeAdmiral e2e test suite is written using Ginkgo test specs. You may refer to the for more information. When defining a new test spec, first initialize the test framework by calling `framework.NewFramework`. ```go var _ = ginkgo.Describe("Example", func() { f := framework.NewFramework("example", framework.FrameworkOptions{}) ... } ``` Subsequently, you may use the returned `Framework` interface to perform useful operations like cluster provisioning, accessing the test namespace or retrieving cluster clients. ```go var _ = ginkgo.Describe("Example", ginkgo.Label(framework.TestLabelNeedCreateCluster), func() { f := framework.NewFramework("example", framework.FrameworkOptions{}) waitForClusterJoin := func(ctx context.Context, cluster *fedcorev1a1.FederatedCluster) { ... } ginkgo.It("create cluster", func(ctx ginkgo.SpecContext) { cluster, _ = f.NewCluster(ctx) waitForClusterJoin(ctx, cluster) }) }) ``` This is the full interface of `Framework`. ```go type Framework interface { HostKubeClient() kubeclient.Interface HostFedClient() fedclient.Interface HostDynamicClient() dynamic.Interface Name() string TestNamespace() *corev1.Namespace NewCluster(ctx context.Context, clusterModifiers ...ClusterModifier) (fedcorev1a1.FederatedCluster, corev1.Secret) ClusterKubeClient(ctx context.Context, cluster *fedcorev1a1.FederatedCluster) kubeclient.Interface ClusterFedClient(ctx context.Context, cluster *fedcorev1a1.FederatedCluster) fedclient.Interface ClusterDynamicClient(ctx context.Context, cluster *fedcorev1a1.FederatedCluster) dynamic.Interface } ``` Additionally, useful helper functions are provided by the following packages: