virt

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DockerComposeProjectPrefix = "workstation-windsor-"

DockerComposeProjectPrefix is the prefix for the compose-style project label value (e.g. workstation-windsor-local). Containers are grouped by label com.docker.compose.project=<prefix><context> for display and cleanup.

View Source
const (
	IncusNetworkName = "incusbr0"
)
View Source
const WindsorNetworkPrefix = "windsor-"

WindsorNetworkPrefix is the prefix for Windsor-managed Docker networks (e.g. windsor-local). Down() targets only the current context's network, windsor-<context>.

Variables

View Source
var RETRY_WAIT = func() int {
	return map[bool]int{true: 0, false: 2}[os.Getenv("CI") == "true"]
}()

RETRY_WAIT is the number of seconds to wait between retries when starting or stopping a VM If running in CI, no wait is performed

Functions

This section is empty.

Types

type BaseVirt

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

func NewBaseVirt

func NewBaseVirt(rt *runtime.Runtime) *BaseVirt

NewBaseVirt creates a new BaseVirt instance

type ColimaVirt

type ColimaVirt struct {
	*BaseVirt
}

ColimaVirt implements the VirtInterface and VMInterface for Colima

func NewColimaVirt

func NewColimaVirt(rt *runtime.Runtime) *ColimaVirt

NewColimaVirt creates a new instance of ColimaVirt

func (*ColimaVirt) Down

func (v *ColimaVirt) Down() error

Down stops and deletes the Colima VM, ensuring resources are reclaimed. Attempts graceful shutdown, then deletes the VM. Returns an error if deletion fails.

func (*ColimaVirt) Up

func (v *ColimaVirt) Up() error

Up starts the Colima VM and configures its network settings. It initializes the VM with the appropriate configuration and waits for it to become ready. If the VM is already running, it skips the start operation and reuses the existing VM. The VM address is set in the configuration handler for later use. Kills stuck processes before starting if VM is not already running to prevent vmnet/daemon issues. Returns an error if the VM fails to start or if the address cannot be set.

func (*ColimaVirt) WriteConfig

func (v *ColimaVirt) WriteConfig() error

WriteConfig writes the Colima configuration file with VM settings Generates a configuration based on the current context and system properties Creates a temporary file and then renames it to the final configuration file Returns an error if any step of the configuration process fails

type ContainerInfo

type ContainerInfo struct {
	Name    string
	Address string
	Labels  map[string]string
}

type ContainerRuntime

type ContainerRuntime interface {
	Virt
}

ContainerRuntime defines methods for container operations

type DockerVirt

type DockerVirt struct {
	*BaseVirt
}

DockerVirt implements ContainerRuntime for platform docker. It does not start or manage a VM; Up/WriteConfig are no-ops when Terraform or compose elsewhere own the stack. Down() performs robust cleanup of residual containers and networks so windsor down clears local resources even if Terraform destroy was skipped.

func NewDockerVirt

func NewDockerVirt(rt *runtime.Runtime) *DockerVirt

NewDockerVirt creates a new DockerVirt with the provided runtime.

func (*DockerVirt) Down

func (v *DockerVirt) Down() error

Down stops and removes only resources for the current project/context: containers and named volumes with label com.docker.compose.project=workstation-windsor-<context>, and the network windsor-<context>. Anonymous volumes are removed with containers via rm -v. No global Docker cleanup is performed. Best-effort: errors are logged to stderr but do not cause Down to return an error. Shows a progress spinner.

func (*DockerVirt) Up

func (v *DockerVirt) Up() error

Up is a no-op for DockerVirt; containers are started by Terraform or compose elsewhere.

func (*DockerVirt) WriteConfig

func (v *DockerVirt) WriteConfig() error

WriteConfig is a no-op for DockerVirt.

type IncusInstance added in v0.9.0

type IncusInstance struct {
	Name            string                 `json:"name"`
	Status          string                 `json:"status"`
	StatusCode      int                    `json:"status_code"`
	Type            string                 `json:"type"`
	ExpandedDevices map[string]interface{} `json:"expanded_devices"`
}

IncusInstance represents an Incus instance parsed from JSON output. It contains the instance name, status information, type, and expanded device configurations as returned by the Incus CLI when listing instances.

type IncusInstanceConfig added in v0.9.0

type IncusInstanceConfig struct {
	Name      string
	Type      string
	Image     string
	Config    map[string]string
	Devices   map[string]map[string]string
	Profiles  []string
	IPv4      string
	Network   string
	Resources map[string]string
}

IncusInstanceConfig represents the complete configuration for creating an Incus instance. It contains all necessary parameters including instance name, type, image, network settings, device configurations, profiles, and resource limits required for instance creation.

