e2e

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: MIT Imports: 38 Imported by: 0

README

E2E OSM Testing

Table of Contents

Overview

End-to-end tests verify the behavior of the entire system. For OSM, e2e tests will install a control plane, install test workloads and SMI policies, and check that the workload is behaving as expected.

Files and structure

OSM's e2e tests are located in tests/e2e. The tests are written using Ginkgo and Gomega so they may also be directly invoked using go test. Be sure to build the osm-controller and init container images and osm CLI before directly invoking the tests (see instructions below).

OSM's framework has an init mechanism which will automatically initialize and parse flags and variables from both env and go test flags if any are passed to the test. The hooks for initialization and cleanup are set at Ginkgo's BeforeEach at the top level of test execution (between Ginkgo Describes); we henceforth recommend keeping every test in its own Describe section, as well as on a separate file for clarity. You can refer to suite_test for more details about the init process.

Running the tests

Running the tests will require a running Kubernetes cluster. If you do not have a Kubernetes cluster to run the tests onto, you can choose to run them using Kind, which will make the test framework initialize a cluster on a local accessible docker client.

The tests can be run using the test-e2e Makefile target at repository root level (which defaults to use Kind), or alternatively go test targetting the test folder, which gives more flexibility but depends on related env flags given or parsed by the test.

Please refer to the Kind cluster or Other K8s deployment and follow the instructions to setup potential env flags required by either option.

In addition to the flags provided by go test and Ginkgo, there are several custom command line flags that may be used for e2e tests to configure global parameters like container image locations and cleanup behavior. You can see the list of flags under the flag section below.

Kind cluster

The following make target will create local containers for the OSM components, tagging them with CTR_TAG, and will launch the tests using Kind cluster. A Kind cluster is created at test start, and requires a docker interface to be available on the host running the test. When using Kind, we load the images onto the Kind nodes directly (as opposed to providing a registry to pull the images from).

CTR_TAG=not-latest make test-e2e

Note: If you use latest tag, K8s will try to pull the image by default. If the images are not pushed to a registry accessible by the kind cluster, image pull errors will occur. Or, if an image with the same name is available, like openservicemesh/init:latest, then that publicly available image will be pulled and started instead, which may not be as up-to-date as the local image already loaded onto the cluster.

Other K8s deployment

Have your Kubeconfig file point to your testing cluster of choice. The following code uses latest tag by default. Non-Kind deployments do not push the images on the nodes, so make sure to set the registry accordingly.

export CTR_REGISTRY=<myacr>.dockerhub.io # if needed, set CTR_REGISTRY_USER and CTR_REGISTRY_PASSWORD 
make build-osm
make docker-push
go test ./tests/e2e -test.v -ginkgo.v -ginkgo.progress
Flags
(TODO) Kubeconf selection

Currently, test init will load a Kubeconf based on Defalut Kubeconf Loading rules. If Kind is used, the kubeconf is temporarily replaced and Kind's kubeconf is used instead.

Container registry

A container registry where to load the images from (OSM, init container, etc.). Credentials are optional if the container registry allows pulling the images publicly:

-ctrRegistry string
		Container registry
-ctrRegistrySecret string
		Container registry secret
-ctrRegistryUser string
		Container registry username

If container registry user and password are provided, the test framework will take care to add those as Docker secret credentials for the given container registry whenever appropriate (tenant namespaces for init containers, OSM intallation, etc). Container registry related flags can also be set through env:

export CTR_REGISTRY=<your_cr>.dockerhub.io
export CTR_REGISTRY_USER=<uername>             # opt
export CTR_REGISTRY_PASSWORD=<password>        # opt
OSM Tag

The following flag will refer to the version of the OSM platform containers (OSM and init) for test to use:

-osmImageTag string
		OSM image tag (default "latest")

Make sure you have compiled the images and pushed them on your registry first if you are not using a kind cluster:

