cluster

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 28 Imported by: 5

Documentation

Index

Constants

View Source
const K0sMinVersion = "0.11.0-rc1"

K0sMinVersion is the minimum supported k0s version

Variables

View Source
var K0sForceFlagSince = version.MustConstraint(">= v1.27.4+k0s.0")

Functions

func TokenID

func TokenID(s string) (string, error)

TokenID returns a token id from a token string that can be used to invalidate the token

Types

type Flags

type Flags []string

Flags is a slice of strings with added functions to ease manipulating lists of command-line flags

func (*Flags) Add

func (f *Flags) Add(s string)

Add adds a flag regardless if it exists already or not

func (*Flags) AddOrReplace

func (f *Flags) AddOrReplace(s string)

AddOrReplace replaces a flag with the same prefix or adds a new one if one does not exist

func (*Flags) AddUnlessExist

func (f *Flags) AddUnlessExist(s string)

AddUnlessExist adds a flag unless one with the same prefix exists

func (*Flags) AddWithValue added in v0.13.0

func (f *Flags) AddWithValue(key, value string)

Add a flag with a value

func (*Flags) Delete

func (f *Flags) Delete(s string)

Delete removes a matching flag from the list

func (Flags) Each added in v0.19.3

func (f Flags) Each(fn func(string, string))

Each iterates over each flag and calls the function with the flag key and value as arguments

func (Flags) Equals added in v0.19.3

func (f Flags) Equals(b Flags) bool

Equals compares the flags with another Flags and returns true if they have the same flags and values, ignoring order

func (Flags) Get

func (f Flags) Get(s string) string

Get returns the full flag with the possible value such as "--san=10.0.0.1" or "" when not found

func (Flags) GetBoolean added in v0.15.0

func (f Flags) GetBoolean(s string) (bool, error)

GetValue returns the boolean value part of a flag such as true for a flag like "--san" If the flag is not defined returns false. If the flag is defined without a value, returns true If no value is set, returns true

func (Flags) GetValue

func (f Flags) GetValue(s string) string

GetValue returns the value part of a flag such as "10.0.0.1" for a flag like "--san=10.0.0.1"

func (Flags) Include

func (f Flags) Include(s string) bool

Include returns true if a flag with a matching prefix can be found

func (Flags) Index

func (f Flags) Index(s string) int

Index returns an index to a flag with a matching prefix

func (*Flags) Join

func (f *Flags) Join() string

Join creates a string separated by spaces

func (Flags) Map added in v0.19.3

func (f Flags) Map() map[string]string

Map returns a map[string]string of the flags where the key is the flag and the value is the value

func (*Flags) Merge

func (f *Flags) Merge(b Flags)

Merge takes the flags from another Flags and adds them to this one unless this already has that flag set

func (*Flags) MergeAdd

func (f *Flags) MergeAdd(b Flags)

MergeAdd takes the flags from another Flags and adds them into this one even if they exist

func (*Flags) MergeOverwrite

func (f *Flags) MergeOverwrite(b Flags)

MergeOverwrite takes the flags from another Flags and adds or replaces them into this one

type Hooks

type Hooks map[string]map[string][]string

Hooks define a list of hooks such as hooks["apply"]["before"] = ["ls -al", "rm foo.txt"]

func (Hooks) ForActionAndStage

func (h Hooks) ForActionAndStage(action, stage string) []string

ForActionAndStage return hooks for given action and stage

type Host

type Host struct {
	rig.Connection `yaml:",inline"`

	Role             string            `yaml:"role"`
	Reset            bool              `yaml:"reset,omitempty"`
	PrivateInterface string            `yaml:"privateInterface,omitempty"`
	PrivateAddress   string            `yaml:"privateAddress,omitempty"`
	DataDir          string            `yaml:"dataDir,omitempty"`
	Environment      map[string]string `yaml:"environment,flow,omitempty"`
	UploadBinary     bool              `yaml:"uploadBinary,omitempty"`
	K0sBinaryPath    string            `yaml:"k0sBinaryPath,omitempty"`
	K0sDownloadURL   string            `yaml:"k0sDownloadURL,omitempty"`
	InstallFlags     Flags             `yaml:"installFlags,omitempty"`
	Files            []*UploadFile     `yaml:"files,omitempty"`
	OSIDOverride     string            `yaml:"os,omitempty"`
	HostnameOverride string            `yaml:"hostname,omitempty"`
	NoTaints         bool              `yaml:"noTaints,omitempty"`
	Hooks            Hooks             `yaml:"hooks,omitempty"`

	UploadBinaryPath string       `yaml:"-"`
	Metadata         HostMetadata `yaml:"-"`
	Configurer       configurer   `yaml:"-"`
}

Host contains all the needed details to work with hosts

func (*Host) Address

func (h *Host) Address() string

Address returns an address for the host

func (*Host) CheckHTTPStatus

func (h *Host) CheckHTTPStatus(url string, expected ...int) error

CheckHTTPStatus will perform a web request to the url and return an error if the http status is not the expected

func (*Host) CordonNode added in v0.17.0

func (h *Host) CordonNode(node *Host) error

CordonNode marks the node unschedulable

func (*Host) DeleteNode added in v0.15.0

func (h *Host) DeleteNode(node *Host) error

DeleteNode deletes the given node from kubernetes

func (*Host) DrainNode

func (h *Host) DrainNode(node *Host) error

DrainNode drains the given node

func (*Host) ExpandTokens added in v0.17.6

func (h *Host) ExpandTokens(input string, k0sVersion *version.Version) string

ExpandTokens expands percent-sign prefixed tokens in a string, mainly for the download URLs. The supported tokens are:

  • %% - literal %
  • %p - host architecture (arm, arm64, amd64)
  • %v - k0s version (v1.21.0+k0s.0)
  • %x - k0s binary extension (.exe on Windows)

Any unknown token is output as-is with the leading % included.

func (*Host) FileChanged added in v0.13.0

func (h *Host) FileChanged(lpath, rpath string) bool

FileChanged returns true when a remote file has different size or mtime compared to local or if an error occurs

func (*Host) FlagsChanged added in v0.19.0

func (h *Host) FlagsChanged() bool

FlagsChanged returns true when the flags have changed by comparing the host.Metadata.K0sStatusArgs to what host.InstallFlags would produce

func (*Host) InstallK0sBinary added in v0.15.1

func (h *Host) InstallK0sBinary(path string) error

InstallK0sBinary installs the k0s binary from the provided file path to K0sBinaryPath

func (*Host) IsController

func (h *Host) IsController() bool

IsController returns true for controller and controller+worker roles

func (*Host) K0sBackupCommand

func (h *Host) K0sBackupCommand(targetDir string) string

K0sBackupCommand returns a full command to be used as run k0s backup

func (*Host) K0sConfigPath

func (h *Host) K0sConfigPath() string

K0sConfigPath returns the config file path from install flags or configurer

func (*Host) K0sDataDir added in v0.15.5

func (h *Host) K0sDataDir() string

K0sDataDir returns the data dir for the host either from host.DataDir or the default from configurer's DataDirDefaultPath

func (*Host) K0sInstallCommand

func (h *Host) K0sInstallCommand() (string, error)

K0sInstallCommand returns a full command that will install k0s service with necessary flags

func (*Host) K0sInstallFlags added in v0.19.3

func (h *Host) K0sInstallFlags() (Flags, error)

func (*Host) K0sJoinTokenPath

func (h *Host) K0sJoinTokenPath() string

K0sJoinTokenPath returns the token file path from install flags or configurer

func (*Host) K0sRestoreCommand

func (h *Host) K0sRestoreCommand(backupfile string) string

K0sRestoreCommand returns a full command to restore cluster state from a backup

func (*Host) K0sRole added in v0.19.3

func (h *Host) K0sRole() string

func (*Host) K0sServiceName

func (h *Host) K0sServiceName() string

K0sServiceName returns correct service name

func (*Host) NeedCurl

func (h *Host) NeedCurl() bool

NeedCurl returns true when the curl package is needed on the host

func (*Host) NeedIPTables deprecated

func (h *Host) NeedIPTables() bool

NeedIPTables returns true when the iptables package is needed on the host

Deprecated: iptables is only required for k0s versions that are unsupported for a long time already (< v1.22.1+k0s.0).

func (*Host) NeedInetUtils

func (h *Host) NeedInetUtils() bool

NeedInetUtils returns true when the inetutils package is needed on the host to run `hostname`.

func (*Host) Protocol

func (h *Host) Protocol() string

Protocol returns host communication protocol

func (*Host) ResolveConfigurer

func (h *Host) ResolveConfigurer() error

ResolveConfigurer assigns a rig-style configurer to the Host (see configurer/)

func (*Host) SetDefaults

func (h *Host) SetDefaults()

func (*Host) UncordonNode

func (h *Host) UncordonNode(node *Host) error

UncordonNode marks the node schedulable

func (*Host) UnmarshalYAML

func (h *Host) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML sets in some sane defaults when unmarshaling the data from yaml

func (*Host) UpdateK0sBinary

func (h *Host) UpdateK0sBinary(path string, version *version.Version) error

UpdateK0sBinary updates the binary on the host from the provided file path

func (*Host) Validate

func (h *Host) Validate() error

type HostMetadata

type HostMetadata struct {
	K0sBinaryVersion  *version.Version
	K0sBinaryTempFile string
	K0sRunningVersion *version.Version
	K0sInstalled      bool
	K0sExistingConfig string
	K0sNewConfig      string
	K0sJoinToken      string
	K0sJoinTokenID    string
	K0sStatusArgs     Flags
	Arch              string
	IsK0sLeader       bool
	Hostname          string
	Ready             bool
	NeedsUpgrade      bool
	MachineID         string
	DryRunFakeLeader  bool
}

HostMetadata resolved metadata for host

type Hosts

type Hosts []*Host

Hosts are destnation hosts

func (Hosts) BatchedParallelEach added in v0.15.0

func (hosts Hosts) BatchedParallelEach(batchSize int, filter ...func(h *Host) error) error

BatchedParallelEach runs a function (or multiple functions chained) on every Host parallelly in groups of batchSize hosts.

func (Hosts) Controllers

func (hosts Hosts) Controllers() Hosts

Controllers returns hosts with the role "controller"

func (Hosts) Each added in v0.17.0

func (hosts Hosts) Each(filters ...func(h *Host) error) error

Each runs a function (or multiple functions chained) on every Host.

func (Hosts) Filter

func (hosts Hosts) Filter(filter func(h *Host) bool) Hosts

Filter returns a filtered list of Hosts. The filter function should return true for hosts matching the criteria.

func (Hosts) Find

func (hosts Hosts) Find(filter func(h *Host) bool) *Host

Find returns the first matching Host. The finder function should return true for a Host matching the criteria.

func (Hosts) First

func (hosts Hosts) First() *Host

First returns the first host

func (Hosts) Last

func (hosts Hosts) Last() *Host

Last returns the last host

func (Hosts) ParallelEach

func (hosts Hosts) ParallelEach(filters ...func(h *Host) error) error

ParallelEach runs a function (or multiple functions chained) on every Host parallelly. Any errors will be concatenated and returned.

func (Hosts) Validate

func (hosts Hosts) Validate() error

func (Hosts) WithRole

func (hosts Hosts) WithRole(s string) Hosts

WithRole returns a ltered list of Hosts that have the given role

func (Hosts) Workers

func (hosts Hosts) Workers() Hosts

Workers returns hosts with the role "worker"

type K0s

type K0s struct {
	Version        *version.Version `yaml:"version,omitempty"`
	VersionChannel string           `yaml:"versionChannel,omitempty"`
	DynamicConfig  bool             `yaml:"dynamicConfig,omitempty" default:"false"`
	Config         dig.Mapping      `yaml:"config,omitempty"`
	Metadata       K0sMetadata      `yaml:"-"`
}

K0s holds configuration for bootstraping a k0s cluster

func (*K0s) GenerateToken

func (k *K0s) GenerateToken(h *Host, role string, expiry time.Duration) (string, error)

GenerateToken runs the k0s token create command

func (*K0s) GetClusterID

func (k *K0s) GetClusterID(h *Host) (string, error)

GetClusterID uses kubectl to fetch the kube-system namespace uid

func (*K0s) MarshalYAML added in v0.17.6

func (k *K0s) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler interface

func (*K0s) NodeConfig added in v0.13.0

func (k *K0s) NodeConfig() dig.Mapping

func (*K0s) SetDefaults

func (k *K0s) SetDefaults()

SetDefaults sets default values

func (*K0s) UnmarshalYAML

func (k *K0s) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML sets in some sane defaults when unmarshaling the data from yaml

func (*K0s) Validate

func (k *K0s) Validate() error

type K0sMetadata

type K0sMetadata struct {
	ClusterID        string
	VersionDefaulted bool
}

K0sMetadata contains gathered information about k0s cluster

type LocalFile

type LocalFile struct {
	Path     string
	PermMode string
}

type Spec

type Spec struct {
	Hosts Hosts `yaml:"hosts,omitempty"`
	K0s   *K0s  `yaml:"k0s,omitempty"`
	// contains filtered or unexported fields
}

Spec defines cluster config spec section

func (*Spec) APIPort added in v0.19.1

func (s *Spec) APIPort() int

func (*Spec) InternalKubeAPIURL added in v0.19.1

func (s *Spec) InternalKubeAPIURL() string

InternalKubeAPIURL returns a cluster internal url to the cluster's kube API

func (*Spec) K0sLeader

func (s *Spec) K0sLeader() *Host

K0sLeader returns a controller host that is selected to be a "leader", or an initial node, a node that creates join tokens for other controllers.

func (*Spec) KubeAPIURL

func (s *Spec) KubeAPIURL() string

KubeAPIURL returns an external url to the cluster's kube API

func (*Spec) MarshalYAML added in v0.17.6

func (s *Spec) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler interface

func (*Spec) NodeInternalKubeAPIURL added in v0.19.1

func (s *Spec) NodeInternalKubeAPIURL(h *Host) string

NodeInternalKubeAPIURL returns a cluster internal url to the node's kube API

func (*Spec) SetDefaults added in v0.17.0

func (s *Spec) SetDefaults()

SetDefaults sets defaults

func (*Spec) UnmarshalYAML

func (s *Spec) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML sets in some sane defaults when unmarshaling the data from yaml

func (*Spec) Validate

func (s *Spec) Validate() error

type UploadFile

type UploadFile struct {
	Name            string       `yaml:"name,omitempty"`
	Source          string       `yaml:"src"`
	DestinationDir  string       `yaml:"dstDir"`
	DestinationFile string       `yaml:"dst"`
	PermMode        interface{}  `yaml:"perm"`
	DirPermMode     interface{}  `yaml:"dirPerm"`
	User            string       `yaml:"user"`
	Group           string       `yaml:"group"`
	PermString      string       `yaml:"-"`
	DirPermString   string       `yaml:"-"`
	Sources         []*LocalFile `yaml:"-"`
	Base            string       `yaml:"-"`
}

UploadFile describes a file to be uploaded for the host

func (*UploadFile) IsURL

func (u *UploadFile) IsURL() bool

IsURL returns true if the source is a URL

func (*UploadFile) Owner

func (u *UploadFile) Owner() string

Owner returns a chown compatible user:group string from User and Group, or empty when neither are set.

func (*UploadFile) String

func (u *UploadFile) String() string

String returns the file bundle name or if it is empty, the source.

func (*UploadFile) UnmarshalYAML

func (u *UploadFile) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML sets in some sane defaults when unmarshaling the data from yaml

func (UploadFile) Validate

func (u UploadFile) Validate() error

Jump to

Keyboard shortcuts

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