Documentation
¶
Index ¶
- type BaseNetworkManager
- func (n *BaseNetworkManager) ConfigureDNS(ctx context.Context) error
- func (n *BaseNetworkManager) ConfigureGuest() error
- func (n *BaseNetworkManager) ConfigureHostRoute(ctx context.Context) error
- func (n *BaseNetworkManager) DNSChanged() bool
- func (n *BaseNetworkManager) FlushDNS(ctx context.Context) error
- func (n *BaseNetworkManager) IsHostRouteInstalled() bool
- func (n *BaseNetworkManager) IsResolverInstalled() bool
- func (n *BaseNetworkManager) NeedsPrivilegeForCluster() bool
- func (n *BaseNetworkManager) NeedsPrivilegeForDNS() bool
- func (n *BaseNetworkManager) RevertDNS() error
- func (n *BaseNetworkManager) RevertGuest() error
- func (n *BaseNetworkManager) RevertHostRoute() error
- type ColimaNetworkManager
- type MockNetworkInterfaceProvider
- type MockNetworkManager
- func (m *MockNetworkManager) ConfigureDNS(_ context.Context) error
- func (m *MockNetworkManager) ConfigureGuest() error
- func (m *MockNetworkManager) ConfigureHostRoute(_ context.Context) error
- func (m *MockNetworkManager) DNSChanged() bool
- func (m *MockNetworkManager) FlushDNS(_ context.Context) error
- func (m *MockNetworkManager) IsHostRouteInstalled() bool
- func (m *MockNetworkManager) IsResolverInstalled() bool
- func (m *MockNetworkManager) NeedsPrivilegeForCluster() bool
- func (m *MockNetworkManager) NeedsPrivilegeForDNS() bool
- func (m *MockNetworkManager) RevertDNS() error
- func (m *MockNetworkManager) RevertGuest() error
- func (m *MockNetworkManager) RevertHostRoute() error
- type NetworkInterfaceProvider
- type NetworkManager
- type RealNetworkInterfaceProvider
- type Shims
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseNetworkManager ¶
type BaseNetworkManager struct {
// contains filtered or unexported fields
}
BaseNetworkManager is a concrete implementation of NetworkManager.
func NewBaseNetworkManager ¶
func NewBaseNetworkManager(rt *runtime.Runtime) *BaseNetworkManager
NewBaseNetworkManager returns a BaseNetworkManager for rt. It panics when rt, its shell, or its config handler is nil.
func (*BaseNetworkManager) ConfigureDNS ¶
func (n *BaseNetworkManager) ConfigureDNS(ctx context.Context) error
ConfigureDNS writes a systemd-resolved drop-in file that sends queries for dns.domain to the resolver IP. It does not change the global DNS. It returns an error with a remediation hint when the domain or the resolver IP is not set, when systemd-resolved is not running, or when /etc/resolv.conf does not point at the systemd-resolved stub. It shows a warning when the NetworkManager dns=default mode can replace the drop-in.
func (*BaseNetworkManager) ConfigureGuest ¶
func (n *BaseNetworkManager) ConfigureGuest() error
ConfigureGuest does nothing. ColimaNetworkManager overrides it.
func (*BaseNetworkManager) ConfigureHostRoute ¶
func (n *BaseNetworkManager) ConfigureHostRoute(ctx context.Context) error
ConfigureHostRoute sets up the local development network for Linux. Guest address is read from config (workstation.address). Installs the route in the live routing table via `ip route add` when missing, then writes a systemd-networkd drop-in at /etc/systemd/network/windsor-<context>.network (or registers a persistent route via `nmcli` when NetworkManager owns the connection) so the route survives reboot. When neither persistence mechanism is available the live route is left in place and an actionable warning is printed.
func (*BaseNetworkManager) DNSChanged ¶ added in v0.9.0
func (n *BaseNetworkManager) DNSChanged() bool
DNSChanged reports whether ConfigureDNS wrote a new configuration during this run.
func (*BaseNetworkManager) FlushDNS ¶ added in v0.9.0
func (n *BaseNetworkManager) FlushDNS(ctx context.Context) error
FlushDNS is a no-op on Linux; DNS cache is cleared by restarting systemd-resolved during ConfigureDNS.
func (*BaseNetworkManager) IsHostRouteInstalled ¶ added in v0.9.0
func (n *BaseNetworkManager) IsHostRouteInstalled() bool
IsHostRouteInstalled reports whether the host route for the CIDR through the guest address is present. It is always false when workstation.runtime is not colima.
func (*BaseNetworkManager) IsResolverInstalled ¶ added in v0.9.0
func (n *BaseNetworkManager) IsResolverInstalled() bool
IsResolverInstalled reports whether the resolver entry for dns.domain is present with the resolver IP. An entry with a different IP does not count. It is false when dns.domain or the resolver IP is not set.
func (*BaseNetworkManager) NeedsPrivilegeForCluster ¶ added in v0.9.0
func (n *BaseNetworkManager) NeedsPrivilegeForCluster() bool
NeedsPrivilegeForCluster reports whether the host needs a host route before it can reach the cluster. Only colima can need one, because docker-desktop has the cluster on 127.0.0.1. A failed probe counts as false. ConfigureHostRoute reports its own errors.
func (*BaseNetworkManager) NeedsPrivilegeForDNS ¶ added in v0.9.0
func (n *BaseNetworkManager) NeedsPrivilegeForDNS() bool
NeedsPrivilegeForDNS reports whether the host resolver needs a change to send *.dns.domain to the cluster DNS. It is true when dns.domain and a resolver IP are set and the host resolver entry does not match. A failed probe counts as false.
func (*BaseNetworkManager) RevertDNS ¶ added in v0.9.0
func (n *BaseNetworkManager) RevertDNS() error
RevertDNS removes the systemd-resolved drop-in installed by ConfigureDNS on Linux and restarts systemd-resolved so it picks up the change. Idempotent: no-op when dns.domain is unset; rm -f tolerates a missing file silently. The restart is best-effort — a failure surfaces an error because operators expect DNS state to be coherent after revert.
func (*BaseNetworkManager) RevertGuest ¶ added in v0.9.0
func (n *BaseNetworkManager) RevertGuest() error
RevertGuest does nothing. ColimaNetworkManager overrides it.
func (*BaseNetworkManager) RevertHostRoute ¶ added in v0.9.0
func (n *BaseNetworkManager) RevertHostRoute() error
RevertHostRoute removes the host-to-guest route previously added by ConfigureHostRoute on Linux. Idempotent: no-op when the network CIDR is unset, tolerates "No such process" for the live delete, removes any matching systemd-networkd drop-in, and drops the NetworkManager persistent route when one was installed via nmcli.
type ColimaNetworkManager ¶
type ColimaNetworkManager struct {
BaseNetworkManager
// contains filtered or unexported fields
}
ColimaNetworkManager is the NetworkManager for a Colima VM.
func NewColimaNetworkManager ¶
func NewColimaNetworkManager(rt *runtime.Runtime, networkInterfaceProvider NetworkInterfaceProvider) *ColimaNetworkManager
NewColimaNetworkManager returns a ColimaNetworkManager for rt. It panics when rt or the provider is nil.
func (*ColimaNetworkManager) ConfigureGuest ¶
func (n *ColimaNetworkManager) ConfigureGuest() error
ConfigureGuest forwards guest traffic in the Colima VM to the Docker bridge, or to the Incus network on platform incus. It does nothing when workstation.address is empty.
func (*ColimaNetworkManager) RevertGuest ¶ added in v0.9.0
func (n *ColimaNetworkManager) RevertGuest() error
RevertGuest removes the iptables FORWARD rule in the VM that ConfigureGuest installed. It finds the Docker bridge as ConfigureGuest does, and then deletes the rule. It returns nil when the rule, the bridge, or the VM is absent. It does nothing when workstation.address is empty.
type MockNetworkInterfaceProvider ¶
type MockNetworkInterfaceProvider struct {
InterfacesFunc func() ([]net.Interface, error)
InterfaceAddrsFunc func(iface net.Interface) ([]net.Addr, error)
}
MockNetworkInterfaceProvider is a struct that simulates a network interface provider for testing purposes.
func NewMockNetworkInterfaceProvider ¶
func NewMockNetworkInterfaceProvider() *MockNetworkInterfaceProvider
NewMockNetworkInterfaceProvider creates a new instance of MockNetworkInterfaceProvider with default implementations.
func (*MockNetworkInterfaceProvider) InterfaceAddrs ¶
InterfaceAddrs calls the custom InterfaceAddrsFunc if provided.
func (*MockNetworkInterfaceProvider) Interfaces ¶
func (m *MockNetworkInterfaceProvider) Interfaces() ([]net.Interface, error)
Interfaces calls the custom InterfacesFunc if provided.
type MockNetworkManager ¶
type MockNetworkManager struct {
NetworkManager
ConfigureHostRouteFunc func() error
ConfigureGuestFunc func() error
ConfigureDNSFunc func() error
RevertHostRouteFunc func() error
RevertGuestFunc func() error
RevertDNSFunc func() error
FlushDNSFunc func() error
NeedsPrivilegeForClusterFunc func() bool
NeedsPrivilegeForDNSFunc func() bool
IsHostRouteInstalledFunc func() bool
IsResolverInstalledFunc func() bool
DNSChangedFunc func() bool
}
MockNetworkManager is a struct that simulates a network manager for testing purposes.
func NewMockNetworkManager ¶
func NewMockNetworkManager() *MockNetworkManager
NewMockNetworkManager creates a new instance of MockNetworkManager.
func (*MockNetworkManager) ConfigureDNS ¶
func (m *MockNetworkManager) ConfigureDNS(_ context.Context) error
ConfigureDNS calls the custom ConfigureDNSFunc if provided.
func (*MockNetworkManager) ConfigureGuest ¶
func (m *MockNetworkManager) ConfigureGuest() error
ConfigureGuest calls the custom ConfigureGuestFunc if provided.
func (*MockNetworkManager) ConfigureHostRoute ¶
func (m *MockNetworkManager) ConfigureHostRoute(_ context.Context) error
ConfigureHostRoute calls the custom ConfigureHostRouteFunc if provided.
func (*MockNetworkManager) DNSChanged ¶ added in v0.9.0
func (m *MockNetworkManager) DNSChanged() bool
DNSChanged calls the custom DNSChangedFunc if provided.
func (*MockNetworkManager) FlushDNS ¶ added in v0.9.0
func (m *MockNetworkManager) FlushDNS(_ context.Context) error
FlushDNS calls the custom FlushDNSFunc if provided.
func (*MockNetworkManager) IsHostRouteInstalled ¶ added in v0.9.0
func (m *MockNetworkManager) IsHostRouteInstalled() bool
IsHostRouteInstalled calls the custom IsHostRouteInstalledFunc if provided.
func (*MockNetworkManager) IsResolverInstalled ¶ added in v0.9.0
func (m *MockNetworkManager) IsResolverInstalled() bool
IsResolverInstalled calls the custom IsResolverInstalledFunc if provided.
func (*MockNetworkManager) NeedsPrivilegeForCluster ¶ added in v0.9.0
func (m *MockNetworkManager) NeedsPrivilegeForCluster() bool
NeedsPrivilegeForCluster calls the custom NeedsPrivilegeForClusterFunc if provided.
func (*MockNetworkManager) NeedsPrivilegeForDNS ¶ added in v0.9.0
func (m *MockNetworkManager) NeedsPrivilegeForDNS() bool
NeedsPrivilegeForDNS calls the custom NeedsPrivilegeForDNSFunc if provided.
func (*MockNetworkManager) RevertDNS ¶ added in v0.9.0
func (m *MockNetworkManager) RevertDNS() error
RevertDNS calls the custom RevertDNSFunc if provided.
func (*MockNetworkManager) RevertGuest ¶ added in v0.9.0
func (m *MockNetworkManager) RevertGuest() error
RevertGuest calls the custom RevertGuestFunc if provided.
func (*MockNetworkManager) RevertHostRoute ¶ added in v0.9.0
func (m *MockNetworkManager) RevertHostRoute() error
RevertHostRoute calls the custom RevertHostRouteFunc if provided.
type NetworkInterfaceProvider ¶
type NetworkInterfaceProvider interface {
Interfaces() ([]net.Interface, error)
InterfaceAddrs(iface net.Interface) ([]net.Addr, error)
}
NetworkInterfaceProvider abstracts the system's network interface operations
func NewNetworkInterfaceProvider ¶
func NewNetworkInterfaceProvider() NetworkInterfaceProvider
NewNetworkInterfaceProvider creates a new real implementation of NetworkInterfaceProvider
type NetworkManager ¶
type NetworkManager interface {
ConfigureHostRoute(ctx context.Context) error
ConfigureGuest() error
ConfigureDNS(ctx context.Context) error
RevertHostRoute() error
RevertGuest() error
RevertDNS() error
FlushDNS(ctx context.Context) error
NeedsPrivilegeForCluster() bool
NeedsPrivilegeForDNS() bool
IsHostRouteInstalled() bool
IsResolverInstalled() bool
DNSChanged() bool
}
NetworkManager configures the guest, the host route, and the DNS of the local network. Each Revert method undoes its Configure method and does nothing when the state is absent. IsHostRouteInstalled and IsResolverInstalled report whether that host state is present. 'windsor down' uses them to find host state that it cannot remove without a prompt.
type RealNetworkInterfaceProvider ¶
type RealNetworkInterfaceProvider struct{}
RealNetworkInterfaceProvider is the real implementation of NetworkInterfaceProvider
func (*RealNetworkInterfaceProvider) InterfaceAddrs ¶
InterfaceAddrs returns the addresses of a network interface
func (*RealNetworkInterfaceProvider) Interfaces ¶
func (p *RealNetworkInterfaceProvider) Interfaces() ([]net.Interface, error)
Interfaces returns the system's network interfaces