framework

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2019 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NginxImage   = "docker.io/nginx:1.14.2"
	BusyboxImage = "docker.io/busybox:1.30.0"
)

Variables

View Source
var ClusterURL = flag.String("cluster-url", "http://127.0.0.1:8080", "apiserver URL")
View Source
var ErrTimeout = fmt.Errorf("timeout")

ErrTimeout is the timeout error returned from functions wrapped by WithTimeout

Functions

func Curl

func Curl(url string) (string, error)

func Run added in v1.0.0

func Run(executor Executor, input string, command ...string) (string, string, error)

Run executes command with the given executor, returns stdout/stderr as strings and exit code in CommandError

func RunSimple added in v1.0.0

func RunSimple(executor Executor, command ...string) (string, error)

RunSimple is a simplified version of Run that verifies exit code/stderr internally and returns stdout only

func RunVirsh

func RunVirsh(virtletPod *PodInterface, command ...string) (string, error)

RunVirsh runs virsh command in the given virtlet pod

func WithTimeout

func WithTimeout(timeout time.Duration, fn func() error) func() error

WithTimeout adds timeout to synchronous function

Types

type Command added in v1.0.0

type Command interface {
	Kill() error
	Wait() error
}

Command is the interface to control the command started with an Executor

type CommandError added in v1.0.0

type CommandError struct {
	ExitCode int
}

CommandError holds an exit code for commands finished without any Executor error

func (CommandError) Error added in v1.0.0

func (e CommandError) Error() string

type Controller

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

Controller is the entry point for various operations on k8s+virtlet entities

func NewController

func NewController(namespace string) (*Controller, error)

NewController creates instance of controller for specified k8s namespace. If namespace is empty string then namespace with random name is going to be created

func (*Controller) AddLabelsToNode added in v1.1.2

func (c *Controller) AddLabelsToNode(nodeName string, labels map[string]string) error

AddLabelsToNode adds the specified labels to the node. Based on test/utils/density_utils.go in the Kubernetes source.

func (*Controller) AvailableNodeName added in v1.1.2

func (c *Controller) AvailableNodeName() (string, error)

AvailableNodeName returns the name of a node that doesn't run Virtlet after the standard test setup is done but which can be labelled to run Virtlet.

func (*Controller) ConfigMaps

func (c *Controller) ConfigMaps() typedv1.ConfigMapInterface

ConfigMaps returns interface for ConfigMap objects

func (*Controller) CreateVirtletConfigMapping added in v1.1.2

func (c *Controller) CreateVirtletConfigMapping(configMapping virtlet_v1.VirtletConfigMapping) (*virtlet_v1.VirtletConfigMapping, error)

func (*Controller) CreateVirtletImageMapping

func (c *Controller) CreateVirtletImageMapping(mapping virtlet_v1.VirtletImageMapping) (*virtlet_v1.VirtletImageMapping, error)

func (*Controller) DeleteVirtletConfigMapping added in v1.1.2

func (c *Controller) DeleteVirtletConfigMapping(name string) error

func (*Controller) DeleteVirtletImageMapping

func (c *Controller) DeleteVirtletImageMapping(name string) error

func (*Controller) DinDNodeExecutor

func (c *Controller) DinDNodeExecutor(name string) (Executor, error)

DinDNodeExecutor returns executor in DinD container for one of k8s nodes

func (*Controller) DockerContainer

func (c *Controller) DockerContainer(name string) (*DockerContainerInterface, error)

DockerContainer returns interface for operations on a docker container with a given name

func (*Controller) Finalize

func (c *Controller) Finalize() error

Finalize deletes random namespace that might has been created by NewController

func (*Controller) FindPod

func (c *Controller) FindPod(namespace string, labelMap map[string]string,
	predicate func(podInterface *PodInterface) bool) (*PodInterface, error)

FindPod looks for a pod in a given namespace having specified labels and matching optional predicate function

func (*Controller) Namespace

func (c *Controller) Namespace() string

Namespace returns default controller namespace name

func (*Controller) PersistentVolumeClaimsClient

func (c *Controller) PersistentVolumeClaimsClient() typedv1.PersistentVolumeClaimInterface

PersistentVolumeClaimsClient returns interface for PVCs

func (*Controller) PersistentVolumesClient