type IncusOperation added in v0.9.0

type IncusOperation struct {
	ID         string         `json:"id"`
	Class      string         `json:"class"`
	CreatedAt  string         `json:"created_at"`
	UpdatedAt  string         `json:"updated_at"`
	Status     string         `json:"status"`
	StatusCode int            `json:"status_code"`
	Resources  map[string]any `json:"resources"`
	Metadata   map[string]any `json:"metadata"`
	MayCancel  bool           `json:"may_cancel"`
	Err        string         `json:"err"`
}

IncusOperation represents an Incus operation parsed from JSON output. It contains operation metadata including ID, status, timestamps, resources affected, and error information as returned by the Incus CLI when listing operations.

type IncusRemote added in v0.9.0

type IncusRemote struct {
	Name     string `json:"name"`
	URL      string `json:"url"`
	Protocol string `json:"protocol"`
	Public   bool   `json:"public"`
}

IncusRemote represents an Incus remote repository parsed from JSON output. It contains the remote name, URL, protocol type, and public access flag as returned by the Incus CLI when listing configured remotes.

type IncusVirt added in v0.9.0

type IncusVirt struct {
	*ColimaVirt
	// contains filtered or unexported fields
}

IncusVirt implements both the ContainerRuntime and VirtualMachine interfaces for Incus. It embeds ColimaVirt to inherit Colima VM functionality. Instance creation is handled by Terraform in the stack.

func NewIncusVirt added in v0.9.0

func NewIncusVirt(rt *runtime.Runtime) *IncusVirt

NewIncusVirt creates a new IncusVirt with the provided runtime and embeds ColimaVirt for VM lifecycle.

func (*IncusVirt) Down added in v0.9.0

func (v *IncusVirt) Down() error

Down stops the Colima Incus daemon and runs the parent's Down() to clean up the VM.

func (*IncusVirt) Up added in v0.9.0

func (v *IncusVirt) Up() error

Up performs startup for the IncusVirt environment according to its current role. When invoked as a VirtualMachine, it starts the Colima VM by delegating to ColimaVirt.Up() if the VM is not already running. When invoked as a ContainerRuntime, and the VM is already running, it creates Incus instances for all configured services. This method determines the operation to perform by checking the VM's running status. It performs Incus-specific initialization when running as a container runtime, such as remote repository setup and instance creation. Returns an error if any step of initialization or startup fails.

type MockVirt

type MockVirt struct {
	UpFunc          func(verbose ...bool) error
	DownFunc        func() error
	WriteConfigFunc func() error
}

MockVirt is a struct that simulates a virt environment for testing purposes.

func NewMockVirt

func NewMockVirt() *MockVirt

NewMockVirt creates a new instance of MockVirt.

func (*MockVirt) Down

func (m *MockVirt) Down() error

Down stops the mock virt. If a custom DownFunc is provided, it will use that function instead.

func (*MockVirt) Up

func (m *MockVirt) Up() error

Up starts the mock virt. If a custom UpFunc is provided, it will use that function instead.

func (*MockVirt) WriteConfig

func (m *MockVirt) WriteConfig() error

WriteConfig writes the configuration of the mock virt. If a custom WriteConfigFunc is provided, it will use that function instead.

type Shims

type Shims struct {
	Setenv         func(key, value string) error
	UnmarshalJSON  func(data []byte, v any) error
	UserHomeDir    func() (string, error)
	MkdirAll       func(path string, perm os.FileMode) error
	WriteFile      func(name string, data []byte, perm os.FileMode) error
	Rename         func(oldpath, newpath string) error
	Stat           func(name string) (os.FileInfo, error)
	GOARCH         func() string
	NumCPU         func() int
	VirtualMemory  func() (*mem.VirtualMemoryStat, error)
	MarshalYAML    func(v any) ([]byte, error)
	NewYAMLEncoder func(w io.Writer, opts ...yaml.EncodeOption) YAMLEncoder
}

Shims provides mockable wrappers around system and runtime functions

func NewShims

func NewShims() *Shims

NewShims creates a new Shims instance with default implementations

type VMInfo

type VMInfo struct {
	Address string
	Arch    string
	CPUs    int
	Disk    int
	Memory  int
	Name    string
}

VMInfo is a struct that holds the information about the VM

type Virt

type Virt interface {
	Up() error
	Down() error
	WriteConfig() error
}

Virt defines methods for the virt operations

type VirtualMachine

type VirtualMachine interface {
	Virt
}

VirtualMachine defines methods for VirtualMachine operations

type YAMLEncoder

type YAMLEncoder interface {
	Encode(v any) error
	Close() error
}

YAMLEncoder is an interface for encoding YAML data.

Jump to

Keyboard shortcuts

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