engine

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InstallerURL = "https://get.k3s.io"
)
View Source
const (
	// Program is used to configure the name of the configuration file.
	Program = "k3se"
)

Variables

View Source
var (
	// Channels is a list of the available release channels.
	Channels = []string{"stable", "latest", "testing"}
)

Functions

This section is empty.

Types

type Agent added in v1.0.0

type Agent struct {
	Debug                         bool     `yaml:"debug,omitempty"`
	V                             int      `yaml:"v,omitempty"`
	VModule                       string   `yaml:"vmodule,omitempty"`
	Log                           string   `yaml:"log,omitempty"`
	AlsoLogToStderr               bool     `yaml:"also-log-to-stderr,omitempty"`
	Server                        string   `yaml:"server,omitempty"`
	DataDir                       string   `yaml:"data-dir,omitempty"`
	NodeName                      string   `yaml:"node-name,omitempty"`
	WithNodeID                    bool     `yaml:"with-node-id,omitempty"`
	NodeLabel                     []string `yaml:"node-label,omitempty"`
	NodeTaint                     []string `yaml:"node-taint,omitempty"`
	ImageCredentialProviderBinDir string   `yaml:"image-credential-provider-bin-dir,omitempty"`
	ImageCredentialProviderConfig string   `yaml:"image-credential-provider-config,omitempty"`
	Docker                        bool     `yaml:"docker,omitempty"`
	ContainerRuntimeEndpoint      string   `yaml:"container-runtime-endpoint,omitempty"`
	PauseImage                    string   `yaml:"pause-image,omitempty"`
	Snapshotter                   string   `yaml:"snapshotter,omitempty"`
	PrivateRegistry               string   `yaml:"private-registry,omitempty"`
	NodeIP                        []string `yaml:"node-ip,omitempty"`
	NodeExternalIP                []string `yaml:"node-external-ip,omitempty"`
	ResolvConf                    string   `yaml:"resolv-conf,omitempty"`
	FlannelIface                  string   `yaml:"flannel-iface,omitempty"`
	FlannelConf                   string   `yaml:"flannel-conf,omitempty"`
	KubeletArg                    []string `yaml:"kubelet-arg,omitempty"`
	KubeProxyArg                  []string `yaml:"kube-proxy-arg,omitempty"`
	ProtectKernelDefaults         bool     `yaml:"protect-kernel-defaults,omitempty"`
	Rootless                      bool     `yaml:"rootless,omitempty"`
	LBServerPort                  int      `yaml:"lb-server-port,omitempty"`
}

Agent describes the configuration of a k3s agent. For more information, please refer to the k3s documentation: https://rancher.com/docs/k3s/latest/en/installation/install-options/agent-config/#k3s-agent-cli-help

type Cluster added in v1.0.0

type Cluster struct {
	Server Server `yaml:"server,omitempty"`
	Agent  Agent  `yaml:"agent,omitempty"`
}

Cluster defines share settings across all servers and agents.

type Config

type Config struct {
	// Version is the version of k3s to use. It may also be a
	// channel as specified in the k3s installation options.
	Version string `yaml:"version"`

	// Cluster defines shared configuration settings across all
	// servers and agents.
	Cluster Cluster `yaml:"cluster"`

	// Nodes is a list of nodes to deploy the cluster on. It stores
	// both, connection information and node-specific configuration.
	Nodes []Node `yaml:"nodes"`

	// SSHProxy describes the SSH connection configuration
	// for an SSH proxy, often also referred to as bastion
	// host or jumpbox.
	SSHProxy sshx.Config `yaml:"ssh-proxy"`
}

Config describes the state of a k3s cluster. For general reference, please refer to the k3s installation options: https://rancher.com/docs/k3s/latest/en/installation/install-options

func LoadConfig

func LoadConfig(configFile string) (*Config, error)

LoadConfig sets up the configuration parser and loads the configuration file.

func (*Config) Verify

func (c *Config) Verify() error

Verify verifies the configuration file. TODO: How do we pass a logger to this function? TODO: Use logger to display configuration errors.

type Engine added in v0.2.0

type Engine struct {
	Logger *zerolog.Logger

	sync.Mutex

	Spec *Config
	// contains filtered or unexported fields
}

Engine is a type that encapsulates parts of the installation logic.

func New added in v0.2.0

func New(options ...Option) (*Engine, error)

New creates a new Engine.

func (*Engine) ConfigureNode added in v0.3.0

func (e *Engine) ConfigureNode(node *Node) error

ConfigureNode uploads the installer and the configuration to a node prior to running the installation script.

func (*Engine) Connect added in v0.3.0

func (e *Engine) Connect() error

Connect establishes an SSH connection to all nodes.

func (*Engine) Disconnect added in v0.3.0

func (e *Engine) Disconnect() error

Disconnect closes all SSH connections to all nodes.

func (*Engine) FilterNodes added in v0.3.0