func (c *Controller) PersistentVolumesClient() typedv1.PersistentVolumeInterface

PersistentVolumesClient returns interface for PVs

func (*Controller) Pod

func (c *Controller) Pod(name, namespace string) (*PodInterface, error)

Pod returns interface for operations on k8s pod in a given namespace. If namespace is an empty string then default controller namespace is used

func (*Controller) RemoveLabelOffNode added in v1.1.2

func (c *Controller) RemoveLabelOffNode(nodeName string, labelKeys []string) error

RemoveLabelOffNode is for cleaning up labels temporarily added to node, won't fail if target label doesn't exist or has been removed. Based on test/utils/density_utils.go in the Kubernetes source.

func (*Controller) RunPod

func (c *Controller) RunPod(name, image string, opts RunPodOptions) (*PodInterface, error)

RunPod is a helper method to create a pod in a simple configuration (similar to `kubectl run`)

func (*Controller) Secrets

func (c *Controller) Secrets() typedv1.SecretInterface

Secrets returns interface for Secret objects

func (*Controller) VM

func (c *Controller) VM(name string) *VMInterface

VM returns interface for operations on virtlet VM pods

func (*Controller) VirtletNodeName

func (c *Controller) VirtletNodeName() (string, error)

VirtletNodeName returns the name of one of the nodes that run Virtlet

func (*Controller) VirtletPod

func (c *Controller) VirtletPod() (*PodInterface, error)

VirtletPod returns one of the active virtlet pods

func (*Controller) WaitForVirtletPodOnTheNode added in v1.1.2

func (c *Controller) WaitForVirtletPodOnTheNode(name string) (*PodInterface, error)

func (*Controller) WaitForVirtletPodToDisappearFromTheNode added in v1.1.2

func (c *Controller) WaitForVirtletPodToDisappearFromTheNode(name string) error

type DockerContainerExecInterface

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

DockerContainerExecInterface is the receiver object for commands execution in docker container

func (*DockerContainerExecInterface) Close

Close closes the executor

func (*DockerContainerExecInterface) Logs added in v1.5.0

Logs is a placeholder for fulfilling Executor interface

func (*DockerContainerExecInterface) Run added in v1.0.0

func (n *DockerContainerExecInterface) Run(stdin io.Reader, stdout, stderr io.Writer, command ...string) error

Run executes command in docker container

func (*DockerContainerExecInterface) Start added in v1.0.0

func (*DockerContainerExecInterface) Start(stdin io.Reader, stdout, stderr io.Writer, command ...string) (Command, error)

Start is a placeholder for fulfilling Executor interface

type DockerContainerInterface

type DockerContainerInterface struct {
	Name string
	ID   string
	// contains filtered or unexported fields
}

DockerContainerInterface is the receiver object for docker container operations

func (*DockerContainerInterface) Container

func (d *DockerContainerInterface) Container() (*types.Container, error)

Container returns info for the container associated with method receiver

func (*DockerContainerInterface) Delete

func (d *DockerContainerInterface) Delete() error

Delete deletes docker container

func (*DockerContainerInterface) Executor

func (d *DockerContainerInterface) Executor(privileged bool, user string) Executor

Executor returns interface to run commands in docker container

func (*DockerContainerInterface) PullImage

func (d *DockerContainerInterface) PullImage(name string) error

PullImage pulls docker image from remote registry

func (*DockerContainerInterface) Run

func (d *DockerContainerInterface) Run(image string, env map[string]string, network string, ports []string, privileged bool, cmd ...string) error

Run starts new docker container (similar to `docker run`)

type Executor

type Executor interface {
	io.Closer
	Run(stdin io.Reader, stdout, stderr io.Writer, command ...string) error
	Start(stdin io.Reader, stdout, stderr io.Writer, command ...string) (Command, error)
	Logs() (string, error)
}

Executor is the interface to run shell commands in arbitrary places

type HostPathMount added in v1.5.0

type HostPathMount struct {
	// The path on the host.
	HostPath string
	// The path inside the container.
	ContainerPath string
}

HostPathMount specifies a host path to mount into a pod sandbox.

type LocalCmd

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

func LocalExecutor

func LocalExecutor(ctx context.Context) *LocalCmd

func (*LocalCmd) Close

func (l *LocalCmd) Close() error

func (*LocalCmd) Logs added in v1.5.0

