clustermanager

package
v0.0.0-...-a9402ed Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateEtcdSystemdService

func GenerateEtcdSystemdService(node Node, etcdNodes []Node) string

GenerateEtcdSystemdService generate configuration file used to manage etcd service on systemd

func GenerateMasterConfiguration

func GenerateMasterConfiguration(masterNode Node, masterNodes []Node, etcdNodes []Node, kubernetesVersion string) string

GenerateMasterConfiguration generate the kubernetes config for master

func GenerateOverlayRouteSystemdService

func GenerateOverlayRouteSystemdService(node Node) string

GenerateOverlayRouteSystemdService generate configuration file used to manage overlay route service on systemd

func GenerateWireguardConf

func GenerateWireguardConf(node Node, nodes []Node) string

GenerateWireguardConf generate wireguard configuration file

func PrivateIPPrefix

func PrivateIPPrefix(cidr string) (string, error)

PrivateIPPrefix extracts the first 3 digits of an IPv4 address from CIDR block

Types

type Cluster

type Cluster struct {
	Name              string `json:"name"`
	Nodes             []Node `json:"nodes"`
	HaEnabled         bool   `json:"ha_enabled"`
	IsolatedEtcd      bool   `json:"isolated_etcd"`
	CloudInitFile     string `json:"cloud_init_file"`
	NodeCIDR          string `json:"node_cidr"`
	KubernetesVersion string `json:"kubernetes_version"`
}

Cluster is the structure used to define a cluster

type ClusterProvider

type ClusterProvider interface {
	SetNodes([]Node)
	GetAllNodes() []Node
	GetMasterNodes() []Node
	GetEtcdNodes() []Node
	GetWorkerNodes() []Node
	GetMasterNode() (*Node, error)
	GetCluster() Cluster
	GetAdditionalMasterInstallCommands() []NodeCommand
	GetNodeCidr() string
	MustWait() bool
}

ClusterProvider is the interface used to declare a cluster provider

type EtcdManager

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

EtcdManager is a tool which provides basic backup & restore functionality for HA clusters

func NewEtcdManager

func NewEtcdManager(provider ClusterProvider, nodeCommunicator NodeCommunicator) *EtcdManager

NewEtcdManager returns a new instance of EtcdManager

func (*EtcdManager) CreateSnapshot

func (manager *EtcdManager) CreateSnapshot(name string) error

CreateSnapshot creates a snapshot with a name. If name is empty, a datetime string is generated

func (*EtcdManager) RestoreSnapshot

func (manager *EtcdManager) RestoreSnapshot(name string, skipCopy bool) (bool, error)

RestoreSnapshot restores a snapshot, given its name

type EventService

type EventService interface {
	AddEvent(eventName string, eventMessage string)
}

EventService is the interface used to manage events

type FilePermission

type FilePermission string

FilePermission is the date uesd to define file permission

const (
	// OwnerRead indicate that the file can be readed only from owner
	OwnerRead FilePermission = "C0600"
	// AllRead indicate that the file can be readed from all user on system
	AllRead FilePermission = "C0644"
	// AllExecute indicate that the file can be executed from all user on system
	AllExecute FilePermission = "C0755"
)

type KeepCerts

type KeepCerts int

KeepCerts is an enumeration for existing certificate handling during master install

const (
	// NONE generate completely new certificates
	NONE KeepCerts = 0
	// CA generate certificates using existing authority
	CA KeepCerts = 1
	// ALL keep all certificates
	ALL KeepCerts = 2
)

type Manager

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

Manager is the structure used to mange cluster

func NewClusterManager

func NewClusterManager(provider ClusterProvider, nodeCommunicator NodeCommunicator, eventService EventService, name string, haEnabled bool, isolatedEtcd bool, cloudInitFile string) *Manager

NewClusterManager create a new manager for the cluster

func NewClusterManagerFromCluster

func NewClusterManagerFromCluster(cluster Cluster, provider ClusterProvider, nodeCommunicator NodeCommunicator, eventService EventService) *Manager

NewClusterManagerFromCluster create a new manager from an existing cluster

func (*Manager) AppendNodes

func (manager *Manager) AppendNodes(nodes []Node)

AppendNodes can be used to append nodes to the cluster after initialization

func (*Manager) Cluster

func (manager *Manager) Cluster() Cluster

Cluster creates a Cluster object for further processing

func (*Manager) DeployLoadBalancer

func (manager *Manager) DeployLoadBalancer(nodes []Node) error

DeployLoadBalancer installs a client based load balancer for the master nodes to given nodes

func (*Manager) InstallEtcdNodes

func (manager *Manager) InstallEtcdNodes(nodes []Node, keepData bool) error

InstallEtcdNodes installs the etcd cluster

