Documentation
¶
Overview ¶
Package network manages Docker networks owned by workspaces. The platform owns the full lifecycle: each workspace gets a default network on creation, and the Docker network is created/removed alongside the database record.
Index ¶
- Constants
- Variables
- type ClusterCap
- type DBInstances
- type Detail
- type Input
- type MigrationReport
- type Resolver
- type Servers
- type Service
- func (s *Service) Create(ctx context.Context, workspaceID uint, in Input) (*models.Network, error)
- func (s *Service) Delete(ctx context.Context, workspaceID, id uint) error
- func (s *Service) Detail(ctx context.Context, workspaceID, id uint) (*Detail, error)
- func (s *Service) EnsureDefault(ctx context.Context, workspaceID uint) (*models.Network, error)
- func (s *Service) Get(workspaceID, id uint) (*models.Network, error)
- func (s *Service) List(workspaceID uint) ([]models.Network, error)
- func (s *Service) Migrate(ctx context.Context) (MigrationReport, error)
- func (s *Service) PendingMigration() (int, error)
- func (s *Service) PruneStaleBridges(ctx context.Context, dc docker.Client, nodeName string) []string
- func (s *Service) Rollback(ctx context.Context) (MigrationReport, error)
- func (s *Service) SetAllocator(a *netalloc.Service)
- func (s *Service) SetClients(r Resolver)
- func (s *Service) SetCluster(c ClusterCap)
- func (s *Service) SetMigrationDeps(servers Servers, dbs DBInstances)
- func (s *Service) SetQuota(q *quota.Service)
Constants ¶
const ( DriverBridge = "bridge" DriverOverlay = "overlay" )
DriverBridge and DriverOverlay are the two drivers a workspace network can be provisioned with. Overlay spans nodes (requires swarm); bridge is node-local.
Variables ¶
var ( ErrNameRequired = errors.New("network name is required") ErrNameTaken = errors.New("a network with this name already exists") ErrNotFound = errors.New("network not found") ErrInUse = errors.New("network is attached to one or more applications") ErrIsDefault = errors.New("the default network cannot be deleted") ErrInvalidDriver = errors.New("unsupported network driver") )
var ErrClusterRequired = errors.New("cluster mode must be enabled to convert workspace networks")
ErrClusterRequired is returned when a driver conversion is attempted while the manager is not a swarm manager. Both directions need it: creating an overlay requires swarm, and so does detaching containers from one.
Functions ¶
This section is empty.
Types ¶
type ClusterCap ¶ added in v1.3.0
ClusterCap reports whether a cluster runs a swarm. Implemented by services/cluster. A workspace network is a swarm-scoped overlay while the default cluster is a swarm, a node-local bridge otherwise.
type DBInstances ¶ added in v1.3.0
DBInstances repoints database instances pinned to a network by name. Satisfied by repositories.DatabaseRepository.
type Detail ¶ added in v1.10.2
type Detail struct {
models.Network
// Exists is false when the network is recorded but absent from the engine — a node rebuilt
// without it, or a hand-removed network. The addressing fields are then empty rather than stale.
Exists bool `json:"exists"`
Subnet string `json:"subnet,omitempty"`
Gateway string `json:"gateway,omitempty"`
IPv6Subnet string `json:"ipv6_subnet,omitempty"`
IPv6Gateway string `json:"ipv6_gateway,omitempty"`
EnableIPv6 bool `json:"enable_ipv6"`
Scope string `json:"scope,omitempty"`
}
Detail is a workspace network with the addressing the engine actually gave it. The stored row says what Miabi asked for; this says what exists, which is what an operator debugging connectivity needs — and the only place the IPv6 half is visible at all.
type MigrationReport ¶ added in v1.3.0
type MigrationReport struct {
Migrated []string `json:"migrated"` // docker names of the networks after conversion
Failed []string `json:"failed,omitempty"` // networks left on their old driver (see logs)
// OfflineNodes are nodes whose containers could not be moved because their
// agent was disconnected. Their containers stay on the old network until the
// next deploy re-attaches them to the (already repointed) workspace network.
OfflineNodes []string `json:"offline_nodes,omitempty"`
}
MigrationReport summarizes one conversion run.
type Resolver ¶ added in v1.3.0
Resolver resolves the Docker client for a node id (0 = local/manager). Satisfied by the nodes.Clients registry.
type Servers ¶ added in v1.3.0
Servers lists the nodes whose engines may hold containers on a workspace network. Satisfied by repositories.ServerRepository.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(repo *repositories.NetworkRepository, dockerClient docker.Client) *Service
func (*Service) Detail ¶ added in v1.10.2
Detail returns one workspace network with its live addressing. A network the engine does not have (an overlay no local container has attached yet, an offline node) comes back with Exists false rather than an error: the row is still the truth about what the workspace owns.
func (*Service) EnsureDefault ¶
EnsureDefault creates the workspace's default network if it has none.
func (*Service) Migrate ¶ added in v1.3.0
func (s *Service) Migrate(ctx context.Context) (MigrationReport, error)
Migrate converts every bridge-backed workspace network into a swarm overlay, so containers can reach each other across nodes. It runs when the admin enables cluster networking — never on upgrade, never implicitly, and never on a single-node install, since the overlay driver requires swarm.
func (*Service) PendingMigration ¶ added in v1.3.0
PendingMigration counts the workspace networks still on a node-local bridge. Non-zero in cluster mode means cross-node east-west does not work yet. That is the normal state for an install already clustered when it upgraded, since Migrate runs only on the enable transition; the UI surfaces this count.
func (*Service) PruneStaleBridges ¶ added in v1.10.18
func (s *Service) PruneStaleBridges(ctx context.Context, dc docker.Client, nodeName string) []string
PruneStaleBridges removes, on one node, the workspace bridges that no longer back a workspace network. Converting to cluster networking removes the old bridges only on the nodes it reaches, and hands their pool subnets to the new overlays; a bridge left on another node then makes every overlay attachment there fail with "Pool overlaps". Run when a node joins the cluster and whenever its agent connects.
Docker refuses to remove a network with containers attached, so a bridge still in use is kept and reported rather than torn out from under its containers.
func (*Service) Rollback ¶ added in v1.3.0
func (s *Service) Rollback(ctx context.Context) (MigrationReport, error)
Rollback converts every overlay-backed workspace network back into a node-local bridge. It must run *before* the manager leaves the swarm — once swarm is gone the overlays go with it, and every workspace would be left pointing at a network that no longer exists. See cluster.Disable.
func (*Service) SetAllocator ¶
SetAllocator wires the subnet allocator so managed networks get a Miabi-carved subnet instead of Docker's default pool (nil-safe; nil = Docker default pool).
func (*Service) SetClients ¶ added in v1.3.0
SetClients wires the per-node Docker client registry used by the migration.
func (*Service) SetCluster ¶ added in v1.3.0
func (s *Service) SetCluster(c ClusterCap)
SetCluster wires swarm detection (nil-safe; nil = never cluster mode, so workspace networks stay bridges — the single-node default).
func (*Service) SetMigrationDeps ¶ added in v1.3.0
func (s *Service) SetMigrationDeps(servers Servers, dbs DBInstances)
SetMigrationDeps wires the pieces only the bridge -> overlay migration needs. All are optional: without them Migrate refuses to run rather than half-doing it.