func (l *LocalCmd) Logs() (string, error)

Logs is a placeholder for fulfilling Executor interface

func (*LocalCmd) Run added in v1.0.0

func (l *LocalCmd) Run(stdin io.Reader, stdout, stderr io.Writer, command ...string) error

func (*LocalCmd) Start added in v1.0.0

func (l *LocalCmd) Start(stdin io.Reader, stdout, stderr io.Writer, command ...string) (Command, error)

type PVCInterface added in v1.4.0

type PVCInterface struct {

	// Spec for the PV and PVC.
	Spec PVCSpec
	// Kubernetes PV object
	Volume *v1.PersistentVolume
	// Kubernetes PVC object
	Claim *v1.PersistentVolumeClaim
	// contains filtered or unexported fields
}

PVCInterface is used to work with PersistentVolumes (PVs) and PersistentVolumeClaims (PVCs).

func (*PVCInterface) AddToPod added in v1.4.0

func (pvci *PVCInterface) AddToPod(pi *PodInterface, name string)

AddToPod adds the volume to the pod referencing the PVC.

func (*PVCInterface) Create added in v1.4.0

func (pvci *PVCInterface) Create() error

Create creates the PVC and its corresponding PV.

func (*PVCInterface) Delete added in v1.4.0

func (pvci *PVCInterface) Delete() error

Delete deletes the PVC and its corresponding PV. It doesn't return an error if either PVC or PV doesn't exist.

func (*PVCInterface) WaitForDestruction added in v1.4.0

func (pvci *PVCInterface) WaitForDestruction(timing ...time.Duration) error

WaitForDestruction waits for the PV and PVC to be deleted.

type PVCSpec added in v1.4.0

type PVCSpec struct {
	// The name of PVC. The PV name is derived by adding the "-pv"
	// suffix.
	Name string
	// The size of PV. Must be parseable as k8s resource quantity
	// (e.g. 10M).
	Size string
	// If non-empty, specifies the node name for local PV.
	NodeName string
	// If true, specifies the block volume mode, otherwise
	// filesystem volume mode is used.
	Block bool
	// In block volume mode, the path to the block device inside the VM,
	// empty value means not referencing the volume in volumeDevices.
	// In filesystem volume mode, the path inside the VM for mounting the volume,
	// empty value means not mounting the volume.
	ContainerPath string
	// For local PVs, specifies the path to the directory when
	// using filesystem mode, and the path to the block device in
	// the block mode.
	LocalPath string
	// Ceph RBD image name.
	CephRBDImage string
	// Ceph monitor IP.
	CephMonitorIP string
	// Ceph pool name for the RBD.
	CephRBDPool string
	// The name of Kubernetes secret to use for Ceph.
	CephSecretName string
	// FlexVolume options for Virtlet flexvolume driver.
	FlexVolumeOptions map[string]string
}

PVCSpec describes a PVC+PV pair to create.

type PodInterface

type PodInterface struct {
	Pod *v1.Pod
	// contains filtered or unexported fields
}

PodInterface provides API to work with a pod

func (*PodInterface) Container

func (pi *PodInterface) Container(name string) (Executor, error)

Container returns an interface to handle one of the pod's containers. If name is empty, it takes the first container of the pod.

func (*PodInterface) Create

func (pi *PodInterface) Create() error

Create creates pod in the k8s

func (*PodInterface) Delete

func (pi *PodInterface) Delete() error

Delete deletes the pod and associated service, which was earlier created by `controller.Run()`

func (*PodInterface) DinDNodeExecutor

func (pi *PodInterface) DinDNodeExecutor() (Executor, error)

DinDNodeExecutor return DinD executor for node, where this pod is located

func (*PodInterface) LoadEvents added in v1.3.0

func (pi *PodInterface) LoadEvents() ([]string, error)

LoadEvents retrieves the evnets for this pod as a list of strings of the form Type:Reason:Message

func (*PodInterface) PortForward added in v1.0.0

func (pi *PodInterface) PortForward(ports []*tools.ForwardedPort) (chan struct{}, error)

PortForward starts port forwarding to the specified ports to the specified pod in background. If a port entry has LocalPort = 0, it's updated with the real port number that was selected by the forwarder. Close returned channel to stop the port forwarder.

func (*PodInterface) Wait

func (pi *PodInterface) Wait(timing ...time.Duration) error

