software

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OSLinux   string = "linux"
	OSDarwin  string = "darwin"
	OSWindows string = "windows"

	ArchAMD64 string = "amd64"
	ArchARM64 string = "arm64"
)
View Source
const (
	CrioServiceName = "crio"

	// File names - extracted as constants to avoid duplication
	CrioConfFile          = "10-crio.conf"
	CrioServiceFile       = "crio.service"
	PolicyJsonFile        = "policy.json"
	CrictlYamlFile        = "crictl.yaml"
	CrioUmountConfFile    = "crio-umount.conf"
	CrioConfDisabledFile  = "10-crio-bridge.conflist.disabled"
	CrioConf5File         = "crio.conf.5"
	CrioConfd5File        = "crio.conf.d.5"
	Crio8File             = "crio.8"
	CrioFishFile          = "crio.fish"
	RegistriesConfFile    = "registries.conf"
	CrioInstallFile       = ".crio-install"
	CrioDefaultConfigFile = "crio"

	// Directory names
	ContribDir = "contrib/"
)
View Source
const KubeletServiceName = "kubelet"

Variables

View Source
var (
	ErrorsNamespace       = errorx.NewNamespace("software")
	ConfigLoadError       = ErrorsNamespace.NewType("config_load_error")
	SoftwareNotFoundError = ErrorsNamespace.NewType("software_not_found")
	VersionNotFoundError  = ErrorsNamespace.NewType("version_not_found")
	PlatformNotFoundError = ErrorsNamespace.NewType("platform_not_found")
	DownloadError         = ErrorsNamespace.NewType("download_error")
	ChecksumError         = ErrorsNamespace.NewType("checksum_error")
	ExtractionError       = ErrorsNamespace.NewType("extraction_error")
	FileNotFoundError     = ErrorsNamespace.NewType("file_not_found")
	InstallationError     = ErrorsNamespace.NewType("installation_error")
	UninstallationError   = ErrorsNamespace.NewType("uninstallation_error")
	ConfigurationError    = ErrorsNamespace.NewType("configuration_error")
	CleanupError          = ErrorsNamespace.NewType("cleanup_error")
	FileSystemError       = ErrorsNamespace.NewType("filesystem_error")
	TemplateError         = ErrorsNamespace.NewType("template_error")
	PathTraversalError    = ErrorsNamespace.NewType("path_traversal_error")
	InvalidURLError       = ErrorsNamespace.NewType("invalid_url_error")
)
View Source
var GenerateKubeadmToken = func() (string, error) {
	const allowedChars = "abcdefghijklmnopqrstuvwxyz0123456789"
	const part1Len = 6
	const part2Len = 16
	tokenPart := func(length int) (string, error) {
		b := make([]byte, length)
		for i := range b {
			nBig, err := rand.Int(rand.Reader, big.NewInt(int64(len(allowedChars))))
			if err != nil {
				return "", fmt.Errorf("failed to generate random int for kubeadm token: %w", err)
			}
			b[i] = allowedChars[nBig.Int64()]
		}
		return string(b), nil
	}
	part1, err := tokenPart(part1Len)
	if err != nil {
		return "", err
	}
	part2, err := tokenPart(part2Len)
	if err != nil {
		return "", err
	}
	return fmt.Sprintf("%s.%s", part1, part2), nil
}

GenerateKubeadmToken generates a random kubeadm token in the format [a-z0-9]{6}.[a-z0-9]{16}

Functions

func AutoRemove

func AutoRemove() error

func GetPackageManager

func GetPackageManager() (syspkg.PackageManager, error)

func GetRegistriesConfPath

func GetRegistriesConfPath() string

GetRegistriesConfPath returns the full path to the registries.conf file in the sandbox This is used by tests to install custom registry mirror configuration

func NewChecksumError

func NewChecksumError(filePath, algorithm, expectedHash, actualHash string) *errorx.Error

func NewCleanupError

func NewCleanupError(cause error, downloadFolder string) *errorx.Error

func NewConfigLoadError

