framework

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2018 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

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) ConfigMaps

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

ConfigMaps returns interface for ConfigMap objects

func (*Controller) CreateVirtletImageMapping

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) RunPod

func (c *Controller) RunPod(name, image string, command []string, timeout time.Duration, exposePorts ...int32) (*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

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) 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)
}

Executor is the interface to run shell commands in arbitrary places

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) 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 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 interface to execute commands in one of pod's containers

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) 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) WaitDestruction

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

WaitDestruction waits for the pod to be deleted

type VMInterface

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

VMInterface provides API to work with virtlet VM pods

func (*VMInterface) Create

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

Create create new virtlet VM pod in k8s

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) 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 {
	Image             string
	VCPUCount         int
	SSHKey            string
	SSHKeySource      string
	CloudInitScript   string
	DiskDriver        string
	Limits            map[string]string
	UserData          string
	OverwriteUserData bool
	UserDataScript    string
	UserDataSource    string
	NodeName          string
}

VMOptions defines VM parameters

Jump to

Keyboard shortcuts

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