export CTR_REGISTRY=myacr.dockerhub.io
export CTR_TAG=mytag               # Optional, 'latest' used by default
make docker-push-init docker-push-osm-controller.    # Use docker-build-* targets instead when using kind
Use Kind for testing

Testing implements support for Kind. If kindCluster is enabled, a new Kind cluster will be provisioned and it will be automatically used for the test.

-kindCluster
		Creates kind cluster
-kindClusterName string
		Name of the Kind cluster to be created (default "osm-e2e")
-cleanupKindCluster
		Cleanup kind cluster upon exit (default true)
-cleanupKindClusterBetweenTests
		Cleanup kind cluster between tests (default true)
Test specific flags

Worth mentioning cleanupTest is especially useful for debugging or leaving the test in a certain state at test-exit. When using Kind, you need to use cleanupKindCluster and cleanupKindClusterBetweenTests in conjunction, or else the cluster will anyway be destroyed.

-cleanupTest
		Cleanup test resources when done (default true)
-meshName string
		OSM mesh name (default "osm-system")
-waitForCleanup
		Wait for effective deletion of resources (default true)

Plus, go test and Ginkgo specific flags, of course.

Documentation

Index

Constants

View Source
const (
	// StatusCodeWord is an identifier used on curl commands to print and parse REST Status codes
	StatusCodeWord = "StatusCode"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CleanupType

type CleanupType string

CleanupType identifies what triggered the cleanup

const (
	// Test is to mark after-test cleanup
	Test CleanupType = "test"
	//Suite is to mark after-suite cleanup
	Suite CleanupType = "suite"
)

type DockerConfig

type DockerConfig map[string]DockerConfigEntry

DockerConfig and other configs are docker-specific container registry secret structures. Most of it is taken or referenced from kubectl source itself

type DockerConfigEntry

type DockerConfigEntry struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
	Email    string `json:"email,omitempty"`
	Auth     string `json:"auth,omitempty"`
}

type DockerConfigJSON

type DockerConfigJSON struct {
	Auths       DockerConfig      `json:"auths"`
	HTTPHeaders map[string]string `json:"HttpHeaders,omitempty"`
}

type HTTPMultipleRequest

type HTTPMultipleRequest struct {
	// Request
	Sources []HTTPRequestDef
}

HTTPMultipleRequest takes multiple HTTP request defs to issue them concurrently

type HTTPMultipleResults

type HTTPMultipleResults map[string]map[string]HTTPRequestResult

HTTPMultipleResults represents results from a multiple HTTP request call results come back as a map[namespace][pod] -> HTTPResults

type HTTPRequestDef

type HTTPRequestDef struct {
	// Source pod where to run the HTTP request from
	SourceNs        string
	SourcePod       string
	SourceContainer string

	// Either host or IP, ie. "server", "server1.server", "192.168.0.1"
	Destination string
	// HTTP path on url, ie. "/index.html"
	HTTPUrl string
	// TCP port on request
	Port int
}

HTTPRequestDef defines a remote HTTP request intent

type HTTPRequestResult

type HTTPRequestResult struct {
	StatusCode int
	Headers    map[string]string
	Err        error
}

HTTPRequestResult represents results of an HTTPRequest call

type InstallOSMOpts

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

InstallOSMOpts describes install options for OSM

type OsmTestData

type OsmTestData struct {
	T GinkgoTInterface // for common test logging
	// contains filtered or unexported fields
}

OsmTestData stores common state, variables and flags for the test at hand

func (*OsmTestData) AddNsToMesh

func (td *OsmTestData) AddNsToMesh(sidecardInject bool, ns ...string) error

AddNsToMesh Adds monitored namespaces to the OSM mesh

func (*OsmTestData) AreRegistryCredsPresent

func (td *OsmTestData) AreRegistryCredsPresent() bool

AreRegistryCredsPresent checks if Registry Credentials are present It's usually used to factor if a docker registry secret and ImagePullSecret should be installed when creating namespaces and application templates

