e2e

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2020 License: Apache-2.0 Imports: 36 Imported by: 0

README

Running the Antrea end-to-end tests

Creating the test Kubernetes cluster

The tests must be run on an actual Kubernetes cluster. At the moment, we require the cluster to be created using Vagrant and the provided Vagrantfile, which you can do by following the instructions below.

Creating the test Kubernetes cluster with Vagrant

We use Vagrant to provision two Virtual Machines (one Kubernetes master node and one worker node). The required software is installed on each machine with Ansible. By default the Vagrantfile uses VirtualBox but you should be able to edit the file to use your favorite Vagrant provider.

Dependencies

We require the following to be installed on your host machine:

  • vagrant (>= 2.0.0)
  • ansible (>= 2.4.0)
  • virtualbox (See supported versions here).
Ubuntu 18.04 (or later)

You can install all dependencies with sudo apt install vagrant ansible virtualbox.

Mac OS

You can install all the dependencies with brew:

  • brew cask install virtualbox
  • brew cask install vagrant
  • brew install ansible

If an action is required on your part, brew will let you know in its log messages.

Managing the cluster

Use the following Bash scripts to manage the Kubernetes nodes with Vagrant:

  • ./infra/vagrant/provision.sh: create the required VMs and provision them
  • ./infra/vagrant/push_antrea.sh: load the antrea/antrea-ubuntu Docker image to each node, along with the Antrea deployment YAML
  • ./infra/vagrant/suspend.sh: suspend all node VMs
  • ./infra/vagrant/resume.sh: resume all node VMs
  • ./infra/vagrant/destroy.sh: destoy all node VMs, you will need to run provision.sh again to create a new cluster

Note that ./infra/vagrant/provision.sh can take a while to complete but it only needs to be run once.

Debugging