func (*Manager) InstallMasters

func (manager *Manager) InstallMasters(keepCerts KeepCerts) error

InstallMasters installs the kubernetes control plane to master nodes

func (*Manager) InstallWorkers

func (manager *Manager) InstallWorkers(nodes []Node) error

InstallWorkers installs kubernetes workers to given nodes

func (*Manager) ProvisionNodes

func (manager *Manager) ProvisionNodes(nodes []Node) error

ProvisionNodes install packages for the nodes

func (*Manager) SetupEncryptedNetwork

func (manager *Manager) SetupEncryptedNetwork() error

SetupEncryptedNetwork setups an encrypted virtual network using wireguard modifies the state of manager.Nodes

func (*Manager) SetupHA

func (manager *Manager) SetupHA() error

SetupHA installs the high-availability plane to cluster

type Node

type Node struct {
	Name             string    `json:"name"`
	Type             string    `json:"type"`
	IsMaster         bool      `json:"is_master"`
	IsEtcd           bool      `json:"is_etcd"`
	IPAddress        string    `json:"ip_address"`
	PrivateIPAddress string    `json:"private_ip_address"`
	SSHKeyName       string    `json:"ssh_key_name"`
	WireGuardKeyPair WgKeyPair `json:"wire_guard_key_pair"`
}

Node is the structure used to define a node

type NodeCommand

type NodeCommand struct {
	EventName string
	Command   string
}

NodeCommand is the structure used to define acommand to execute on a node

type NodeCommunicator

type NodeCommunicator interface {
	RunCmd(node Node, command string) (string, error)
	WriteFile(node Node, filePath string, content string, permission FilePermission) error
	CopyFileOverNode(source Node, target Node, filePath string) error
	TransformFileOverNode(source Node, target Node, filePath string, transform func(string) string) error
}

NodeCommunicator is the interface used to define a node comunication protocol

func NewSSHCommunicator

func NewSSHCommunicator(sshKeys []SSHKey, debug bool) NodeCommunicator

NewSSHCommunicator creates an instance of SSHCommunicator

type NodeProvisioner

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

NodeProvisioner provisions all basic packages to install docker, kubernetes and wireguard

func NewNodeProvisioner

func NewNodeProvisioner(node Node, manager *Manager) *NodeProvisioner

NewNodeProvisioner creates a NodeProvisioner instance

func (*NodeProvisioner) Provision

func (provisioner *NodeProvisioner) Provision(node Node, communicator NodeCommunicator, eventService EventService) error

Provision performs all steps to provision a node

type SSHCommunicator

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

SSHCommunicator implements NodeCommunicator as a SSH client

func (*SSHCommunicator) CapturePassphrase

func (sshComm *SSHCommunicator) CapturePassphrase(sshKeyName string) error

CapturePassphrase asks the user to enter a private keys passphrase

func (*SSHCommunicator) CopyFileOverNode

func (sshComm *SSHCommunicator) CopyFileOverNode(sourceNode Node, targetNode Node, filePath string) error

CopyFileOverNode copies a file from a node to another. Does not work with directories.

func (*SSHCommunicator) Log

func (sshComm *SSHCommunicator) Log(msg ...string)

Log is an helper method that allow to print logs

func (*SSHCommunicator) RunCmd

func (sshComm *SSHCommunicator) RunCmd(node Node, command string) (output string, err error)

RunCmd runs a bash command on the given node

func (*SSHCommunicator) TransformFileOverNode

func (sshComm *SSHCommunicator) TransformFileOverNode(sourceNode Node, targetNode Node, filePath string, manipulator func(string) string) error

TransformFileOverNode works like CopyFileOverNode, with the addition of changing the file contents using a func(string) string function

func (*SSHCommunicator) WriteFile

func (sshComm *SSHCommunicator) WriteFile(node Node, filePath string, content string, permission FilePermission) error

WriteFile places a file at a given part from string. Permissions are 0644, or 0755 if executable true

type SSHKey

type SSHKey struct {
	Name           string `json:"name"`
	PrivateKeyPath string `json:"private_key_path"`
	PublicKeyPath  string `json:"public_key_path"`
}

SSHKey represents a keypair with the paths to the keys

type WgKeyPair

type WgKeyPair struct {
	Private string `json:"private"`
	Public  string `json:"public"`
}

WgKeyPair containse key pairs

func GenerateKeyPair

func GenerateKeyPair() (WgKeyPair, error)

GenerateKeyPair create a key-pair used to instantiate a wireguard connection Code is redacted from https://github.com/WireGuard/wireguard-go/blob/1c025570139f614f2083b935e2c58d5dbf199c2f/noise-helpers.go

Jump to

Keyboard shortcuts

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