mesh

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: GPL-3.0, LGPL-3.0 Imports: 22 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mesh manages the global infrastructure shared across all sind clusters.

Index

Constants

View Source
const (
	NetworkName      docker.NetworkName   = "sind-mesh"
	DNSContainerName docker.ContainerName = "sind-dns"
	SSHContainerName docker.ContainerName = "sind-ssh"
	SSHVolumeName    docker.VolumeName    = "sind-ssh-config"
)

Default-realm resource names. Production code uses Manager methods; these constants are used in tests as expected values for DefaultRealm.

View Source
const DNSImage = "coredns/coredns:1.15.0"

DNSImage is the container image used for the mesh DNS server, a pinned CoreDNS release.

View Source
const DefaultRealm = "sind"

DefaultRealm is the realm name that produces the standard resource names.

View Source
const LabelDNSIP = "sind.dns.ip"

LabelDNSIP is the label of a mesh network that records the address its DNS container is pinned to (see EnsureMeshNetwork). Meshes created by earlier sind versions lack it: their DNS container gets an address from Docker each time it starts.

View Source
const LabelRealm = "sind.realm"

LabelRealm is the Docker label applied to mesh resources (network, volumes) so realm-scoped listings can filter by label rather than by name prefix. pkg/cluster defines the same constant for cluster-scoped resources; keeping it local here avoids a pkg/mesh → pkg/cluster import.

View Source
const PublicKeyPath = "/root/.ssh/id_ed25519.pub"

PublicKeyPath is the path to the public key inside the SSH container.

Variables

This section is empty.

Functions

func SSHImage

func SSHImage() string

SSHImage returns the container image of the SSH relay: sind's default node image, which has an ssh client and bash, and which the default cluster pulls anyway. Custom node images need not have an ssh client.

func ServiceIP added in v0.12.0

func ServiceIP(dnsIP string, n int) string

ServiceIP returns the address n below a pinned DNS address, for the n-th mesh service with a pinned address of its own (n from 1): like the DNS address, it lies in the upper half of the mesh subnet, outside the --ip-range Docker gives other containers their addresses from (see pinnedLayout), so no container takes it while the service is stopped. It returns "" for an empty or unreadable dnsIP.

Types

type CoreDNSStub added in v0.13.0

type CoreDNSStub struct {
	Zone     string `json:"zone"`
	Server   string `json:"server"` // the mesh DNS server's address
	Corefile string `json:"corefile"`
}

CoreDNSStub is a CoreDNS server block that forwards the realm's zone to the mesh DNS server, for a DNS server outside sind such as the CoreDNS of a kind cluster.

type DNSRecord

type DNSRecord struct {
	Hostname string `json:"hostname"`
	IP       string `json:"ip"`
}

DNSRecord represents a single A record in the mesh DNS.

type Info added in v0.9.0

type Info struct {
	Network      string `json:"network"`
	DNSContainer string `json:"dns_container"`
	DNSIP        string `json:"dns_ip"`
	DNSZone      string `json:"dns_zone"`
	DNSImage     string `json:"dns_image"`
	SSHContainer string `json:"ssh_container"`
	SSHVolume    string `json:"ssh_volume"`
	SSHImage     string `json:"ssh_image"`
}

Info holds information about the mesh infrastructure for a realm.

type KnownHostEntry added in v0.9.0

type KnownHostEntry struct {
	Hostname string
	HostKey  string
}

KnownHostEntry holds a hostname and its SSH host key for batch registration.

type Manager

type Manager struct {
	Docker  *docker.Client
	Exec    cmdexec.Executor // executor for non-docker system commands (systemctl, resolvectl, etc.)
	Realm   string
	Pull    bool // force fresh image pull (--pull always)
	HostDNS bool // configure host DNS resolution via systemd-resolved

	// OnWarning receives warnings meant for the user, such as a mesh DNS
	// address that containers created earlier no longer use. Without it,
	// Warn reports them through the context (sindlog.Warn), where the sind
	// CLI prints them to stderr.
	OnWarning func(msg string)
	// contains filtered or unexported fields
}

Manager handles global infrastructure resources shared across all clusters.

func NewHostManager added in v0.13.0

func NewHostManager(docker *docker.Client, realm string) *Manager

NewHostManager returns the Manager that sind commands and UIs run on the Docker host: NewManager with every command it runs logged at trace level and host DNS configuration enabled (HostDNS).

