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 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) 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) 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
type ClusterCap interface {
CapCluster() bool
}
ClusterCap reports whether the manager engine is a reachable swarm manager (cluster mode on). Implemented by services/cluster. A workspace network is a swarm-scoped overlay in cluster mode and 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 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) 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 (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: those workspaces' apps and databases are on per-node islands. That is the normal state for an install that was ALREADY in cluster mode when it upgraded to this version — Migrate only runs on the enable transition, so nothing has converted it. The admin applies it explicitly (cluster.ApplyNetworking); the UI surfaces this count to tell them they need to.
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.