drivercore

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 1 Imported by: 3

README

drivercore

Core interfaces, types and functions for kutti drivers.

Go Report Card PkgGoDev GitHub release (latest by date)

The kutti project aims to let users create small, non production Kubernetes clusters for learning and development. It aims to allow this on all popular platforms.

Drivers are the way to make the kutti project platform-neutral.

A kutti driver manages Networks, Machines and Images.

Documentation

Overview

Package drivercore contains types, interfaces and functions that define kutti driver functionality. It also provides a central place for drivers to register themselves.

The interfaces are:

Driver

This defines the interface for kutti "drivers". Each driver should be able to manage:

- Machines, which represent Kubernetes nodes

- Networks, which connect Machines and may manage DHCP and NAT

- Images, which allow templated creation of Machines

Implemented drivers should call the RegisterDriver function with a unique name on init.

Network

This defines a private network to which all nodes in a cluster will be connected. The network should allow connectivity between nodes, and public internet connectivity. For now, only IPv4 capability is assumed.

Machine

This defines a machine that will act as a Kubernetes node. The machine should allow start, stop, force stop, and wait operations, and provide a way to connect to it via SSH. It should also allow the execution of some predefined commands within its operating system, including:

- RenameMachine

- RestartMachine

- CheckConnectivity

- SetProxy

- SetNoProxy

- InitCluster

- JoinCluster

- InstallOverlayNetwork

Image

This defines a template from which a Machine can be created. An image has a property called K8sVersion , which specifies the version of kubernetes binaries present in Machines created from it. Drivers should include the functionality to download Images from driver-defined repositories, and check their integrity.

Index

Constants

View Source
const (
	ImageStatusNotDownloaded = ImageStatus("Notdownloaded")
	ImageStatusDownloaded    = ImageStatus("Downloaded")
	ImageStatusUnknown       = ImageStatus("Unknown")
)

Image Statuses

View Source
const (
	MachineStatusStopped = MachineStatus("Stopped")
	MachineStatusRunning = MachineStatus("Running")
	MachineStatusUnknown = MachineStatus("Unknown")
	MachineStatusError   = MachineStatus("Error")
)

Machine Statuses

View Source
const (
	RenameMachine         = PredefinedCommand("RenameMachine")
	RestartMachine        = PredefinedCommand("RestartMachine")
	CheckConnectivity     = PredefinedCommand("CheckConnectivity")
	SetProxy              = PredefinedCommand("SetProxy")
	SetNoProxy            = PredefinedCommand("SetNoProxy")
	InitCluster           = PredefinedCommand("InitCluster")
	JoinCluster           = PredefinedCommand("JoinCluster")
	InstallOverlayNetwork = PredefinedCommand("InstallOverlayNetwork")
)

Prefined Commands

Variables

This section is empty.

Functions

func DriverCount

func DriverCount() int

DriverCount returns the number of registered drivers.

func ForEachDriver

func ForEachDriver(f func(Driver) bool)

ForEachDriver iterates over registered Drivers. The callback function can return false to stop the iteration.

func IsRegisteredDriver added in v0.3.0

func IsRegisteredDriver(name string) bool

IsRegisteredDriver checks if a driver name is registered. The name check is case-insensitive.

func RegisterDriver

func RegisterDriver(name string, d Driver)

RegisterDriver registers a Driver with a name to drivercore. If a driver with the specified name already exists, it is replaced. Driver names are converted to lower case.

func RegisteredDrivers

func RegisteredDrivers() []string

RegisteredDrivers returns all registered driver names.

Types

type Driver

type Driver interface {
	// Name returns the unique name for a Driver. It should be short.
	Name() string
	// Description returns a short description of the Driver.
	Description() string
	// UsesPerClusterNetworking should return true if the Driver supports
	// creation of isolated Networks (NAT or routed) per cluster.
	UsesPerClusterNetworking() bool
	// UsesNATNetworking should return true if the networking used by the
	// Driver implements NAT, and therefore Machine ports need forwarding.
	UsesNATNetworking() bool
	// Status returns the current status of the Driver.
	Status() string
	// Error returns the last error reported by the Driver.
	Error() string

	// QualifiedNetworkName returns a unique Network name for a cluster.
	QualifiedNetworkName(clustername string) string
	// DeleteNetwork deletes the Network for a cluster.
	DeleteNetwork(clustername string) error
	// NewNetwork creates a new Network for a cluster.
	NewNetwork(clustername string) (Network, error)

	// QualifiedMachineName returns a unique name for a Machine in a cluster.
	// This name is usually used internally by a Driver.
	QualifiedMachineName(machinename string, clustername string) string
	// GetMachine returns a Machine in a cluster.
	GetMachine(machinename string, clustername string) (Machine, error)
	// DeleteMachine deletes a Machine in a cluster.
	DeleteMachine(machinename string, clustername string) error
	// NewMachine creates a new Machine in a cluster, usually using an Image
	// for the supplied Kubernetes version.
	NewMachine(machinename string, clustername string, k8sversion string) (Machine, error)

	// UpdateImageList fetches the latest list of Images from a driver-defined
	// source, and stores it locally.
	UpdateImageList() error
	// ValidK8sVersion returns true if the specified Kubernetes version is
	// available in the local list.
	ValidK8sVersion(k8sversion string) bool
	// K8sVersions returns all Kubernetes versions currently supported by a
	// Driver. This should come from the local list.
	K8sVersions() []string
	// ListImages returns the currently available Images from the local list.
	ListImages() ([]Image, error)
	// GetImage returns the Image for a Kubernetes version, or an error.
	GetImage(k8sversion string) (Image, error)
}