func NewManager

func NewManager(docker *docker.Client, realm string) *Manager

NewManager returns a Manager that operates on global resources through the given docker client. The realm determines resource naming: realm "sind" produces names like "sind-mesh", "sind-dns", etc.

func (*Manager) AddDNSRecords added in v0.9.0

func (m *Manager) AddDNSRecords(ctx context.Context, records []DNSRecord) error

AddDNSRecords adds multiple A records to the mesh DNS Corefile and reloads CoreDNS once. Existing entries for the same hostnames are replaced, making the operation idempotent on retry.

func (*Manager) AddKnownHosts added in v0.9.0

func (m *Manager) AddKnownHosts(ctx context.Context, entries []KnownHostEntry) error

AddKnownHosts adds host key entries to the known_hosts file. Existing entries for the same hostnames are replaced, making the operation idempotent on retry.

func (*Manager) CleanupMesh

func (m *Manager) CleanupMesh(ctx context.Context) error

CleanupMesh removes all global infrastructure resources. This should only be called when the last cluster is deleted.

func (*Manager) ComposeProject

func (m *Manager) ComposeProject() string

ComposeProject returns the Docker Compose project name for this realm's mesh.

func (*Manager) Created added in v0.6.0

func (m *Manager) Created() bool

Created reports whether the last EnsureMesh (or EnsureMeshNetwork) call created the mesh network, that is, the realm had no mesh before. Callers use it to decide whether to remove the mesh again when a create fails. A Manager can serve several creates, so they must still check that no cluster uses the mesh before they remove it.

func (*Manager) DNSContainerName

func (m *Manager) DNSContainerName() docker.ContainerName

DNSContainerName returns the DNS container name for this realm.

func (*Manager) DNSPolkitAuthorized added in v0.5.0

func (m *Manager) DNSPolkitAuthorized(ctx context.Context) bool

DNSPolkitAuthorized checks if the current process can configure per-link DNS without interactive authentication.

func (*Manager) EnsureMesh

func (m *Manager) EnsureMesh(ctx context.Context) (err error)

EnsureMesh creates the global infrastructure resources (mesh network, DNS, SSH volume, SSH container) that do not exist yet, and starts the DNS and SSH containers when they exist but are stopped, as after a host reboot or a Docker daemon restart.

network ┬→ DNS ────┬→ SSH relay → host DNS
        └→ volume ─┘

The DNS container starts before the relay, which resolves through it.

EnsureMesh reports its work as the hidden progress step "mesh", with a target for each part: "network", "dns", "volume" and "relay", each skipped with the reason "exists" or "running" when it had nothing to do, so that a mesh in place leaves no trace on a display. The step shows in the row of a part the newest line its docker commands write to standard error, not the data they write to standard output (see docker.Client): the docker create of the DNS container and of the relay writes the lines of the pull of its image there when the daemon does not have it. A part not seen to because one before it failed ends canceled with the step.

func (*Manager) EnsureMeshNetwork

func (m *Manager) EnsureMeshNetwork(ctx context.Context) error

EnsureMeshNetwork creates the shared mesh network if it does not already exist, and records in Created whether it did.

A new mesh network pins the address of the DNS container, which every node and the relay get as their --dns: Docker does not keep a stopped container's address, so after a host reboot a container that starts before the DNS container could take it. Docker accepts a fixed address (--ip) only on a network with a user-configured subnet. EnsureMeshNetwork therefore creates the network without one, so that Docker picks a subnet from its default address pools that avoids the other networks and the host's routes, removes it, and creates it again with that subnet and gateway and the --ip-range that pinnedLayout derives, recording the DNS address in the LabelDNSIP label. When another network takes the subnet in between, it starts over with the subnet Docker picks next, up to meshSubnetAttempts times. A subnet too small for the layout, or no attempt left, leaves the network without a pinned address, as earlier sind versions created it.

A client of the same Docker daemon that does not hold the realm's lock on the daemon (state.LockRealm with LockOptions.Client), such as a library caller, can create the network between the check and the create. Docker's "already exists" error then counts as an existing network, so that the caller's failure handling never removes it.

func (*Manager) GetCoreDNSStub added in v0.13.0

func (m *Manager) GetCoreDNSStub(ctx context.Context) (*CoreDNSStub, error)

GetCoreDNSStub returns the CoreDNS server block that forwards the realm's zone to the mesh DNS server. It fails while the DNS container is stopped, which then has no address.