func NewConfigLoadError(cause error) *errorx.Error

func NewConfigurationError

func NewConfigurationError(cause error, softwareName string) *errorx.Error

func NewDownloadError

func NewDownloadError(cause error, url string, statusCode int) *errorx.Error

func NewExtractionError

func NewExtractionError(cause error, filePath, destPath string) *errorx.Error

func NewFileNotFoundError

func NewFileNotFoundError(filePath string) *errorx.Error

func NewFileSystemError

func NewFileSystemError(cause error) *errorx.Error

func NewInstallationError

func NewInstallationError(cause error, softwareName, version string) *errorx.Error

func NewInvalidURLError

func NewInvalidURLError(cause error, url string) *errorx.Error

func NewPathTraversalError

func NewPathTraversalError(entryName string) *errorx.Error

func NewPlatformNotFoundError

func NewPlatformNotFoundError(softwareName, version, os, arch string) *errorx.Error

func NewSoftwareNotFoundError

func NewSoftwareNotFoundError(softwareName string) *errorx.Error

func NewTemplateError

func NewTemplateError(cause error, softwareName string) *errorx.Error

func NewUninstallationError

func NewUninstallationError(cause error, softwareName, version string) *errorx.Error

func NewVersionNotFoundError

func NewVersionNotFoundError(softwareName, version string) *errorx.Error

func RefreshPackageIndex

func RefreshPackageIndex() error

func SafeErrorDetails

func SafeErrorDetails(err *errorx.Error) []string

SafeErrorDetails emits a PII-safe slice of error details.

func VerifyChecksum

func VerifyChecksum(filePath string, expectedValue string, algorithm string) error

VerifyChecksum dynamically verifies the checksum of a file using the specified algorithm

func WithPackageManager

func WithPackageManager(pm syspkg.PackageManager) func(*PackageInstaller)

func WithPackageName

func WithPackageName(name string) func(*PackageInstaller)

func WithPackageOptions

func WithPackageOptions(opts manager.Options) func(*PackageInstaller)

Types

type ArchiveDetail

type ArchiveDetail struct {
	Name             string `yaml:"name"`
	URL              string `yaml:"url"`
	PlatformChecksum `yaml:",inline"`
}

type ArtifactCollection

type ArtifactCollection struct {
	Artifact []ArtifactMetadata `yaml:"artifact"`
}

ArtifactCollection represents the root configuration structure

func LoadArtifactConfig

func LoadArtifactConfig() (*ArtifactCollection, error)

LoadArtifactConfig loads and parses the artifact.yaml configuration

func (*ArtifactCollection) GetArtifactByName

func (sc *ArtifactCollection) GetArtifactByName(name string) (*ArtifactMetadata, error)

GetArtifactByName finds a artifact item by name

type ArtifactMetadata

type ArtifactMetadata struct {
	Name     string                     `yaml:"name"`
	Versions map[Version]VersionDetails `yaml:"versions"`
	// contains filtered or unexported fields
}

ArtifactMetadata represents a single software artifact configuration with its versions which including archives, binaries and configuration files

func (*ArtifactMetadata) GetLatestVersion

func (si *ArtifactMetadata) GetLatestVersion() (string, error)

GetLatestVersion returns the latest versionToBeInstalled available for this software item Only supports semantic versions - returns error for non-semantic versionToBeInstalled formats

type AutoRemover

type AutoRemover interface {
	AutoRemove(opts *manager.Options) ([]manager.PackageInfo, error)
}

AutoRemover is an interface for package managers that support autoremove.

type BinaryDetail

type BinaryDetail struct {
	Name             string `yaml:"name"`
	URL              string `yaml:"url,omitempty"`
	Archive          string `yaml:"archive,omitempty"`
	PlatformChecksum `yaml:",inline"`
}

type Checksum

type Checksum struct {
	Algorithm string `yaml:"algorithm"`
	Value     string `yaml:"checksum"`
}

Checksum contains platform-specific checksum information

type ConfigDetail

