Documentation
¶
Index ¶
- Constants
- Variables
- func EncodeFileB64(path string) (string, error)
- func GenerateConfigCloudInit(cluster *Cluster) (string, error)
- func GenerateConfigKubeadm(cluster *Cluster) (string, error)
- func GenerateConfigLB(cluster *Cluster) (string, error)
- func RunCmd(vmName string, args []string) (string, error)
- func SetLogLevel(level LogLevel)
- func Transfer(vmName string, src string, dst string) error
- type BootstrapConfig
- type Cluster
- func (cluster *Cluster) AddComputeIP(IP string)
- func (cluster *Cluster) AddControlIP(IP string)
- func (cluster *Cluster) CreateKubeVMs(cloudInitPath string, numWorkers int)
- func (cluster *Cluster) CreateLB(cloudInitPath string, lbConfPath string) (*Instance, error)
- func (cluster *Cluster) GetCertHash() (string, error)
- func (cluster *Cluster) GetControlVM(vmName string, cloudInitPath string) (*Instance, error)
- func (cluster *Cluster) GetMasterJoinCMD() ([]string, error)
- func (cluster *Cluster) GetWorkerJoinCMD() ([]string, error)
- func (cluster *Cluster) InstallCNI() error
- func (cluster *Cluster) KubeInit(remoteHomeDir string) error
- func (cluster *Cluster) ValidateConfig() error
- type Instance
- type LogLevel
Constants ¶
const MinDisk = "1G"
MinDisk is the minimal disk size that can be assigned to a VM instance
const MinMemory = "2G"
MinMemory is the minimal acceptable memory for a VM instance
Variables ¶
var ( ErrMinControlNodes = errors.New("control nodes number should be odd and minimum 3") ErrMinComputeNodes = errors.New("compute nodes number should be minimum 1") ErrGetHomeDirectory = errors.New("cannot get user's home directory") ErrLoadTemplate = errors.New("cannot load template from embed") ErrCreateFile = errors.New("cannot create new file") ErrParseTemplate = errors.New("cannot parse template") ErrBase64Encode = errors.New("cannot encode file to b64") ErrMemFormat = errors.New("memory format should be like <number>K|M|G|k|m|g") ErrInvalidIPV4Address = errors.New("invalid IP address provided") ErrVMNotRunning = errors.New("VM is not running") ErrVMAlreadyExist = errors.New("VM already exist") ErrCloudInitGeneration = errors.New("unable to generate cloud init file") ErrClusterConfiguration = errors.New("wrong value in cluster configuration") ErrOddNumberCtrlNode = errors.New("number of control nodes should be odd") )
Application wide custom error types.
var Logger = slog.New(h)
Functions ¶
func EncodeFileB64 ¶
EncodeFileB64 encode a file in b64
func GenerateConfigCloudInit ¶
GenerateConfigCloudInit generates configuration files used to bootstrap the kubernetes nodes. This cloud init file is used to prepare the nodes for k8s.
func GenerateConfigKubeadm ¶
GenerateConfigKubeadm generates configuration files used to bootstrap the using KubeAdmin.
func GenerateConfigLB ¶
GenerateConfigLB generates configuration files used to bootstrap the cluster load balancer.
func RunCmd ¶
RunCmd run commands in a VM. It leverages multipass exec command. Returns the combined output (stderr + stdout) of the command and an error.
func SetLogLevel ¶
func SetLogLevel(level LogLevel)
SetLogLevel sets the application log level dynamically. Defaut level in info.
Types ¶
type BootstrapConfig ¶
type BootstrapConfig struct { // Base64 encoded node bootstrap script. Can leverage EncodeFileB64 function for that NodeBootstrapScript string }
BootstrapConfig will hold k8s cluster independent configuration like nodes bootstrap scripts, LB config files and kubernetes version to deploy
type Cluster ¶
type Cluster struct { Name string PublicAPIEndpoint string PodSubnet string // List of IPs for the compute node. Minimum 1. They are updated by vm create command. The reason is that at this time, // multipass does not support setting VM IP address at creation time. So it has to be retrieved after VM creation time // and the cluster info needs to be updated. CmpNodesIPs []string CmpNodesMemory string CmpNodesCores int CmpNodesNumber int CmpNodesDiskSize string // List of IPs for the control node. Minimum 3. CtrlNodesIPs []string CtrlNodesMemory string CtrlNodesCores int CtrlNodesNumber int CtrlNodesDiskSize string LBNodeMemory string LBNodeCore int LBNodeDiskSize string // OS image Image string Mux sync.Mutex // Bootstrap Tokens take the form of abcdef.0123456789abcdef. // More formally, they must match the regular expression [a-z0-9]{6}\.[a-z0-9]{16}. // They can also be created using the command kubeadm token create. BootstrapToken string KubernetesCertKey string }
Cluster is a struct representing a kubernetes cluster. The minimum number of control nodes is 3 and the minimum of compute nodes is 1.
func (*Cluster) AddComputeIP ¶
AddComputeIP add the IP address of a newly created compute machine to compute nodes IP list. This is because multipass does not allow to set static IP on a node. So we have to fetch them dynamically and update the cluster configurations.
func (*Cluster) AddControlIP ¶
AddControlIP add the IP address of a newly created control machine to control nodes IP list. This is because multipass does not allow to set static IP on a node. So we have to fetch them dynamically and update the cluster configurations.
func (*Cluster) CreateKubeVMs ¶
CreateKubeVMs creates a VM for the kubernetes cluster. parallel param is the number of vms to create in parallel. This method use the worker concurrency pattern to create and run VMs. Creating a high number of VMs will incur network traffic and hypervisor cpu load, so the number of workers should be planned wisely.
func (*Cluster) CreateLB ¶
CreateLB creates the LB associated with the cluster and run it. After running this method, you'll have a LB deployed and ready to server traffic. Returns a pointer to an instance of VM and an error. If the VM already exist, an error will be thrown but the VM instance that will be returned will be valid.
func (*Cluster) GetCertHash ¶
GetCertHash retrieves the bootstrap CA certificate hash to populate kubeadm yaml configuration file. The hash is generated and stored in the first control node at the path /tmp/kubeadm-cert-hash. The hash is directly set as a Cluster attribute. This should be run after the control-0 VM is alive.
func (*Cluster) GetControlVM ¶
GetControlVM return a VM instance populated with a control node parameters. This is useful to generate the configuration of an existing vm instance to apply specific instance related methods on them (for instance, file transfer)
func (*Cluster) GetMasterJoinCMD ¶
GetMasterJoinCMD build the master join command to join other master nodes
func (*Cluster) GetWorkerJoinCMD ¶
GetWorkerJoinCMD build the master join command to join other master nodes
func (*Cluster) InstallCNI ¶
InstallCNI installs the cluster CNI. For now, only cilium is supported and is directly hardcoded in the tool.
func (*Cluster) ValidateConfig ¶
ValidateConfig checks if cluster configuration is valid. It checks Disk sizes, memory sizes, and validity of IP addresses @TODO; add more validation (duplicate IPs, PodSubnet, memory and disk sizes, number of nodes)
type Instance ¶
type Instance struct { Cores int // Memory in bytes. Could be prefixed with K, M or G. // Should be more than min memory Memory string // Disk space in bytes. Could be prefixed with K, M or G. // Should be more than min disk Disk string Name string // CloudInitFile is a path to a cloud init file. Not mandatory. CloudInitFile string // Name of the cluster in which this instance belongs to Cluster string // Image is the name of the image to use, on 20.04 works with our k8s script for now Image string }
Instance represents a multipass VM, typically created using the launch subcommand. Try multipass launch --help for more info.
func NewInstanceConfig ¶
func NewInstanceConfig(cores int, memory string, disk string, image string, name string, cloudinit string) (*Instance, error)
NewInstanceConfig returns a valid configuration of an instance or an error cloudinit is the path of a cloud init script to pass to the method