func (*OsmTestData) Cleanup

func (td *OsmTestData) Cleanup(ct CleanupType)

Cleanup is Used to cleanup resorces once the test is done

func (*OsmTestData) CreateDeployment

func (td *OsmTestData) CreateDeployment(ns string, deployment appsv1.Deployment) (*appsv1.Deployment, error)

CreateDeployment is a wrapper to create a deployment

func (*OsmTestData) CreateDockerRegistrySecret

func (td *OsmTestData) CreateDockerRegistrySecret(ns string)

CreateDockerRegistrySecret creates a secret named `registrySecretName` in namespace <ns>, based on ctrRegistry variables

func (*OsmTestData) CreateHTTPRouteGroup

func (td *OsmTestData) CreateHTTPRouteGroup(ns string, rg smiSpecs.HTTPRouteGroup) (*smiSpecs.HTTPRouteGroup, error)

CreateHTTPRouteGroup Creates an SMI Route Group

func (*OsmTestData) CreateMultipleNs

func (td *OsmTestData) CreateMultipleNs(nsName ...string) error

CreateMultipleNs simple CreateNs for multiple NS creation

func (*OsmTestData) CreateNs

func (td *OsmTestData) CreateNs(nsName string, labels map[string]string) error

CreateNs creates a Namespace. Will automatically add Docker registry creds if provided

func (*OsmTestData) CreatePod

func (td *OsmTestData) CreatePod(ns string, pod corev1.Pod) (*corev1.Pod, error)

CreatePod is a wrapper to create a pod

func (*OsmTestData) CreateService

func (td *OsmTestData) CreateService(ns string, svc corev1.Service) (*corev1.Service, error)

CreateService is a wrapper to create a service

func (*OsmTestData) CreateServiceAccount

func (td *OsmTestData) CreateServiceAccount(ns string, svcAccount *corev1.ServiceAccount) (*corev1.ServiceAccount, error)

CreateServiceAccount is a wrapper to create a service account

func (*OsmTestData) CreateSimpleAllowPolicy

func (td *OsmTestData) CreateSimpleAllowPolicy(def SimpleAllowPolicy) (smiSpecs.HTTPRouteGroup, smiAccess.TrafficTarget)

CreateSimpleAllowPolicy returns basic allow policy from source to destination, on a HTTP all-wildcard fashion

func (*OsmTestData) CreateSimpleTrafficSplit

func (td *OsmTestData) CreateSimpleTrafficSplit(def TrafficSplitDef) (smiSplit.TrafficSplit, error)

CreateSimpleTrafficSplit Creates an SMI TrafficTarget

func (*OsmTestData) CreateTrafficSplit

func (td *OsmTestData) CreateTrafficSplit(ns string, tar smiSplit.TrafficSplit) (*smiSplit.TrafficSplit, error)

CreateTrafficSplit Creates an SMI TrafficSplit

func (*OsmTestData) CreateTrafficTarget

func (td *OsmTestData) CreateTrafficTarget(ns string, tar smiAccess.TrafficTarget) (*smiAccess.TrafficTarget, error)

CreateTrafficTarget Creates an SMI TrafficTarget

func (*OsmTestData) DeleteNs

func (td *OsmTestData) DeleteNs(nsName string) error

DeleteNs deletes a test NS

func (*OsmTestData) GetOSMInstallOpts

func (td *OsmTestData) GetOSMInstallOpts() InstallOSMOpts

GetOSMInstallOpts initializes install options for OSM

func (*OsmTestData) HTTPRequest

func (td *OsmTestData) HTTPRequest(ht HTTPRequestDef) HTTPRequestResult

HTTPRequest runs a synchronous call to run the HTTPRequestDef and return a HTTPRequestResult

func (*OsmTestData) InitSMIClients

func (td *OsmTestData) InitSMIClients() error

