network

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

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

View Source
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

View Source
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")
)
View Source
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

type DBInstances interface {
	RetargetNetwork(oldName, newName string) error
}

DBInstances repoints database instances pinned to a network by name. Satisfied by repositories.DatabaseRepository.

type Input

type Input struct {
	// Name is the desired unique slug handle; it is normalized to canonical slug
	// form. DisplayName is the free-text label (falls back to Name when blank).
	Name        string
	DisplayName string
	Driver      string
	Internal    bool
}

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

type Resolver interface {
	For(serverID uint) (docker.Client, error)
}

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

type Servers interface {
	List() ([]models.Server, error)
}

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) Create

func (s *Service) Create(ctx context.Context, workspaceID uint, in Input) (*models.Network, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, workspaceID, id uint) error

func (*Service) EnsureDefault

func (s *Service) EnsureDefault(ctx context.Context, workspaceID uint) (*models.Network, error)

EnsureDefault creates the workspace's default network if it has none.

func (*Service) Get

func (s *Service) Get(workspaceID, id uint) (*models.Network, error)

func (*Service) List

func (s *Service) List(workspaceID uint) ([]models.Network, error)

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

func (s *Service) PendingMigration() (int, error)

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

func (s *Service) SetAllocator(a *netalloc.Service)

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

func (s *Service) SetClients(r Resolver)

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.

func (*Service) SetQuota

func (s *Service) SetQuota(q *quota.Service)

SetQuota wires the plan/quota enforcer (nil-safe; nil skips checks).

Jump to

Keyboard shortcuts

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