Driver describes operations to manage Networks, Machines and Images. The UsesPerClusterNetworking method returns true if the driver supports creation of Networks per cluster. The UsesNATNetworking() method returns true if the Networks of the driver use NAT. This means that ports of the Machines will need to be forwarded to physical host ports for host access. A driver is also responsible for maintaining a local cache of Images. It can update a list of published images from a driver-defined source, download local copies of images, and delete local copies (but not the image list itself).

func GetDriver

func GetDriver(name string) (Driver, bool)

GetDriver returns a Driver corresponding to the name. If there is no driver registered against the name, nil is returned. Names are case-insensitive.

type Image

type Image interface {
	// K8sVersion returns the version of Kubernetes components in the image.
	K8sVersion() string
	// Status can be Notdownloaded, Downloaded or Unknown.
	Status() ImageStatus
	// Deprecated returns true if the image is no longer supported.
	Deprecated() bool

	// Fetch downloads the image from the driver repository into the local cache.
	Fetch() error
	// FetchWithProgress downloads the image from the driver repository into the
	// local cache, and reports progress via the supplied callback. The callback
	// reports current and total in bytes.
	FetchWithProgress(progress func(current int64, total int64)) error
	// FromFile imports the image from the local filesystem into the local cache.
	FromFile(filepath string) error
	// PurgeLocal removes the image from the local cache.
	PurgeLocal() error
}

Image describes a template from which Machines are created. Each kutti Image should contain binaries for a specific Kubernetes version. A Driver is expected to maintain a cache of Images locally, which can be updated from a driver-specific source. An Image listed in this cache will have a status of Notdownloaded before the actual template is downloaded, or Downloaded after it is. An Image in the local cache can be downloaded from a driver-specific source using the Fetch method, or added to the cache from a local file using the FromFile method. The Image can be purged from the local cache (but not from the list) using the PurgeLocal method.

type ImageStatus

type ImageStatus string

ImageStatus can be Notdownloaded, Downloaded or Unknown

type Machine

type Machine interface {
	// Name is the name of the machine.
	// The operating system hostname should match this.
	Name() string
	// Status can be drivercore.MachineStatusRunning, drivercore.MachineStatusStopped
	// drivercore.MachineStatusUnknown or drivercore.MachineStatusError.
	Status() MachineStatus
	// Error returns the last error caused when manipulating this machine.
	// A valid value can be expected only when Status() returns
	// drivercore.MachineStatusError.
	Error() string

	// IPAddress returns the current IP Address of this Machine.
	// A valid value can be expected only when Status() returns
	// drivercore.MachineStatusRunning.
	IPAddress() string
	// SSHAddress returns the host address and port number to SSH into this Machine.
	// For drivers that use NAT netwoking, the host address will be 'localhost'.
	SSHAddress() string

	// Start starts a Machine.
	// Note that a Machine may not be ready for further operations at the end of this,
	// and therefore its status may not change immediately.
	// See WaitForStateChange().
	Start() error
	// Stop stops a Machine.
	// Note that a Machine may not be ready for further operations at the end of this,
	// and therefore its status will not change immediately.
	// See WaitForStateChange().
	Stop() error
	// ForceStop stops a Machine forcibly.
	// This operation should set the status to drivercore.MachineStatusStopped.
	ForceStop() error
	// WaitForStateChange waits the specified number of seconds, or until the Machine
	// status changes.
	// WaitForStateChange should be called after calls to Start() or Stop(), before
	// any other operation. It should not be called _before_ Stop().
	WaitForStateChange(timeoutinseconds int)

	// ForwardPort creates a rule to forward the specified Machine port to the
	// specified physical host port.
	ForwardPort(hostport int, machineport int) error
	// UnforwardPort removes the rule which forwarded the specified Machine port.
	UnforwardPort(machineport int) error
	// ForwardSSHPort forwards the SSH port of this Machine to the specified
	// physical host port.
	ForwardSSHPort(hostport int) error

	// ImplementsCommand returns true if the driver implements the specified
	// predefined operation.
	ImplementsCommand(command PredefinedCommand) bool
	// ExecuteCommand executes the specified predefined operation.
	ExecuteCommand(command PredefinedCommand, params ...string) error
}

Machine describes a node in a cluster. A machine, when created from an Image, is expected to have an operating system and a container runtime already installed. A machine can be started, stopped normally and stopped forcibly. If the Driver and the Network use NAT, then a Machine can also have its ports forwarded to NAT router ports. A machine provides a way to execute predefined commands within its guest operating system.

type MachineStatus

type MachineStatus string

MachineStatus can be either Stopped, Running, Unknown or Error.

type Network

type Network interface {
	// Name is the name of the network.
	Name() string
	// CIDR is the network's IPv4 address range.
	CIDR() string

	// SetCIDR sets a new IPv4 address range, in CIDR format.
	SetCIDR(cidr string)
}

Network describes a virtual network, via which a cluster of Machines are connected. It provides machine-to-machine private connectivity, and external network connectivity via routing or NAT. It may also manage DHCP.

type PredefinedCommand

type PredefinedCommand string

PredefinedCommand provides commands that Machines can execute while running. Drivers implement these.

Directories

Path Synopsis
Package drivercoretest provides utilities for driver testing.
Package drivercoretest provides utilities for driver testing.
drivermock
Package drivermock implements a mock driver.
Package drivermock implements a mock driver.

Jump to

Keyboard shortcuts

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