Wait waits for pod to start and checks that it doesn't fail immediately after that

func (*PodInterface) WaitForDestruction added in v1.4.0

func (pi *PodInterface) WaitForDestruction(timing ...time.Duration) error

WaitForDestruction waits for the pod to be deleted

func (*PodInterface) WaitForPodStatus added in v1.3.0

func (pi *PodInterface) WaitForPodStatus(expectedContainerErrors []string, timing ...time.Duration) error

WaitForPodStatus waits for the pod to reach the specified status. If expectedContainerErrors is empty, the pod is expected to become Running and Ready. If it isn't, the pod is expected to have one of these errors among its container statuses.

type RunPodOptions added in v1.5.0

type RunPodOptions struct {
	// The command to run (optional).
	Command []string
	// Timeout. Defaults to 4 minutes.
	Timeout time.Duration
	// The list of ports to expose.
	ExposePorts []int32
	// The list of host paths to mount.
	HostPathMounts []HostPathMount
	// Node name to run this pod on.
	NodeName string
}

RunPodOptions specifies the options for RunPod

type VMInterface

type VMInterface struct {
	Name string
	PVCs []*PVCInterface
	// contains filtered or unexported fields
}

VMInterface provides API to work with virtlet VM pods

func (*VMInterface) Create

func (vmi *VMInterface) Create(options VMOptions, beforeCreate func(*PodInterface)) error

Create creates a new VM pod

func (*VMInterface) CreateAndWait added in v1.3.0

func (vmi *VMInterface) CreateAndWait(options VMOptions, waitTimeout time.Duration, beforeCreate func(*PodInterface)) error

CreateAndWait creates a new VM pod in k8s and waits for it to start

func (*VMInterface) Delete

func (vmi *VMInterface) Delete(waitTimeout time.Duration) error

Delete deletes VM pod and waits for it to disappear from k8s

func (*VMInterface) Domain

func (vmi *VMInterface) Domain() (libvirtxml.Domain, error)

Domain returns libvirt domain definition for the VM

func (*VMInterface) DomainName

func (vmi *VMInterface) DomainName() (string, error)

DomainName returns libvirt domain name the VM

func (*VMInterface) Pod

func (vmi *VMInterface) Pod() (*PodInterface, error)

Pod returns ensures that underlying is started and returns it

func (*VMInterface) PodWithoutChecks added in v1.3.0

func (vmi *VMInterface) PodWithoutChecks() *PodInterface

PodWithoutChecks returns the underlying pods without performing any checks

func (*VMInterface) SSH

func (vmi *VMInterface) SSH(user, secret string) (Executor, error)

SSH returns SSH executor that can run commands in VM

func (*VMInterface) VirshCommand

func (vmi *VMInterface) VirshCommand(command ...string) (string, error)

VirshCommand runs virsh command in the virtlet pod, responsible for this VM Domain name is automatically substituted into commandline in place of `<domain>`

func (*VMInterface) VirtletPod

func (vmi *VMInterface) VirtletPod() (*PodInterface, error)

VirtletPod returns pod in which virtlet instance, responsible for this VM is located (i.e. kube-system:virtlet-xxx pod on the same node)

type VMOptions

type VMOptions struct {
	// VM image to use.
	Image string
	// Number of virtual CPUs.
	VCPUCount int
	// SSH public key to add to the VM.
	SSHKey string
	// SSH key source to use
	SSHKeySource string
	// Cloud-init userdata script
	CloudInitScript string
	// Disk driver to use
	DiskDriver string
	// VM resource limit specs
	Limits map[string]string
	// Cloud-init userdata
	UserData string
	// Enable overridding the userdata
	OverwriteUserData bool
	// Replaces cloud-init userdata with a script
	UserDataScript string
	// Data source for the userdata
	UserDataSource string
	// The name of the node to run the VM on
	NodeName string
	// Root volume size spec
	RootVolumeSize string
	// "cni" annotation value for CNI-Genie
	MultiCNI string
	// PVCs (with corresponding PVs) to use
	PVCs []PVCSpec
	// ConfigMap or Secret to inject into the rootfs
	InjectFilesToRootfsFrom string
	// SystemUUID to set
	SystemUUID string
}

VMOptions defines VM parameters

Jump to

Keyboard shortcuts

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