Documentation
¶
Index ¶
- func PreflightConfigureNetwork() error
- func SetCanElevateNonInteractivelyForTest(fn func(shell.Shell) bool) func()
- type DeferredWorkItem
- type NetworkChange
- type Workstation
- func (w *Workstation) ConfigureNetwork(dnsAddressOverride string, showStatus bool) error
- func (w *Workstation) DeferredWork() []DeferredWorkItem
- func (w *Workstation) Down() error
- func (w *Workstation) FlushDNS() error
- func (w *Workstation) IsProvisioned() (bool, error)
- func (w *Workstation) MakeApplyHook() func(componentID string) (bool, error)
- func (w *Workstation) MakePostApplyHook() func(componentID string) error
- func (w *Workstation) PendingNetworkChanges() []NetworkChange
- func (w *Workstation) Prepare() error
- func (w *Workstation) PrepareForUp(blueprint *blueprintv1alpha1.Blueprint)
- func (w *Workstation) RevertNetwork(showStatus bool) error
- func (w *Workstation) Up() error
- func (w *Workstation) WriteState() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PreflightConfigureNetwork ¶ added in v0.9.0
func PreflightConfigureNetwork() error
PreflightConfigureNetwork gates 'windsor configure network' on platforms that need the process itself to be elevated. On unix the privileged steps each invoke per-op sudo (cached after the first prompt), so the process can start unprivileged and this returns nil.
func SetCanElevateNonInteractivelyForTest ¶ added in v0.9.0
SetCanElevateNonInteractivelyForTest replaces the package's elevation probe for the duration of a test and returns a restore function. Used by tests across platforms to simulate "can elevate" / "cannot elevate" without depending on the OS-specific implementation.
Types ¶
type DeferredWorkItem ¶ added in v0.9.0
DeferredWorkItem describes a step the apply skipped because it requires elevation the in-process Up() will not request. The end-of-run summary in cmd/up renders these into operator-facing guidance. Required items denote a halt (subsequent components were skipped and the operator must re-run 'windsor up' after acting); optional items denote work the operator can do at their convenience without re-running.
type NetworkChange ¶ added in v0.9.0
NetworkChange is one row of structured output for PendingNetworkChanges. Kind is a stable kebab-case identifier ("host-route", "vm-forward", "dns-resolver") and Detail is the value being installed ("192.168.5.0/24 via 192.168.5.10"). Callers are expected to render these as aligned columns rather than baking the kind into a prose sentence.
type Workstation ¶
type Workstation struct {
// Workstation-specific dependencies (created as needed)
NetworkManager network.NetworkManager
VirtualMachine virt.VirtualMachine
ContainerRuntime virt.ContainerRuntime
// DeferHostGuestSetup when true skips ConfigureGuest/ConfigureHostRoute/ConfigureDNS in Up().
// Set when the blueprint has a "workstation" Terraform component; host/guest setup runs after that component is applied via the provisioner callback.
// Temporary: in the future host/guest setup will always run after the "workstation" component and this flag may be removed.
DeferHostGuestSetup bool
// contains filtered or unexported fields
}
Workstation manages workstation virtualization, networking, and SSH operations.
func NewWorkstation ¶
func NewWorkstation(rt *runtime.Runtime, opts ...*Workstation) *Workstation
NewWorkstation creates a new Workstation instance with the provided runtime. Other dependencies are created only if not already present via opts. Panics if runtime or any required dependencies are nil.
func (*Workstation) ConfigureNetwork ¶ added in v0.9.0
func (w *Workstation) ConfigureNetwork(dnsAddressOverride string, showStatus bool) error
ConfigureNetwork runs host/guest and DNS setup. Workstation address and DNS config are expected in the config handler, loaded from .windsor/contexts/<context>/workstation.yaml (written during windsor up) or set explicitly. dnsAddressOverride (from --dns-address flag or Terraform output) takes priority over config. DNS is configured whenever dns.domain and the resolver address are both available — the operator opts in by running 'windsor configure network'. No-op when NetworkManager is nil.
func (*Workstation) DeferredWork ¶ added in v0.9.0
func (w *Workstation) DeferredWork() []DeferredWorkItem
DeferredWork returns the deferred-work items accumulated during the most recent Up(). The slice is reset at the start of each Up; callers should read it after Up returns. Returns nil when nothing was deferred.
func (*Workstation) Down ¶
func (w *Workstation) Down() error
Down reverts host network configuration (when present and elevation is available without prompting) and stops the workstation environment: container runtime, then VM. The revert step, when it fires, runs FIRST so that RevertGuest can SSH into the still-running VM to remove iptables rules; host route and resolver entries are then removed on the host. If the process can't elevate without prompting, the revert is skipped and the leftover state is recorded as a deferred-work item so the cmd layer can render an end-of-run summary after teardown — surprise sudo prompts during 'windsor down' would undermine the no-prompts contract this command exists to support. Revert failures are warned and do not halt teardown — the operator's primary intent is to stop the workstation. Workstation state is preserved so that 'windsor up' can resume cleanly.
func (*Workstation) FlushDNS ¶ added in v0.9.0
func (w *Workstation) FlushDNS() error
FlushDNS flushes the DNS cache when DNS is fully configured. It is a no-op when the network manager is absent or DNS domain/address are not set.
func (*Workstation) IsProvisioned ¶ added in v0.9.0
func (w *Workstation) IsProvisioned() (bool, error)
IsProvisioned reports whether 'windsor up' has applied the workstation Terraform component for the current context. Detection is by file presence: WriteState only writes <projectRoot>/.windsor/contexts/<context>/workstation.yaml after MakeApplyHook persists the component's TF outputs, so the file is the canonical "workstation provisioned" signal. Callers like 'windsor configure network' use this as a precondition gate. Returns (false, nil) when the state file is absent; (false, err) when a real IO error prevents the check.
func (*Workstation) MakeApplyHook ¶ added in v0.9.0
func (w *Workstation) MakeApplyHook() func(componentID string) (bool, error)
MakeApplyHook returns a callback for the provisioner's onApply when DeferHostGuestSetup is true. The callback persists DNS-related outputs from the just-applied workstation Terraform component, then inspects whether the host needs configuration that 'windsor up' is not allowed to perform (it must never prompt for sudo). When the cluster is unreachable from the host without a host route + in-VM forwarding, the hook appends a required DeferredWorkItem and returns (true, nil) so the stack halts after the workstation component and 'windsor up' renders an operator-facing summary. When the cluster DNS resolver isn't pointed at the cluster's DNS service, the hook appends an optional DeferredWorkItem with the outcome the operator gets from running 'windsor configure network' and continues (DNS is not load-bearing for subsequent components). Returns nil when DeferHostGuestSetup is false.
func (*Workstation) MakePostApplyHook ¶ added in v0.9.0
func (w *Workstation) MakePostApplyHook() func(componentID string) error
MakePostApplyHook returns a callback for the provisioner's postApply when DeferHostGuestSetup is true. The callback flushes the DNS cache after the workstation Terraform component if NetworkManager reports DNSChanged. Returns nil when DeferHostGuestSetup is false.
func (*Workstation) PendingNetworkChanges ¶ added in v0.9.0
func (w *Workstation) PendingNetworkChanges() []NetworkChange
PendingNetworkChanges returns the host configuration changes that 'windsor configure network' would apply for the current context. Returns an empty slice when nothing is pending. Returns nil when the workstation has no NetworkManager.
func (*Workstation) Prepare ¶
func (w *Workstation) Prepare() error
Prepare creates workstation components (network manager, virtual machine, container runtime). Call after configuration is loaded, then returns an error if any component creation fails.
func (*Workstation) PrepareForUp ¶ added in v0.9.0
func (w *Workstation) PrepareForUp(blueprint *blueprintv1alpha1.Blueprint)
PrepareForUp sets DeferHostGuestSetup to defer host/guest and DNS setup until after the "workstation" Terraform component is applied (via provisioner hook) when present and terraform.enabled is true. Call before Up() when Up will run Terraform with this blueprint.
func (*Workstation) RevertNetwork ¶ added in v0.9.0
func (w *Workstation) RevertNetwork(showStatus bool) error
RevertNetwork undoes the host configuration that ConfigureNetwork applied: removes the host route + in-VM forwarding on VM-backed runtimes, and removes the per-domain DNS resolver entry. Each step is idempotent — the corresponding NetworkManager.Revert* method tolerates missing state — so this is safe to call after partial configuration or against contexts that were never configured. No-op when NetworkManager is nil. showStatus emits one line per step to stderr; suppress it for non-interactive callers.
func (*Workstation) Up ¶
func (w *Workstation) Up() error
Up initializes the workstation environment: starts VMs, container runtime, and networking. Sets NO_CACHE, starts the virtual machine if configured, writes container runtime config, and configures networking. All components must be created via Prepare() before calling Up().
func (*Workstation) WriteState ¶ added in v0.9.0
func (w *Workstation) WriteState() error
WriteState delegates to ConfigHandler.SaveWorkstationState to persist workstation-managed config keys (workstation.*, platform, dns.*) to .windsor/contexts/<context>/workstation.yaml.