k8s

package
v0.0.0-...-6240e64 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package k8s spins up a Kubernetes cluster for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cluster

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

Cluster is a Kubernetes cluster that runs inside of a k3s Docker container. Call GetConfig to retrieve a Kubernetes *rest.Config to use to connect to the cluster.

Cluster also runs an NGINX ingress controller which is exposed to the host. Call GetHTTPAddr to get the address for making requests against the server.

Set E2E_K8S_USE_DOCKER_NETWORK in your environment variables if you are running tests from inside of a Docker container. This environment variable configures the k3s Docker container to join the same network as the container tests are running in. When this environment variable isn't set, the exposed ports on the Docker host are used for cluster communication.

Note that k3s uses containerd as its runtime, which means local Docker images are not immediately available for use. To push local images to a container, call PushImages. It's recommended that tests use image names that are not available on Docker Hub to avoid accidentally testing against the wrong image.

Cluster should be stopped by calling Stop, otherwise running Docker containers will leak.

func NewCluster

func NewCluster() (cluster *Cluster, err error)

NewCluster creates a new Cluster.

func (*Cluster) GetConfig

func (c *Cluster) GetConfig() *rest.Config

GetConfig returns a *rest.Config that can be used to connect to the Kubernetes cluster. The returned Config is a copy and is safe for modification.

func (*Cluster) GetHTTPAddr

func (c *Cluster) GetHTTPAddr() string

GetHTTPAddr returns the host:port address that can be used to connect to the cluster's NGINX server.

func (*Cluster) PushImages

func (c *Cluster) PushImages(images ...string) error

PushImages push images from the local Docker host into the Cluster. If the specified image does not have a tag, `:latest` is assumed.

func (*Cluster) Stop

func (c *Cluster) Stop()

Stop shuts down and deletes the cluster. Stop must be called to clean up created Docker resources.

Jump to

Keyboard shortcuts

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