func (*Manager) GetDNSRecords

func (m *Manager) GetDNSRecords(ctx context.Context) ([]DNSRecord, error)

GetDNSRecords returns all A records currently served by the mesh DNS, in the natural order of their host names (natsort), as the Corefile keeps them in the order they were added.

func (*Manager) GetInfo added in v0.9.0

func (m *Manager) GetInfo(ctx context.Context) (*Info, error)

GetInfo returns information about the mesh infrastructure for this realm: the DNS container's address (empty while it is stopped) and the images the DNS and SSH containers run (empty without an SSH container). Returns an error containing "no mesh found for realm" if the DNS container does not exist.

func (*Manager) GetSSHKnownHosts added in v0.9.0

func (m *Manager) GetSSHKnownHosts(ctx context.Context) (string, error)

GetSSHKnownHosts reads the known_hosts file from the SSH container.

func (*Manager) GetSSHPrivateKey added in v0.9.0

func (m *Manager) GetSSHPrivateKey(ctx context.Context) (string, error)

GetSSHPrivateKey reads the SSH private key from the SSH container.

func (*Manager) GetSSHPublicKey added in v0.9.0

func (m *Manager) GetSSHPublicKey(ctx context.Context) (string, error)

GetSSHPublicKey reads the SSH public key from the SSH container.

func (*Manager) NetworkName

func (m *Manager) NetworkName() docker.NetworkName

NetworkName returns the mesh network name for this realm.

func (*Manager) PinnedDNSIP added in v0.12.0

func (m *Manager) PinnedDNSIP(ctx context.Context) (string, error)

PinnedDNSIP returns the address the mesh network pins its DNS container to (LabelDNSIP), empty for a mesh created by an earlier sind version without one, or for a realm without a mesh network.

func (*Manager) RemoveDNSRecords added in v0.9.0

func (m *Manager) RemoveDNSRecords(ctx context.Context, hostnames []string) error

RemoveDNSRecords removes all A records for the given hostnames from the mesh DNS Corefile and reloads CoreDNS once.

func (*Manager) RemoveKnownHosts added in v0.9.0

func (m *Manager) RemoveKnownHosts(ctx context.Context, hostnames []string) error

RemoveKnownHosts removes all entries for the given hostnames from the known_hosts file in a single operation.

func (*Manager) ResolvedActive added in v0.5.0

func (m *Manager) ResolvedActive(ctx context.Context) bool

ResolvedActive checks if systemd-resolved is running.

func (*Manager) SSHContainerName

func (m *Manager) SSHContainerName() docker.ContainerName

SSHContainerName returns the SSH container name for this realm.

func (*Manager) SSHKeygenName

func (m *Manager) SSHKeygenName() docker.ContainerName

SSHKeygenName returns the temporary keygen container name for this realm.

func (*Manager) SSHVolumeName

func (m *Manager) SSHVolumeName() docker.VolumeName

SSHVolumeName returns the SSH volume name for this realm.

func (*Manager) StartMesh added in v0.11.0

func (m *Manager) StartMesh(ctx context.Context) (dnsIP string, found bool, err error)

StartMesh starts the realm's DNS and SSH relay containers that exist but are not running, as after a host reboot or a Docker daemon restart. It creates nothing: EnsureMesh does. The DNS container starts first, as the relay and the nodes resolve through it, and a restarted DNS container reapplies host DNS (HostDNS), which the host loses with the mesh bridge.

It returns the DNS container's address on the mesh network, and whether the realm has a DNS container. A relay created with another DNS address is reported with Warn (see WarnStaleDNS).

func (*Manager) Warn added in v0.11.0

func (m *Manager) Warn(ctx context.Context, msg string)

Warn reports a warning for the user through OnWarning, or through the context (sindlog.Warn) when OnWarning is nil.

func (*Manager) WarnStaleDNS added in v0.11.0

func (m *Manager) WarnStaleDNS(ctx context.Context, dnsIP string, infos ...*docker.ContainerInfo)

WarnStaleDNS warns about the containers in infos that were created to resolve through the mesh DNS at another address than dnsIP, the DNS container's current one. Docker fixes a container's DNS servers when it creates the container, so these keep asking the old address: names under <realm>.sind and external names no longer resolve in them. Containers created without --dns, and an empty dnsIP, are not checked.

Jump to

Keyboard shortcuts

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