os

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package os is for running commands on a remote host

Index

Constants

View Source
const (
	// BinaryPath key for the binary path for the distro engine
	BinaryPath = "BinaryPath"
	// ConfigPath key for the config directory for the distro engine
	ConfigPath = "ConfigPath"
	// JoinTokenPath key for the join token for the cluster
	JoinTokenPath = "JoinTokenPath"
	// DataDirDefaultPath key for the data directory for the distro engine
	DataDirDefaultPath = "DataDirDefaultPath"
)
View Source
const (
	// FirewallFirewalld is the firewall front end shipped by Enterprise Linux and SUSE.
	FirewallFirewalld = "firewalld"
	// FirewallUFW is the firewall front end shipped by Debian and Ubuntu.
	FirewallUFW = "ufw"
)

Variables

This section is empty.

Functions

func RegisterOSModule

func RegisterOSModule(match func(*rigos.Release) bool, builder func() any)

RegisterOSModule registers an OS support module. Modules are matched in most-recently-registered-first order, mirroring the behavior of the (now removed in rig v2) github.com/k0sproject/rig/os/registry package that this replaces.

func ResolveOSModule

func ResolveOSModule(release *rigos.Release) (func() any, bool)

ResolveOSModule returns the builder function for the first registered module whose matcher accepts release, or false if none match.

Types

type Configurer

type Configurer interface {
	// ApplySysctl loads the sysctl settings in the file at the given path into the running
	// kernel. The path is passed rather than assumed because not every OS can apply the whole
	// of /etc/sysctl.d in one command.
	ApplySysctl(Host, string) error
	// PreferredFirewall names the firewall front end this distribution ships, e.g. firewalld on
	// Enterprise Linux and ufw on Debian. It returns an empty string when the distribution has no
	// front end of its own.
	PreferredFirewall() string
	// Kind returns the general OS family identifier (e.g. "linux")
	Kind() string
	// OSKind returns the identifier for Linux hosts
	OSKind() string
	// Dir returns the directory part of a path
	Dir(string) string
	// GetDistroService returns the name of the service for the current distro.
	// common key values are, "controller" and "agent"
	GetDistroService(string) (string, error)
	// SetPath adds a key value to the paths string map.
	SetPath(string, string)
	// UpdateEnvironment updates the hosts's environment variables
	UpdateEnvironment(Host, map[string]string) error
	// Hostname resolves the short hostname
	Hostname(Host) string
	// LongHostname resolves the FQDN (long) hostname
	LongHostname(Host) string
	// InstallPackage installs packages
	InstallPackage(Host, ...string) error
	// UninstallPackage uninstalls packages
	UninstallPackage(Host, ...string) error
	// CTLLockFilePath returns a path to a lock file
	CTLLockFilePath(Host) string
	// PrivateInterface tries to find a private network interface
	PrivateInterface(Host) (string, error)
	// PrivateAddress resolves internal ip from private interface
	PrivateAddress(Host, string, string) (string, error)
}

Configurer defines the per-host operations required for managing a host. Most filesystem, service, and OS-detection operations are handled directly via the rig v2 Host interface (FS(), Sudo(), OS()) rather than through this interface -- Configurer only carries what is genuinely distro-specific.

type Host

type Host interface {
	cmd.SimpleRunner
	// Sudo returns a memoized clone of the client whose runner wraps every
	// command with the detected privilege escalation mechanism.
	Sudo() *rig.Client
	// FS returns a filesystem interface for accessing files on the host.
	FS() remotefs.FS
}

Host is the interface that Configurer methods use to interact with a remote host. It is satisfied by *rig.Client, and therefore by any type that embeds rig.ClientWithConfig (such as cluster.ZarfHost), since those methods are promoted.

type HostValidator

type HostValidator interface {
	ValidateHost(Host) error
}

HostValidator allows a Configurer to implement host-specific validation logic.

type Linux

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

Linux is a base module for various linux OS support packages

func (*Linux) ApplySysctl

func (l *Linux) ApplySysctl(h Host, _ string) error

ApplySysctl loads every sysctl file the OS reads at boot, which includes the file at path. Applying them all rather than only that file keeps a setting cargoship overrides from being re-applied at its old value by a file later in the load order, and matches what the host does on its next boot.

func (*Linux) CTLLockFilePath

func (l *Linux) CTLLockFilePath(h Host) string

CTLLockFilePath returns a path to a lock file

func (*Linux) Dir

func (l *Linux) Dir(p string) string

Dir returns the directory part of a path

func (*Linux) GetDistroService

func (l *Linux) GetDistroService(key string) (string, error)

GetDistroService returns the name of the service for the current distro. common key values are, "controller" and "agent"

func (*Linux) Hostname

func (l *Linux) Hostname(h Host) string

Hostname resolves the short hostname

func (*Linux) Kind

func (l *Linux) Kind() string

Kind returns the general OS family identifier for Linux hosts

func (*Linux) LongHostname

func (l *Linux) LongHostname(h Host) string

LongHostname resolves the FQDN (long) hostname

func (*Linux) OSKind

func (l *Linux) OSKind() string

OSKind returns the identifier for Linux hosts

func (*Linux) PreferredFirewall

func (l *Linux) PreferredFirewall() string

PreferredFirewall reports that the distribution ships no firewall front end of its own. An OS module for a distribution that ships one overrides this. The method is declared on each leaf OS module rather than on a shared base such as EnterpriseLinux, because those modules embed both their base and this one at the same depth, which would leave the promoted method ambiguous.

func (*Linux) PrivateAddress

func (l *Linux) PrivateAddress(h Host, iface, publicip string) (string, error)

PrivateAddress resolves internal ip from private interface

func (*Linux) PrivateInterface

func (l *Linux) PrivateInterface(h Host) (string, error)

PrivateInterface tries to find a private network interface

func (*Linux) SetPath

func (l *Linux) SetPath(key, value string)

SetPath adds a key value to the paths string map. TODO add ref to what the paths string map does....

func (*Linux) UpdateEnvironment

func (l *Linux) UpdateEnvironment(h Host, env map[string]string) error

UpdateEnvironment upserts the given key-value pairs into /etc/environment (replacing any existing line for the same key) and exports them into the current shell environment.

Directories

Path Synopsis
Package linux is implementing the interface github.com/colonel-byte/cargoship/types/os.Configurer for Linux based hosts
Package linux is implementing the interface github.com/colonel-byte/cargoship/types/os.Configurer for Linux based hosts
enterpriselinux
Package enterpriselinux is implementing the interface github.com/colonel-byte/cargoship/types/os.Configurer for Enterprise Linux hosts
Package enterpriselinux is implementing the interface github.com/colonel-byte/cargoship/types/os.Configurer for Enterprise Linux hosts

Jump to

Keyboard shortcuts

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