type ConfigDetail struct {
	Name      string `yaml:"name"`
	URL       string `yaml:"url"`
	Archive   string `yaml:"archive,omitempty"`
	Algorithm string `yaml:"algorithm"`
	Value     string `yaml:"checksum"`
}

ConfigDetail represents a configuration file with its software

type Downloader

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

Downloader is responsible for downloading a software package and checking its integrity.

func NewDownloader

func NewDownloader(opts ...DownloaderOption) *Downloader

NewDownloader creates a new Downloader with default settings and optional configurations

func (*Downloader) Download

func (fd *Downloader) Download(url, destination string) error

Download downloads a file from the given URL to the specified destination

func (*Downloader) Extract

func (fd *Downloader) Extract(compressedFilePath string, destDir string) error

ExtractTarGz extracts a tar.gz file

type DownloaderOption

type DownloaderOption func(*Downloader)

DownloaderOption is a function that configures a Downloader

func WithAllowedDomains

func WithAllowedDomains(domains []string) DownloaderOption

WithAllowedDomains sets custom allowed domains for the downloader

func WithBasePath

func WithBasePath(basePath string) DownloaderOption

WithBasePath sets a custom base path for the downloader

func WithHTTPClient

func WithHTTPClient(client *http.Client) DownloaderOption

WithHTTPClient sets a custom HTTP client for the downloader (useful for testing)

func WithTimeout

func WithTimeout(timeout time.Duration) DownloaderOption

WithTimeout sets a custom timeout for the downloader

type InstallerOption

type InstallerOption func(*baseInstaller)

func WithVersion

func WithVersion(version string) InstallerOption

WithVersion sets the specific version to install for the software. If not provided, the latest version will be used automatically. This is a public API option that can be used when creating installers to override the default version selection behavior.

type Package

type Package interface {
	Name() string

	Install() (*syspkg.PackageInfo, error)

	Uninstall() (*syspkg.PackageInfo, error)

	Upgrade() (*syspkg.PackageInfo, error)

	Info() (*syspkg.PackageInfo, error)

	IsInstalled() bool
}

func NewConntrack

func NewConntrack() (Package, error)

func NewContainerd

func NewContainerd() (Package, error)

func NewEbtables

func NewEbtables() (Package, error)

func NewGpg

func NewGpg() (Package, error)

NewGpg creates a GPG package installer that works across different distributions Uses "gpg" package name which works on most modern distributions including: - Ubuntu/Debian (newer versions) - RHEL/CentOS/Fedora/Oracle Linux The underlying syspkg library automatically detects the correct package manager

func NewIptables

func NewIptables() (Package, error)

func NewNftables

func NewNftables() (Package, error)

func NewSocat

func NewSocat() (Package, error)

type PackageInstaller

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

PackageInstaller is the default implementation of the Package interface that uses standard system package manager to manage a system package

func NewPackageInstaller

func NewPackageInstaller(opts ...option) (*PackageInstaller, error)

func (*PackageInstaller) Info

func (p *PackageInstaller) Info() (*syspkg.PackageInfo, error)

func (*PackageInstaller) Install

func (p *PackageInstaller) Install() (*syspkg.PackageInfo, error)

func (*PackageInstaller) IsInstalled

func (p *PackageInstaller) IsInstalled() bool

func (*PackageInstaller) Name

func (p *PackageInstaller) Name() string

func (*PackageInstaller) Uninstall

func (p *PackageInstaller) Uninstall() (*syspkg.PackageInfo, error)

func (*PackageInstaller) Upgrade

func (p *PackageInstaller) Upgrade() (*syspkg.PackageInfo, error)

type PlatformChecksum

type PlatformChecksum map[string]map[string]Checksum

PlatformChecksum maps OS and ARCH to their respective checksums Format: map[OS]map[ARCH]Checksum e.g. in yaml format:

linux:
  amd64:
    algorithm: sha256
    checksum: abcdef...

type Software