func (e *Engine) FilterNodes(selector Role) []*Node

FilterNodes returns a list of nodes based on the specified selector. Use RoleAny to match all nodes, RoleAgent to match all worker nodes, and RoleServer to match all control-plane nodes.

func (*Engine) Install added in v0.2.6

func (e *Engine) Install() error

Install runs the installation script on the node.

func (*Engine) KubeConfig added in v0.3.5

func (e *Engine) KubeConfig(outputPath string) error

KubeConfig writes the kubeconfig of the cluster to the specified location.

func (*Engine) SetSpec added in v0.2.4

func (e *Engine) SetSpec(config *Config) error

SetSpec configures the desired state of the cluster. Note that the config will only be applied if the verification succeeds.

func (*Engine) Uninstall added in v0.3.0

func (e *Engine) Uninstall() error

Uninstall runs the uninstallation script on all nodes.

type Node

type Node struct {
	Role   Role        `yaml:"role"`
	SSH    sshx.Config `yaml:"ssh"`
	Server Server      `yaml:"server,omitempty"`
	Agent  Agent       `yaml:"agent,omitempty"`

	Client *sshx.Client   `yaml:"-"`
	Logger zerolog.Logger `yaml:"-"`
}

Node describes the configuration of a node.

func (*Node) Connect

func (node *Node) Connect(options ...Option) error

Connect establishes a connection to the node.

func (*Node) Disconnect

func (node *Node) Disconnect() error

Disconnect closes the connection to the node.

func (*Node) Do added in v0.2.3

func (node *Node) Do(cmd sshx.Cmd) error

Do executes a command on the node.

func (*Node) Upload added in v0.2.0

func (node *Node) Upload(dst string, src io.Reader) error

Upload writes the specified content to the remote file on the node.

func (*Node) Write added in v0.3.0

func (node *Node) Write(raw []byte) (int, error)

Write writes a log information for the node. TODO: Make this more efficient by reducing allocations.

type Option

type Option func(options *Options) error

Option applies a configuration option for the execution of an operation.

func WithLogger

func WithLogger(logger *zerolog.Logger) Option

WithLogger allows to use a custom logger.

func WithSSHProxy

func WithSSHProxy(proxy *sshx.Client) Option

WithSSHProxy allows to use an existing SSH connection as an SSH bastion host.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout allows to set a custom timeout.

type Options

type Options struct {
	Logger   *zerolog.Logger
	SSHProxy *sshx.Client
	Timeout  time.Duration
}

Options contains the configuration for an operation.

func GetDefaultOptions

func GetDefaultOptions() *Options

GetDefaultOptions returns the default options for all operations of this library.

func (*Options) Apply

func (o *Options) Apply(options ...Option) (*Options, error)

Apply applies the option functions to the current set of options.

type Role

type Role string

Role is the type of a node in the cluster.

const (
	// RoleAny is the role selector that matches any node.
	RoleAny Role = "any"
	// RoleServer is the role of a control-plane node in k3s.
	RoleServer Role = "server"
	// RoleAgent is the role of a worker node in k3s.
	RoleAgent Role = "agent"
)

type Server added in v1.0.0