InitSMIClients initializes SMI clients on OsmTestData structure

func (*OsmTestData) InitTestData

func (td *OsmTestData) InitTestData(t GinkgoTInterface) error

InitTestData Initializes the test structures Called by Gingkgo BeforeEach

func (*OsmTestData) InstallOSM

func (td *OsmTestData) InstallOSM(instOpts InstallOSMOpts) error

InstallOSM installs OSM. Right now relies on externally calling the binary and a subset of possible opts TODO: refactor install to be able to call it directly here vs. exec-ing CLI.

func (*OsmTestData) MultipleHTTPRequest

func (td *OsmTestData) MultipleHTTPRequest(requests *HTTPMultipleRequest) HTTPMultipleResults

MultipleHTTPRequest will issue a list of requests concurrently and return results when all requests have returned

func (*OsmTestData) PrettyPrintHTTPResults

func (td *OsmTestData) PrettyPrintHTTPResults(results *HTTPMultipleResults)

PrettyPrintHTTPResults prints pod results per namespace

func (*OsmTestData) RunLocal

func (td *OsmTestData) RunLocal(path string, args []string) (*bytes.Buffer, *bytes.Buffer, error)

RunLocal Executes command on local

func (*OsmTestData) RunRemote

func (td *OsmTestData) RunRemote(
	ns string, podName string, containerName string,
	command string) (string, string, error)

RunRemote runs command in remote container

func (*OsmTestData) SimpleDeploymentApp

SimpleDeploymentApp creates returns a set of k8s typed definitions for a deployment-based k8s definition. Includes Deployment, Service and ServiceAccount types

func (*OsmTestData) SimplePodApp

SimplePodApp creates returns a set of k8s typed definitions for a pod-based k8s definition. Includes Pod, Service and ServiceAccount types

func (*OsmTestData) WaitForNamespacesDeleted

func (td *OsmTestData) WaitForNamespacesDeleted(namespaces []string, timeout time.Duration) error

WaitForNamespacesDeleted waits for the namespaces to be deleted. Reference impl taken from https://github.com/kubernetes/kubernetes/blob/master/test/e2e/framework/util.go#L258

func (*OsmTestData) WaitForPodsRunningReady

func (td *OsmTestData) WaitForPodsRunningReady(ns string, timeout time.Duration, nExpectedRunningPods int) error

WaitForPodsRunningReady waits for a <n> number of pods on an NS to be running and ready

func (*OsmTestData) WaitForRepeatedSuccess

func (td *OsmTestData) WaitForRepeatedSuccess(f SuccessFunction, minItForSuccess int, maxWaitTime time.Duration) bool

WaitForRepeatedSuccess runs and expects a certain result for a certain operation a set number of consecutive times over a set amount of time.

type SimpleAllowPolicy

type SimpleAllowPolicy struct {
	RouteGroupName string

	TrafficTargetName string

	SourceSVCAccountName string
	SourceNamespace      string

	DestinationSvcAccountName string
	DestinationNamespace      string
}

SimpleAllowPolicy is a simplified struct to later get basic SMI allow policy

type SimpleDeploymentAppDef

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

SimpleDeploymentAppDef defines some parametrization to create a deployment-based application from template

type SimplePodAppDef

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

SimplePodAppDef defines some parametrization to create a pod-based application from template

type SuccessFunction

type SuccessFunction func() bool

SuccessFunction is a simple definition for a success function. True as success, false otherwise

type TrafficSplitBackend

type TrafficSplitBackend struct {
	Name   string
	Weight int
}

TrafficSplitBackend is a simple define to refer to a TrafficSplit backend

type TrafficSplitDef

type TrafficSplitDef struct {
	Name      string
	Namespace string

	TrafficSplitServiceName string
	Backends                []TrafficSplitBackend
}

TrafficSplitDef is a simplified struct to get a TrafficSplit typed definition

Jump to

Keyboard shortcuts

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