Documentation ¶
Index ¶
- Constants
- Variables
- func Curl(url string) (string, error)
- func Run(executor Executor, input string, command ...string) (string, string, error)
- func RunSimple(executor Executor, command ...string) (string, error)
- func RunVirsh(virtletPod *PodInterface, command ...string) (string, error)
- func WithTimeout(timeout time.Duration, fn func() error) func() error
- type Command
- type CommandError
- type Controller
- func (c *Controller) AddLabelsToNode(nodeName string, labels map[string]string) error
- func (c *Controller) AvailableNodeName() (string, error)
- func (c *Controller) ConfigMaps() typedv1.ConfigMapInterface
- func (c *Controller) CreateVirtletConfigMapping(configMapping virtlet_v1.VirtletConfigMapping) (*virtlet_v1.VirtletConfigMapping, error)
- func (c *Controller) CreateVirtletImageMapping(mapping virtlet_v1.VirtletImageMapping) (*virtlet_v1.VirtletImageMapping, error)
- func (c *Controller) DeleteVirtletConfigMapping(name string) error
- func (c *Controller) DeleteVirtletImageMapping(name string) error
- func (c *Controller) DinDNodeExecutor(name string) (Executor, error)
- func (c *Controller) DockerContainer(name string) (*DockerContainerInterface, error)
- func (c *Controller) Finalize() error
- func (c *Controller) FindPod(namespace string, labelMap map[string]string, ...) (*PodInterface, error)
- func (c *Controller) Namespace() string
- func (c *Controller) PersistentVolumeClaimsClient() typedv1.PersistentVolumeClaimInterface
- func (c *Controller) PersistentVolumesClient() typedv1.PersistentVolumeInterface
- func (c *Controller) Pod(name, namespace string) (*PodInterface, error)
- func (c *Controller) RemoveLabelOffNode(nodeName string, labelKeys []string) error
- func (c *Controller) RunPod(name, image string, opts RunPodOptions) (*PodInterface, error)
- func (c *Controller) Secrets() typedv1.SecretInterface
- func (c *Controller) VM(name string) *VMInterface
- func (c *Controller) VirtletNodeName() (string, error)
- func (c *Controller) VirtletPod() (*PodInterface, error)
- func (c *Controller) WaitForVirtletPodOnTheNode(name string) (*PodInterface, error)
- func (c *Controller) WaitForVirtletPodToDisappearFromTheNode(name string) error
- type DockerContainerExecInterface
- func (*DockerContainerExecInterface) Close() error
- func (*DockerContainerExecInterface) Logs() (string, error)
- func (n *DockerContainerExecInterface) Run(stdin io.Reader, stdout, stderr io.Writer, command ...string) error
- func (*DockerContainerExecInterface) Start(stdin io.Reader, stdout, stderr io.Writer, command ...string) (Command, error)
- type DockerContainerInterface
- func (d *DockerContainerInterface) Container() (*types.Container, error)
- func (d *DockerContainerInterface) Delete() error
- func (d *DockerContainerInterface) Executor(privileged bool, user string) Executor
- func (d *DockerContainerInterface) PullImage(name string) error
- func (d *DockerContainerInterface) Run(image string, env map[string]string, network string, ports []string, ...) error
- type Executor
- type HostPathMount
- type LocalCmd
- type PVCInterface
- type PVCSpec
- type PodInterface
- func (pi *PodInterface) Container(name string) (Executor, error)
- func (pi *PodInterface) Create() error
- func (pi *PodInterface) Delete() error
- func (pi *PodInterface) DinDNodeExecutor() (Executor, error)
- func (pi *PodInterface) LoadEvents() ([]string, error)
- func (pi *PodInterface) PortForward(ports []*tools.ForwardedPort) (chan struct{}, error)
- func (pi *PodInterface) Wait(timing ...time.Duration) error
- func (pi *PodInterface) WaitForDestruction(timing ...time.Duration) error
- func (pi *PodInterface) WaitForPodStatus(expectedContainerErrors []string, timing ...time.Duration) error
- type RunPodOptions
- type VMInterface
- func (vmi *VMInterface) Create(options VMOptions, beforeCreate func(*PodInterface)) error
- func (vmi *VMInterface) CreateAndWait(options VMOptions, waitTimeout time.Duration, beforeCreate func(*PodInterface)) error
- func (vmi *VMInterface) Delete(waitTimeout time.Duration) error
- func (vmi *VMInterface) Domain() (libvirtxml.Domain, error)
- func (vmi *VMInterface) DomainName() (string, error)
- func (vmi *VMInterface) Pod() (*PodInterface, error)
- func (vmi *VMInterface) PodWithoutChecks() *PodInterface
- func (vmi *VMInterface) SSH(user, secret string) (Executor, error)
- func (vmi *VMInterface) VirshCommand(command ...string) (string, error)
- func (vmi *VMInterface) VirtletPod() (*PodInterface, error)
- type VMOptions
Constants ¶
const ( NginxImage = "docker.io/nginx:1.14.2" BusyboxImage = "docker.io/busybox:1.30.0" )
Variables ¶
var ClusterURL = flag.String("cluster-url", "http://127.0.0.1:8080", "apiserver URL")
var ErrTimeout = fmt.Errorf("timeout")
ErrTimeout is the timeout error returned from functions wrapped by WithTimeout
Functions ¶
func Run ¶
Run executes command with the given executor, returns stdout/stderr as strings and exit code in CommandError
func RunSimple ¶
RunSimple is a simplified version of Run that verifies exit code/stderr internally and returns stdout only
Types ¶
type CommandError ¶
type CommandError struct {
ExitCode int
}
CommandError holds an exit code for commands finished without any Executor error
func (CommandError) Error ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (c *Controller) WaitForVirtletPodOnTheNode(name string) (*PodInterface, error)
func (*Controller) WaitForVirtletPodToDisappearFromTheNode ¶
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 ¶
func (*DockerContainerExecInterface) Close() error
Close closes the executor
func (*DockerContainerExecInterface) Logs ¶
func (*DockerContainerExecInterface) Logs() (string, error)
Logs 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
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 ¶
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 ¶
type PVCInterface ¶
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 ¶
func (pvci *PVCInterface) AddToPod(pi *PodInterface, name string)
AddToPod adds the volume to the pod referencing the PVC.
func (*PVCInterface) Create ¶
func (pvci *PVCInterface) Create() error
Create creates the PVC and its corresponding PV.
func (*PVCInterface) Delete ¶
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 ¶
func (pvci *PVCInterface) WaitForDestruction(timing ...time.Duration) error
WaitForDestruction waits for the PV and PVC to be deleted.
type PVCSpec ¶
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 ¶
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) 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 ¶
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 ¶
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 ¶
func (pi *PodInterface) WaitForDestruction(timing ...time.Duration) error
WaitForDestruction waits for the pod to be deleted
func (*PodInterface) WaitForPodStatus ¶
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 ¶
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 ¶
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 ¶
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