You can SSH into any of the node VMs using vagrant ssh [node name] (must be run from the infra/vagrant directory. The master node is named k8s-node-master and the worker nodes are named k8s-node-worker-<N> (for a single worker node, the name is k8s-node-worker-1. kubectl is installed on all the nodes.

The kubeconfig file for the cluster can also be found locally on your machine at ./infra/vagrant/playbook/kube/config. If you install kubectl locally and set the KUBECONFIG environment variable to the absolute path of this kubeconfig file, you can run commands against your test cluster created with Vagrant. For example:

cd <directory containing this README file>
export KUBECONFIG=`pwd`/infra/vagrant/playbook/kube/config
kubectl cluster-info

Running the tests

Make sure that your cluster was provisioned and that the Antrea build artifacts were pushed to all the nodes. You can then run the tests from the top-level directory with go test -v -timeout=30m github.com/vmware-tanzu/antrea/test/e2e (the -v enables verbose output).

If you are running the test for the first time and are using the scripts we provide under infra/vagrant to provision your Kubernetes cluster, you will therefore need the following steps:

  1. ./infra/vagrant/provision.sh
  2. make
  3. ./infra/vagrant/push_antrea.sh
  4. go test -v -timeout=30m github.com/vmware-tanzu/antrea/test/e2e

If you need to test an updated version of Antrea, just run ./infra/vagrant/push_antrea.sh and then run the tests again.

By default, if a test case fails, we write some useful debug information to a temporary directory on disk. This information includes the detailed description (obtained with kubectl describe) and the logs (obtained with kubectl logs) of each Antrea Pod at the time the test case exited. When running the tests in verbose mode (i.e. with -v), the test logs will tell you the location of that temporary directory. You may also choose your own directory using --logs-export-dir. For example:

mkdir antrea-test-logs
go test -count=1 -v -run=TestDeletePod github.com/vmware-tanzu/antrea/test/e2e --logs-export-dir `pwd`/antrea-test-logs

By default the description and logs for Antrea Pods are only written to disk if a test fails. You can choose to dump this information unconditionally with --logs-export-on-success.

Testing the Prometheus Integration

The Prometheus integration tests can be run as part of the e2e tests when enabled explicitly.

  • To load Antrea into the cluster with Prometheus enabled, use: ./infra/vagrant/push_antrea.sh --prometheus
  • To run the Prometheus tests within the e2e suite, use: go test -v github.com/vmware-tanzu/antrea/test/e2e --prometheus

Running the e2e tests on a Kind cluster

The simplest way is to run the following command:

./ci/kind/test-e2e-kind.sh [options]

It will set up a two worker Node Kind cluster to run the e2e tests, and destroy the cluster after the tests stop (succeed or fail). kubectl needs to be present in your PATH to set up the test cluster. For more information on the usage of this script and the options, run:

./ci/kind/test-e2e-kind.sh --help

You can also run the e2e tests with an existing Kind cluster. Refer to this document for instructions on how to create a Kind cluster and use Antrea as the CNI. You need at least one control-plane (master) Node and one worker Node. Before running the Go e2e tests, you will also need to copy the Antrea manifest to the master Docker container:

./hack/generate-manifest.sh --kind | docker exec -i kind-control-plane dd of=/root/antrea.yml
go test -v github.com/vmware-tanzu/antrea/test/e2e -provider=kind

Running the performance test

To run all benchmarks, without the standard e2e tests:

go test -v -timeout=30m -run=XXX -bench=. \
    github.com/vmware-tanzu/antrea/test/e2e \
    --performance.http.concurrency=16

The above command uses -run=XXX to deselect all Test* tests and uses -bench=. to select all Benchmark* tests. Since performance tests take a while to complete, you need to extend the timeout duration -timeout from the default 10m to a longer one like 30m.

If you would like to run the performance tests in a different scale, you could run:

go test -v -timeout=30m -run=XXX -bench=BenchmarkCustomize \
    github.com/vmware-tanzu/antrea/test/e2e \
    --performance.http.requests=5000 \
    --performance.http.policy_rules=1000 \
    --performance.http.concurrency=16

All flags of performance tests includes:

  • performance.http.concurrency (int): Number of allowed concurrent http requests (default 1)
  • performance.http.requests (int): Total Number of http requests
  • performance.http.policy_rules (int): Number of CIDRs in the network policy
  • performance.realize.timeout (duration): Timeout of the realization of network policies (default 5m0s)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

IsDirEmpty checks whether a directory is empty or not.

func RunCommandOnNode added in v0.1.1

func RunCommandOnNode(nodeName string, cmd string) (code int, stdout string, stderr string, err error)

RunCommandOnNode is a convenience wrapper around the Provider interface RunCommandOnNode method.

Types

type ClusterInfo

type ClusterInfo struct {
	// contains filtered or unexported fields
}

type ClusterNode

type ClusterNode struct {
	// contains filtered or unexported fields
}

type Connectivity added in v0.8.0

type Connectivity struct {
	From        Pod
	To          Pod
	IsConnected bool
}

type KubernetesUtils added in v0.8.0

type KubernetesUtils struct {
	*TestData
	// contains filtered or unexported fields
}

func NewKubernetesUtils added in v0.8.0

func NewKubernetesUtils(data *TestData) (*KubernetesUtils, error)

func (*KubernetesUtils) Bootstrap added in v0.8.0

func (k *KubernetesUtils) Bootstrap(namespaces, pods []string) (*map[string]string, error)

func (*KubernetesUtils) CleanANPs added in v0.10.0

func (k *KubernetesUtils) CleanANPs(namespaces []string) error

CleanANPs is a convenience function for deleting Antrea NetworkPolicies before startup of any new test.

func (*KubernetesUtils) CleanCNPs added in v0.8.0

func (k *KubernetesUtils) CleanCNPs() error

CleanCNPs is a convenience function for deleting AntreaClusterNetworkPolicies before startup of any new test.

func (*KubernetesUtils) CleanNetworkPolicies added in v0.8.0

func (k *KubernetesUtils) CleanNetworkPolicies(namespaces []string) error

CleanNetworkPolicies is a convenience function for deleting network policies before startup of any new test.

func (*KubernetesUtils) Cleanup added in v0.8.0

func (k *KubernetesUtils) Cleanup(namespaces []string) error

func (*KubernetesUtils) CreateNewTier added in v0.10.0

func (k *KubernetesUtils) CreateNewTier(name string, tierPriority int32) (*secv1alpha1.Tier, error)

CreateTier is a convenience function for creating an Antrea Policy Tier by name and priority.

func (*KubernetesUtils) CreateOrUpdateANP added in v0.10.0

CreateOrUpdateCNP is a convenience function for updating/creating Antrea NetworkPolicies.

func (*KubernetesUtils) CreateOrUpdateCNP added in v0.8.0

CreateOrUpdateCNP is a convenience function for updating/creating AntreaClusterNetworkPolicies.

func (*KubernetesUtils) CreateOrUpdateDeployment added in v0.8.0

func (k *KubernetesUtils) CreateOrUpdateDeployment(ns, deploymentName string, replicas int32, labels map[string]string) (*appsv1.Deployment, error)

CreateOrUpdateDeployment is a convenience function for idempotent setup of deployments

func (*KubernetesUtils) CreateOrUpdateNamespace added in v0.8.0

func (k *KubernetesUtils) CreateOrUpdateNamespace(n string, labels map[string]string) (*v1.Namespace, error)

CreateOrUpdateNamespace is a convenience function for idempotent setup of Namespaces

func (*KubernetesUtils) CreateOrUpdateNetworkPolicy added in v0.8.0

func (k *KubernetesUtils) CreateOrUpdateNetworkPolicy(ns string, netpol *v1net.NetworkPolicy) (*v1net.NetworkPolicy, error)

CreateOrUpdateNetworkPolicy is a convenience function for updating/creating netpols. Updating is important since some tests update a network policy to confirm that mutation works with a CNI.

func (*KubernetesUtils) DeleteTier added in v0.10.0

func (k *KubernetesUtils) DeleteTier(name string) error

DeleteTier is a convenience function for deleting an Antrea Policy Tier with specific name.

func (*KubernetesUtils) GetPod added in v0.8.0

func (k *KubernetesUtils) GetPod(ns string, name string) (*v1.Pod, error)

GetPod returns a Pod with the matching Namespace and name

func (*KubernetesUtils) GetPods added in v0.8.0

func (k *KubernetesUtils) GetPods(ns string, key string, val string) ([]v1.Pod, error)

GetPods returns an array of all Pods in the given Namespace having a k/v label pair.

func (*KubernetesUtils) Probe added in v0.8.0

func (k *KubernetesUtils) Probe(ns1, pod1, ns2, pod2 string, port int) (bool, error)

Probe execs into a Pod and checks its connectivity to another Pod. Of course it assumes that the target Pod is serving on the input port, and also that ncat is installed.

func (*KubernetesUtils) Validate added in v0.8.0

func (k *KubernetesUtils) Validate(allPods []Pod, reachability *Reachability, port int)

type Pod added in v0.8.0

type Pod string

func NewPod added in v0.8.0

func NewPod(namespace string, podName string) Pod

func (Pod) Namespace added in v0.8.0

func (pod Pod) Namespace() string

func (Pod) PodName added in v0.8.0

func (pod Pod) PodName() string

func (Pod) String added in v0.8.0

func (pod Pod) String() string

type PodCondition

type PodCondition func(*corev1.Pod) (bool, error)

type Reachability added in v0.8.0

type Reachability struct {
	Expected *TruthTable
	Observed *TruthTable
	Pods     []Pod
}

func NewReachability added in v0.8.0

func NewReachability(pods []Pod, defaultExpectation bool) *Reachability

func (*Reachability) Expect added in v0.8.0

func (r *Reachability) Expect(pod1 Pod, pod2 Pod, isConnected bool)

func (*Reachability) ExpectAllEgress added in v0.8.0

func (r *Reachability) ExpectAllEgress(pod Pod, connected bool)

ExpectAllEgress defines that any traffic going out of the pod will be allowed/denied (true/false)

func (*Reachability) ExpectAllIngress added in v0.8.0

func (r *Reachability) ExpectAllIngress(pod Pod, connected bool)

ExpectAllIngress defines that any traffic going into the pod will be allowed/denied (true/false)

func (*Reachability) ExpectConn added in v0.8.0

func (r *Reachability) ExpectConn(spec *Connectivity)

ExpectConn is an experimental way to describe connectivity with named fields

func (*Reachability) ExpectSelf added in v0.8.0

func (r *Reachability) ExpectSelf(allPods []Pod, isConnected bool)

func (*Reachability) Observe added in v0.8.0

func (r *Reachability) Observe(pod1 Pod, pod2 Pod, isConnected bool)

func (*Reachability) PrintSummary added in v0.8.0

func (r *Reachability) PrintSummary(printExpected bool, printObserved bool, printComparison bool)

func (*Reachability) Summary added in v0.8.0

func (r *Reachability) Summary() (trueObs int, falseObs int, comparison *TruthTable)

type TestData

type TestData struct {
	// contains filtered or unexported fields
}

TestData stores the state required for each test case.

func (*TestData) GetAntreaConfigMap added in v0.8.0

func (data *TestData) GetAntreaConfigMap(antreaNamespace string) (*corev1.ConfigMap, error)

func (*TestData) GetEncapMode added in v0.4.0

func (data *TestData) GetEncapMode() (config.TrafficEncapModeType, error)

func (*TestData) GetGatewayInterfaceName added in v0.8.0

func (data *TestData) GetGatewayInterfaceName(antreaNamespace string) (string, error)

type TestOptions

type TestOptions struct {
	// contains filtered or unexported fields
}

type TruthTable added in v0.8.0

type TruthTable struct {
	Items []string

	Values map[string]map[string]bool
	// contains filtered or unexported fields
}

func NewTruthTable added in v0.8.0

func NewTruthTable(items []string, defaultValue *bool) *TruthTable

func (*TruthTable) Compare added in v0.8.0

func (tt *TruthTable) Compare(other *TruthTable) *TruthTable

func (*TruthTable) Get added in v0.8.0

func (tt *TruthTable) Get(from string, to string) bool

func (*TruthTable) IsComplete added in v0.8.0

func (tt *TruthTable) IsComplete() bool

IsComplete returns true if there's a value set for every single pair of items, otherwise it returns false.

func (*TruthTable) PrettyPrint added in v0.8.0

func (tt *TruthTable) PrettyPrint(indent string) string

func (*TruthTable) Set added in v0.8.0

func (tt *TruthTable) Set(from string, to string, value bool)

func (*TruthTable) SetAllFrom added in v0.8.0

func (tt *TruthTable) SetAllFrom(from string, value bool)

func (*TruthTable) SetAllTo added in v0.8.0

func (tt *TruthTable) SetAllTo(to string, value bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL