Documentation
¶
Index ¶
- Constants
- Variables
- type ConcurrencyOption
- type DrainOption
- type EvictTaintOption
- type Flags
- func (f *Flags) Add(s string)
- func (f *Flags) AddOrReplace(s string)
- func (f *Flags) AddUnlessExist(s string)
- func (f *Flags) AddWithValue(key, value string)
- func (f *Flags) Delete(s string)
- func (f Flags) Each(fn func(string, string))
- func (f Flags) Equals(b Flags) bool
- func (f Flags) Get(s string) string
- func (f Flags) GetBoolean(s string) (bool, error)
- func (f Flags) GetValue(s string) string
- func (f Flags) Include(s string) bool
- func (f Flags) Index(s string) int
- func (f *Flags) Join() string
- func (f Flags) Map() map[string]string
- func (f *Flags) Merge(b Flags)
- func (f *Flags) MergeAdd(b Flags)
- func (f *Flags) MergeOverwrite(b Flags)
- type Hooks
- type Host
- func (h *Host) AddTaint(node *Host, taint string) error
- func (h *Host) Address() string
- func (h *Host) CheckHTTPStatus(url string, expected ...int) error
- func (h *Host) CordonNode(node *Host) error
- func (h *Host) DeleteNode(node *Host) error
- func (h *Host) DrainNode(node *Host, options DrainOption) error
- func (h *Host) ExpandTokens(input string, k0sVersion *version.Version) string
- func (h *Host) FileChanged(lpath, rpath string) bool
- func (h *Host) FlagsChanged() bool
- func (h *Host) HasHooks(action, stage string) bool
- func (h *Host) InstallK0sBinary(path string) error
- func (h *Host) IsController() bool
- func (h *Host) K0sBackupCommand(targetDir string) string
- func (h *Host) K0sConfigPath() string
- func (h *Host) K0sDataDir() string
- func (h *Host) K0sInstallCommand() (string, error)
- func (h *Host) K0sInstallFlags() (Flags, error)
- func (h *Host) K0sInstallLocation() string
- func (h *Host) K0sJoinTokenPath() string
- func (h *Host) K0sResetCommand() string
- func (h *Host) K0sRestoreCommand(backupfile string) string
- func (h *Host) K0sRole() string
- func (h *Host) K0sServiceName() string
- func (h *Host) NeedCurl() bool
- func (h *Host) NeedIPTables() booldeprecated
- func (h *Host) NeedInetUtils() bool
- func (h *Host) Protocol() string
- func (h *Host) RemoveTaint(node *Host, taint string) error
- func (h *Host) ResolveConfigurer() error
- func (h *Host) RunHooks(ctx context.Context, action, stage string) error
- func (h *Host) SetDefaults()
- func (h *Host) Taints(node *Host) ([]string, error)
- func (h *Host) UncordonNode(node *Host) error
- func (h *Host) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (h *Host) UpdateK0sBinary(path string, version *version.Version) error
- func (h *Host) Validate() error
- type HostMetadata
- type Hosts
- func (hosts Hosts) BatchedParallelEach(ctx context.Context, batchSize int, ...) error
- func (hosts Hosts) Controllers() Hosts
- func (hosts Hosts) Each(ctx context.Context, filters ...func(context.Context, *Host) error) error
- func (hosts Hosts) Filter(filter func(h *Host) bool) Hosts
- func (hosts Hosts) Find(filter func(h *Host) bool) *Host
- func (hosts Hosts) First() *Host
- func (hosts Hosts) Last() *Host
- func (hosts Hosts) ParallelEach(ctx context.Context, filters ...func(context.Context, *Host) error) error
- func (hosts Hosts) Validate() error
- func (hosts Hosts) WithRole(s string) Hosts
- func (hosts Hosts) Workers() Hosts
- type K0s
- func (k *K0s) GenerateToken(ctx context.Context, h *Host, role string, expiry time.Duration) (string, error)
- func (k *K0s) GetClusterID(h *Host) (string, error)
- func (k *K0s) MarshalYAML() (interface{}, error)
- func (k *K0s) NodeConfig() dig.Mapping
- func (k *K0s) SetDefaults()
- func (k *K0s) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (k *K0s) Validate() error
- type K0sMetadata
- type LocalFile
- type Options
- type Spec
- func (s *Spec) APIPort() int
- func (s *Spec) InternalKubeAPIURL() string
- func (s *Spec) K0sLeader() *Host
- func (s *Spec) KubeAPIURL() string
- func (s *Spec) MarshalYAML() (interface{}, error)
- func (s *Spec) NodeInternalKubeAPIURL(h *Host) string
- func (s *Spec) SetDefaults()
- func (s *Spec) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (s *Spec) Validate() error
- type TokenData
- type UploadFile
- type WaitOption
Constants ¶
const K0sMinVersion = "0.11.0-rc1"
K0sMinVersion is the minimum supported k0s version
Variables ¶
var K0sForceFlagSince = version.MustParse("v1.27.4+k0s.0")
Functions ¶
This section is empty.
Types ¶
type ConcurrencyOption ¶ added in v0.24.0
type ConcurrencyOption struct {
Limit int `yaml:"limit" default:"30"` // Max number of hosts to operate on at once
WorkerDisruptionPercent int `yaml:"workerDisruptionPercent" default:"10"` // Max percentage of hosts to disrupt at once
Uploads int `yaml:"uploads" default:"5"` // Max concurrent file uploads
}
ConcurrencyOption controls how many hosts are operated on at once.
func (*ConcurrencyOption) UnmarshalYAML ¶ added in v0.24.0
func (c *ConcurrencyOption) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface for ConcurrencyOption.
type DrainOption ¶ added in v0.24.0
type DrainOption struct {
Enabled bool `yaml:"enabled" default:"true"`
GracePeriod time.Duration `yaml:"gracePeriod" default:"120s"`
Timeout time.Duration `yaml:"timeout" default:"300s"`
Force bool `yaml:"force" default:"true"`
IgnoreDaemonSets bool `yaml:"ignoreDaemonSets" default:"true"`
DeleteEmptyDirData bool `yaml:"deleteEmptyDirData" default:"true"`
PodSelector string `yaml:"podSelector" default:""`
SkipWaitForDeleteTimeout time.Duration `yaml:"skipWaitForDeleteTimeout" default:"0s"`
}
DrainOption controls the drain behavior for cluster operations.
func (*DrainOption) ToKubectlArgs ¶ added in v0.24.0
func (d *DrainOption) ToKubectlArgs() string
ToKubectlArgs converts the DrainOption to kubectl arguments.
func (*DrainOption) UnmarshalYAML ¶ added in v0.25.0
func (d *DrainOption) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface for DrainOption.
type EvictTaintOption ¶ added in v0.24.0
type EvictTaintOption struct {
Enabled bool `yaml:"enabled" default:"false"`
Taint string `yaml:"taint" default:"k0sctl.k0sproject.io/evict=true"`
Effect string `yaml:"effect" default:"NoExecute"`
ControllerWorkers bool `yaml:"controllerWorkers" default:"false"`
}
EvictTaintOption controls whether and how a taint is applied to nodes before service-affecting operations like upgrade or reset.
func (*EvictTaintOption) String ¶ added in v0.24.0
func (e *EvictTaintOption) String() string
String returns a string representation of the EvictTaintOption (<taint>:<effect>)
func (*EvictTaintOption) UnmarshalYAML ¶ added in v0.24.0
func (e *EvictTaintOption) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface for EvictTaintOption.
func (*EvictTaintOption) Validate ¶ added in v0.24.0
func (e *EvictTaintOption) Validate() error
Validate checks if the EvictTaintOption is valid.
type Flags ¶
type Flags []string
Flags is a slice of strings with added functions to ease manipulating lists of command-line flags
func NewFlags ¶ added in v0.19.5
NewFlags shell-splits and parses a string and returns new Flags or an error if splitting fails
func (*Flags) AddOrReplace ¶
AddOrReplace replaces a flag with the same prefix or adds a new one if one does not exist
func (*Flags) AddUnlessExist ¶
AddUnlessExist adds a flag unless one with the same prefix exists
func (*Flags) AddWithValue ¶ added in v0.13.0
Add a flag with a value
func (Flags) Each ¶ added in v0.19.3
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
Equals compares the flags with another Flags and returns true if they have the same flags and values, ignoring order
func (Flags) Get ¶
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
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 ¶
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) Map ¶ added in v0.19.3
Map returns a map[string]string of the flags where the key is the flag and the value is the value
func (*Flags) Merge ¶
Merge takes the flags from another Flags and adds them to this one unless this already has that flag set
func (*Flags) MergeAdd ¶
MergeAdd takes the flags from another Flags and adds them into this one even if they exist
func (*Flags) MergeOverwrite ¶
MergeOverwrite takes the flags from another Flags and adds or replaces them into this one
type Hooks ¶
Hooks define a list of hooks such as hooks["apply"]["before"] = ["ls -al", "rm foo.txt"]
func (Hooks) ForActionAndStage ¶
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"`
KubeletRootDir string `yaml:"kubeletRootDir,omitempty"`
Environment map[string]string `yaml:"environment,flow,omitempty"`
UploadBinary bool `yaml:"uploadBinary,omitempty"`
K0sBinaryPath string `yaml:"k0sBinaryPath,omitempty"`
K0sInstallPath string `yaml:"k0sInstallPath,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) CheckHTTPStatus ¶
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
CordonNode marks the node unschedulable
func (*Host) DeleteNode ¶ added in v0.15.0
DeleteNode deletes the given node from kubernetes
func (*Host) DrainNode ¶
func (h *Host) DrainNode(node *Host, options DrainOption) error
DrainNode drains the given node
func (*Host) ExpandTokens ¶ added in v0.17.6
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
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
FlagsChanged returns true when the flags have changed by comparing the host.Metadata.K0sStatusArgs to what host.InstallFlags would produce
func (*Host) HasHooks ¶ added in v0.26.0
HasHooks returns true when the host has hooks defined for the action and stage.
func (*Host) InstallK0sBinary ¶ added in v0.15.1
InstallK0sBinary installs the k0s binary from the provided file path to K0sBinaryPath
func (*Host) IsController ¶
IsController returns true for controller and controller+worker roles
func (*Host) K0sBackupCommand ¶
K0sBackupCommand returns a full command to be used as run k0s backup
func (*Host) K0sConfigPath ¶
K0sConfigPath returns the config file path from install flags or configurer
func (*Host) K0sDataDir ¶ added in v0.15.5
K0sDataDir returns the data dir for the host either from host.DataDir or the default from configurer's DataDirDefaultPath
func (*Host) K0sInstallCommand ¶
K0sInstallCommand returns a full command that will install k0s service with necessary flags
func (*Host) K0sInstallFlags ¶ added in v0.19.3
func (*Host) K0sInstallLocation ¶ added in v0.26.0
K0sInstallLocation returns the k0s binary path from the K0sInstallPath field or configurer.K0sBinaryPath()
func (*Host) K0sJoinTokenPath ¶
K0sJoinTokenPath returns the token file path from install flags or configurer
func (*Host) K0sResetCommand ¶ added in v0.25.0
K0sResetCommand returns a full command that will reset k0s
func (*Host) K0sRestoreCommand ¶
K0sRestoreCommand returns a full command to restore cluster state from a backup
func (*Host) K0sServiceName ¶
K0sServiceName returns correct service name
func (*Host) NeedIPTables
deprecated
func (*Host) NeedInetUtils ¶
NeedInetUtils returns true when the inetutils package is needed on the host to run `hostname`.
func (*Host) RemoveTaint ¶ added in v0.24.0
RemoveTaint removes a taint from the node.
func (*Host) ResolveConfigurer ¶
ResolveConfigurer assigns a rig-style configurer to the Host (see configurer/)
func (*Host) RunHooks ¶ added in v0.26.0
RunHooks runs the hooks for the given action and stage (such as "apply", "before" would run the "before apply" hooks). It respects context cancellation between hook executions.
func (*Host) SetDefaults ¶
func (h *Host) SetDefaults()
func (*Host) UncordonNode ¶
UncordonNode marks the node schedulable
func (*Host) UnmarshalYAML ¶
UnmarshalYAML sets in some sane defaults when unmarshaling the data from yaml
func (*Host) UpdateK0sBinary ¶
UpdateK0sBinary updates the binary on the host from the provided file path
type HostMetadata ¶
type HostMetadata struct {
K0sBinaryVersion *version.Version
K0sBinaryTempFile string
K0sRunningVersion *version.Version
K0sInstalled bool
K0sExistingConfig string
K0sNewConfig string
K0sTokenData TokenData
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(ctx context.Context, batchSize int, filter ...func(context.Context, *Host) error) error
BatchedParallelEach runs a function (or multiple functions chained) on every Host parallelly in groups of batchSize hosts.
func (Hosts) Controllers ¶
Controllers returns hosts with the role "controller"
func (Hosts) Each ¶ added in v0.17.0
Each runs a function (or multiple functions chained) on every Host.
func (Hosts) Filter ¶
Filter returns a filtered list of Hosts. The filter function should return true for hosts matching the criteria.
func (Hosts) Find ¶
Find returns the first matching Host. The finder function should return true for a Host matching the criteria.
func (Hosts) ParallelEach ¶
func (hosts Hosts) ParallelEach(ctx context.Context, filters ...func(context.Context, *Host) error) error
ParallelEach runs a function (or multiple functions chained) on every Host parallelly. Any errors will be concatenated and returned.
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(ctx context.Context, h *Host, role string, expiry time.Duration) (string, error)
GenerateToken runs the k0s token create command
func (*K0s) GetClusterID ¶
GetClusterID uses kubectl to fetch the kube-system namespace uid
func (*K0s) MarshalYAML ¶ added in v0.17.6
MarshalYAML implements yaml.Marshaler interface
func (*K0s) NodeConfig ¶ added in v0.13.0
func (*K0s) UnmarshalYAML ¶
UnmarshalYAML sets in some sane defaults when unmarshaling the data from yaml
type K0sMetadata ¶
K0sMetadata contains gathered information about k0s cluster
type Options ¶ added in v0.24.0
type Options struct {
Wait WaitOption `yaml:"wait"`
Drain DrainOption `yaml:"drain"`
Concurrency ConcurrencyOption `yaml:"concurrency"`
EvictTaint EvictTaintOption `yaml:"evictTaint"`
}
Options for cluster operations.
func (*Options) UnmarshalYAML ¶ added in v0.25.0
UnmarshalYAML implements the yaml.Unmarshaler interface for Options.
type Spec ¶
type Spec struct {
Hosts Hosts `yaml:"hosts,omitempty"`
K0s *K0s `yaml:"k0s,omitempty"`
Options Options `yaml:"options"`
// contains filtered or unexported fields
}
Spec defines cluster config spec section
func (*Spec) InternalKubeAPIURL ¶ added in v0.19.1
InternalKubeAPIURL returns a cluster internal url to the cluster's kube API
func (*Spec) K0sLeader ¶
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 ¶
KubeAPIURL returns an external url to the cluster's kube API
func (*Spec) MarshalYAML ¶ added in v0.17.6
MarshalYAML overrides default YAML marshaling to get rid of "k0s: null" when nothing is set in spec.k0s
func (*Spec) NodeInternalKubeAPIURL ¶ added in v0.19.1
NodeInternalKubeAPIURL returns a cluster internal url to the node's kube API
func (*Spec) UnmarshalYAML ¶
UnmarshalYAML sets in some sane defaults when unmarshaling the data from yaml
type TokenData ¶ added in v0.19.5
TokenData is data collected from a decoded k0s token
func ParseToken ¶ added in v0.19.5
ParseToken returns TokenData for a token string
type UploadFile ¶
type UploadFile struct {
Name string `yaml:"name,omitempty"`
Source string `yaml:"src,omitempty"`
Data string `yaml:"data,omitempty"`
DestinationDir string `yaml:"dstDir,omitempty"`
DestinationFile string `yaml:"dst,omitempty"`
PermMode interface{} `yaml:"perm,omitempty"`
DirPermMode interface{} `yaml:"dirPerm,omitempty"`
User string `yaml:"user,omitempty"`
Group string `yaml:"group,omitempty"`
PermString string `yaml:"-"`
DirPermString string `yaml:"-"`
Sources []*LocalFile `yaml:"-"`
Base string `yaml:"-"`
}
UploadFile describes a file to be uploaded for the host
func (*UploadFile) HasData ¶ added in v0.27.0
func (u *UploadFile) HasData() bool
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
type WaitOption ¶ added in v0.24.0
type WaitOption struct {
Enabled bool `yaml:"enabled" default:"true"`
}
WaitOption controls the wait behavior for cluster operations.