type Server struct {
	V                             int      `yaml:"v,omitempty"`
	VModule                       string   `yaml:"vmodule,omitempty"`
	Log                           string   `yaml:"log,omitempty"`
	AlsoLogToStderr               bool     `yaml:"also-log-to-stderr,omitempty"`
	BindAddress                   string   `yaml:"bind-address,omitempty"`
	HTTPSListenPort               int      `yaml:"https-listen-port,omitempty"`
	AdvertiseAddress              string   `yaml:"advertise-address,omitempty"`
	AdvertisePort                 int      `yaml:"advertise-port,omitempty"`
	TLSSAN                        []string `yaml:"tls-san,omitempty"`
	DataDir                       string   `yaml:"data-dir,omitempty"`
	ClusterCIDR                   []string `yaml:"cluster-cidr,omitempty"`
	ServiceCIDR                   []string `yaml:"service-cidr,omitempty"`
	ServiceNodePortRange          string   `yaml:"service-node-port-range,omitempty"`
	ClusterDNS                    []string `yaml:"cluster-dns,omitempty"`
	ClusterDomain                 string   `yaml:"cluster-domain,omitempty"`
	FlannelBackend                string   `yaml:"flannel-backend,omitempty"`
	WriteKubeconfig               string   `yaml:"write-kubeconfig,omitempty"`
	WriteKubeconfigMode           string   `yaml:"write-kubeconfig-mode,omitempty"`
	EtcdArg                       []string `yaml:"etcd-arg,omitempty"`
	KubeAPIServerArg              []string `yaml:"kube-apiserver-arg,omitempty"`
	KubeSchedulerArg              []string `yaml:"kube-scheduler-arg,omitempty"`
	KubeControllerManagerArg      []string `yaml:"kube-controller-manager-arg,omitempty"`
	KubeCloudControllerManagerArg []string `yaml:"kube-cloud-controller-manager-arg,omitempty"`
	DatastoreEndpoint             string   `yaml:"datastore-endpoint,omitempty"`
	DatastoreCAFile               string   `yaml:"datastore-cafile,omitempty"`
	DatastoreCertFile             string   `yaml:"datastore-certfile,omitempty"`
	DatastoreKeyFile              string   `yaml:"datastore-keyfile,omitempty"`
	EtcdExposeMetrics             bool     `yaml:"etcd-expose-metrics,omitempty"`
	EtcdDisableSnapshots          bool     `yaml:"etcd-disable-snapshots,omitempty"`
	EtcdSnapshotName              string   `yaml:"etcd-snapshot-name,omitempty"`
	EtcdSnapshotScheduleCron      string   `yaml:"etcd-snapshot-schedule-cron,omitempty"`
	EtcdSnapshotRetention         int      `yaml:"etcd-snapshot-retention,omitempty"`
	EtcdSnapshotDir               string   `yaml:"etcd-snapshot-dir,omitempty"`
	EtcdS3                        bool     `yaml:"etcd-s3,omitempty"`
	EtcdS3Endpoint                string   `yaml:"etcd-s3-endpoint,omitempty"`
	EtcdS3EndpointCA              string   `yaml:"etcd-s3-endpoint-ca,omitempty"`
	EtcdS3SkipSSLVerify           bool     `yaml:"etcd-s3-skip-ssl-verify,omitempty"`
	EtcdS3AccessKey               string   `yaml:"etcd-s3-access-key,omitempty"`
	EtcdS3SecretKey               string   `yaml:"etcd-s3-secret-key,omitempty"`
	EtcdS3Bucket                  string   `yaml:"etcd-s3-bucket,omitempty"`
	EtcdS3Region                  string   `yaml:"etcd-s3-region,omitempty"`
	EtcdS3Folder                  string   `yaml:"etcd-s3-folder,omitempty"`
	DefaultLocalStoragePath       string   `yaml:"default-local-storage-path,omitempty"`
	Disable                       []string `yaml:"disable,omitempty"`
	DisableScheduler              bool     `yaml:"disable-scheduler,omitempty"`
	DisableCloudController        bool     `yaml:"disable-cloud-controller,omitempty"`
	DisableKubeProxy              bool     `yaml:"disable-kube-proxy,omitempty"`
	DisableNetworkPolicy          bool     `yaml:"disable-network-policy,omitempty"`
	NodeName                      string   `yaml:"node-name,omitempty"`
	WithNodeID                    bool     `yaml:"with-node-id,omitempty"`
	NodeLabel                     []string `yaml:"node-label,omitempty"`
	NodeTaint                     []string `yaml:"node-taint,omitempty"`
	ImageCredentialProviderBinDir string   `yaml:"image-credential-provider-bin-dir,omitempty"`
	ImageCredentialProviderConfig string   `yaml:"image-credential-provider-config,omitempty"`
	Docker                        string   `yaml:"docker,omitempty"`
	ContainerRuntimeEndpoint      string   `yaml:"container-runtime-endpoint,omitempty"`
	PauseImage                    string   `yaml:"pause-image,omitempty"`
	Snapshotter                   string   `yaml:"snapshotter,omitempty"`
	PrivateRegistry               string   `yaml:"private-registry,omitempty"`
	NodeIP                        []string `yaml:"node-ip,omitempty"`
	NodeExternalIP                []string `yaml:"node-external-ip,omitempty"`
	ResolvConf                    string   `yaml:"resolv-conf,omitempty"`
	FlannelIface                  string   `yaml:"flannel-iface,omitempty"`
	FlannelConf                   string   `yaml:"flannel-conf,omitempty"`
	KubeletArg                    []string `yaml:"kubelet-arg,omitempty"`
	KubeProxyArg                  []string `yaml:"kube-proxy-arg,omitempty"`
	ProtectKernelDefaults         bool     `yaml:"protect-kernel-defaults,omitempty"`
	Rootless                      bool     `yaml:"rootless,omitempty"`
	Server                        string   `yaml:"server,omitempty"`
	// Options to manage the clustering, such as "--cluster-init", are omitted as this
	// is handled automatically by the engine.
	ClusterResetRestorePath bool   `yaml:"cluster-reset-restore-path,omitempty"`
	SecretsEncryption       bool   `yaml:"secrets-encryption,omitempty"`
	SystemDefaultRegistry   string `yaml:"system-default-registry,omitempty"`
	SELinux                 bool   `yaml:"selinux,omitempty"`
	LBServerPort            int    `yaml:"lb-server-port,omitempty"`
}

Server describes the configuration of a k3s server. For more information, please refer to the k3s documentation: https://rancher.com/docs/k3s/latest/en/installation/install-options/server-config/#k3s-server-cli-help

Jump to

Keyboard shortcuts

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