config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentRole  = "agent"
	ServerRole = "server"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolTransformer

type BoolTransformer struct{}

BoolTransformer is simple struct for mergo. ParameterDoc: none.

func (BoolTransformer) Transformer

func (b BoolTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error

A Transformer for mergo to avoid overwriting false values from node level.

type Config

type Config struct {
	// Nodepools is a map with agents and servers defined.
	// Required for at least one server node.
	// Default is not specified.
	Nodepools *NodepoolsConfig
	// Defaults is a map with default settings for agents and servers.
	// Global values for all nodes can be set here as well.
	// Default is not specified.
	Defaults *DefaultConfig
	// Network defines network configuration for cluster.
	// Default is not specified.
	Network *NetworkConfig
	// K8S defines a distribution-agnostic cluster configuration.
	// Default is not specified.
	K8S *k8sconfig.Config
}

func ParseClusterConfig added in v0.1.0

func ParseClusterConfig(cfg map[string]any) (*Config, error)

func (*Config) Nodes

func (c *Config) Nodes() ([]*NodeConfig, error)

Nodes returns the nodes for the cluster. They are merged with the defaults and nodepool config values. They are sorted by majority as well.

func (*Config) Validate

func (c *Config) Validate(nodes []*NodeConfig) error

Validate validates config globally. If checking requires different parts of the configuration it should be done here, in config package. If checking requires only one specific part of the configuration in Validate() method of that part.

func (*Config) ValidateCCM

func (c *Config) ValidateCCM(_ []*NodeConfig) error

func (*Config) ValidateK3SUpgradeController

func (c *Config) ValidateK3SUpgradeController(merged []*NodeConfig) error

func (*Config) ValidateNodes added in v0.1.0

func (c *Config) ValidateNodes(merged []*NodeConfig) error

func (*Config) WithInited

func (c *Config) WithInited() *Config

WithInited returns the parsed configuration for the cluster with all the defaults set. Nodepools and Nodes are returned sorted. This is required for the network module to work correctly when user changes order of nodepools and nodes.

type DefaultConfig

type DefaultConfig struct {
	// Global provides configuration settings that are applied to all nodes, unless overridden by specific roles.
	Global *NodeConfig

	// Servers holds configuration settings specific to server nodes, overriding Global settings where specified.
	Servers *NodeConfig

	// Agents holds configuration settings specific to agent nodes, overriding Global settings where specified.
	Agents *NodeConfig
}

func (*DefaultConfig) WithInited

func (d *DefaultConfig) WithInited() *DefaultConfig

type FirewallConfig

type FirewallConfig struct {
	// Hetzner specify firewall configuration for cloud firewall.
	Hetzner *firewall.Config
}

type NetworkConfig

type NetworkConfig struct {
	// Hetzner specifies network configuration for private networking.
	Hetzner *network.Config
}

func (*NetworkConfig) WithInited

func (n *NetworkConfig) WithInited() *NetworkConfig

type NodeConfig

type NodeConfig struct {
	// NodeID is the id of a server. It is used throughout the entire program as a key.
	// Required.
	// Default is not specified.
	NodeID string `json:"node-id" yaml:"node-id" mapstructure:"node-id"`
	// Leader specifies the leader of a multi-master cluster.
	// Required if the number of masters is more than 1.
	// Default is not specified.
	Leader bool
	// Server is the configuration of a Hetzner server.
	Server *ServerConfig
	// K3S is the configuration of a k3s cluster.
	K3s *k3s.Config
	// K8S is common configuration for nodes.
	K8S *k8sconfig.NodeConfig
	// Role specifies the role of the server (server or agent).
	// Default is computed.
	Role string `json:"-" yaml:"-" mapstructure:"-"`
}

func (*NodeConfig) GetID

func (n *NodeConfig) GetID() string

type NodepoolConfig

type NodepoolConfig struct {
	// PoolID is id of group of servers. It is used through the entire program as key for the group.
	// Required.
	// Default is not specified.
	PoolID string `json:"pool-id" yaml:"pool-id" mapstructure:"pool-id"`
	// Config is the default node configuration for the group.
	Config *NodeConfig
	// Nodes is a list of nodes inside of the group.
	Nodes []*NodeConfig
}

func (*NodepoolConfig) GetID

func (n *NodepoolConfig) GetID() string

type NodepoolsConfig

type NodepoolsConfig struct {
	// Servers is a list of NodepoolConfig objects, each representing a configuration for a pool of server nodes.
	Servers []*NodepoolConfig

	// Agents is a list of NodepoolConfig objects, each representing a configuration for a pool of agent nodes.
	Agents []*NodepoolConfig
}

func (*NodepoolsConfig) SpecifyLeader

func (no *NodepoolsConfig) SpecifyLeader()

func (*NodepoolsConfig) WithInited

func (no *NodepoolsConfig) WithInited() *NodepoolsConfig

type ServerConfig

type ServerConfig struct {
	// ServerType specifies the type of server to be provisioned (e.g., "cx11", "cx21").
	// Default is cx21.
	ServerType string `json:"server-type" yaml:"server-type" mapstructure:"server-type"`

	// Hostname is the desired hostname to assign to the server.
	// Default is `phkh-${name-of-stack}-${name-of-cluster}-${id-of-node}`.
	Hostname string

	// Firewall points to an optional configuration for a firewall to be associated with the server.
	Firewall *FirewallConfig

	// Location specifies the physical location or data center where the server will be hosted (e.g., "fsn1").
	// Default is hel1.
	Location string

	// AdditionalSSHKeys contains a list of additional public SSH keys to install in the server's user account.
	AdditionalSSHKeys []string `json:"additional-ssh-keys" yaml:"additional-ssh-keys" mapstructure:"additional-ssh-keys"`

	// UserName is the primary user account name that will be created on the server.
	// Default is rancher.
	UserName string `json:"user-name" yaml:"user-name" mapstructure:"user-name"`

	// UserPasswd is the password for the primary user account on the server.
	UserPasswd string `json:"user-password" yaml:"user-password" mapstructure:"user-password"`

	// Image specifies the operating system image to use for the server (e.g., "ubuntu-20.04" or id of private image).
	// Default is autodiscovered.
	Image string
}

type WithID

type WithID interface {
	GetID() string
}

Jump to

Keyboard shortcuts

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