type Software interface {
	// Download fetches the software artifacts,
	// including the binary, and configuration files
	Download() error

	// Extract unpacks the downloaded files under a temporary subdirectory called 'unpack'
	Extract() error

	// Install places the files in the sandbox destination
	Install() error

	// Uninstall removes the software from the sandbox and cleans up related files
	Uninstall() error

	// IsInstalled checks the directories and high-level contents in sandbox
	IsInstalled() (bool, error)

	// Configure sets up configurations, services, and related symlinks
	// It also fills the configuration files
	Configure() error

	// RemoveConfiguration removes symlinks and restores the configuration files
	RemoveConfiguration() error

	// IsConfigured checks if the configuration has been done
	IsConfigured() (bool, error)

	// Version returns the version of the software to be installed
	Version() string

	// Cleanup removes temporary files created during download and extraction
	Cleanup() error

	// GetStateManager returns the state manager for external state management
	GetStateManager() *state.Manager

	// GetSoftwareName returns the software name
	GetSoftwareName() string
}

func NewCiliumInstaller

func NewCiliumInstaller(opts ...InstallerOption) (Software, error)

NewCiliumInstaller creates a new installer for Cilium

func NewCrioInstaller

func NewCrioInstaller(opts ...InstallerOption) (Software, error)

func NewHelmInstaller

func NewHelmInstaller(opts ...InstallerOption) (Software, error)

func NewK9sInstaller

func NewK9sInstaller(opts ...InstallerOption) (Software, error)

func NewKubeadmInstaller

func NewKubeadmInstaller(opts ...InstallerOption) (Software, error)

func NewKubectlInstaller

func NewKubectlInstaller(opts ...InstallerOption) (Software, error)

func NewKubeletInstaller

func NewKubeletInstaller(opts ...InstallerOption) (Software, error)

type TemplateData

type TemplateData struct {
	VERSION string
	OS      string
	ARCH    string
}

TemplateData contains the variables used in template substitution

type Version

type Version string

type VersionDetails

type VersionDetails struct {
	Archives []ArchiveDetail `yaml:"archives,omitempty"`
	Binaries []BinaryDetail  `yaml:"binaries"`
	Configs  []ConfigDetail  `yaml:"configs,omitempty"`
}

VersionDetails represents the structure for a specific versionToBeInstalled including the archive, binary and related configuration files

func (VersionDetails) BinariesByArchive

func (v VersionDetails) BinariesByArchive() []BinaryDetail

BinariesByArchive returns only the binaries that are extracted from archives

func (VersionDetails) BinariesByURL

func (v VersionDetails) BinariesByURL() []BinaryDetail

BinariesByURL returns only the binaries that are downloaded directly via URL

func (VersionDetails) ConfigsByArchive

func (v VersionDetails) ConfigsByArchive() []ConfigDetail

ConfigsByArchive returns only the configuration files that are extracted from archives

func (VersionDetails) ConfigsByURL

func (v VersionDetails) ConfigsByURL() []ConfigDetail

ConfigsByURL returns only the configuration files that are downloaded directly via URL

func (VersionDetails) GetArchiveByName

func (v VersionDetails) GetArchiveByName(archiveName string) (*ArchiveDetail, error)

GetArchiveByName retrieves a specific archive file by name

func (VersionDetails) GetArchives

func (v VersionDetails) GetArchives() []ArchiveDetail

GetArchives retrieves all archives, sorted by name for consistent order

func (VersionDetails) GetBinaries

func (v VersionDetails) GetBinaries() []BinaryDetail

GetBinaries retrieves all binaries, sorted by name for consistent order

func (VersionDetails) GetBinaryByName

func (v VersionDetails) GetBinaryByName(binaryName string) (*BinaryDetail, error)

GetBinaryByName retrieves a specific binary file by name

func (VersionDetails) GetConfigByName

func (v VersionDetails) GetConfigByName(configName string) (*ConfigDetail, error)

GetConfigByName retrieves a specific configuration file by name

func (VersionDetails) GetConfigs

func (v VersionDetails) GetConfigs() []ConfigDetail

GetConfigs retrieves all configuration files, sorted by name for consistent order

Jump to

Keyboard shortcuts

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