Help us shape the future of Go! Take the 2026 Go Developer Survey

substrate

package
v0.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package substrate 是 Docker/Swarm 底座的 moby/client 适配器:把 state.DockerClient 端口翻译为 Docker Engine API 调用。第三方类型 (moby/swarm 结构体)只存在于本包内部,出口一律是核心类型 (state.SubstrateNode / state.ObjectVersion / state.SubstrateEvent), 错误归一为端口哨兵(state.ErrObjectNotFound / ErrVersionConflict / ErrNotSwarmManager)——架构 §2.8 核心不出现第三方概念。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client 是 state.DockerClient 的 moby/client 实现。

func NewClient

func NewClient(host string) (*Client, error)

NewClient 构造底座客户端。host 为空时按惯例解析:DOCKER_HOST 环境变量 优先,缺省本机套接字(linux unix socket / Windows named pipe)。API 版本协商在 moby client v0.6+ 默认开启(Engine 门禁 ≥29.8.1 由安装检查 负责,客户端侧不钉死)。

func (*Client) Close

func (c *Client) Close() error

Close 释放底层连接。

func (*Client) EnsureContainerRunning

func (c *Client) EnsureContainerRunning(ctx context.Context, spec build.DaemonSpec) error

EnsureContainerRunning 实现 build.DaemonManager 端口:把容器收敛到 「存在且运行」(镜像缺失拉取 → 容器缺失创建 → 未运行启动;已在运行 no-op)。镜像钉版变化不重建既有容器(v0.1 保守:平台不偷偷替换用户宿主 上的长驻容器——升级走文档化的人工删除动作,下次 Ensure 按新镜像重建)。

func (*Client) EnsureImagePresent

func (c *Client) EnsureImagePresent(ctx context.Context, image string) error

EnsureImagePresent 实现 build.DaemonManager 端口:确保镜像在本机存在 (缺失时拉取并排空响应流;幂等)。

func (*Client) EnsureVolumePresent

func (c *Client) EnsureVolumePresent(ctx context.Context, name string) error

EnsureVolumePresent 实现 build.DaemonManager 端口:确保命名卷存在 (幂等;卷已存在即 no-op)。

func (*Client) ImageDigest

func (c *Client) ImageDigest(ctx context.Context, ref string) (string, error)

ImageDigest 实现 engine.ImageChecker:返回用于 digest 钉定的不可变摘要。 优先取 RepoDigests 的清单摘要(swarm 分发解析只接受 manifest digest—— 实测钉配置 ID 会得到 "manifest schema unsupported" 任务拒绝);本机构建 镜像(buildkit tar 装载、免 registry)无清单摘要,返回空串由引擎按引用 直用(tag 形态;镜像不被平台自动清理,builds 行留有 digest 台账)。 缺失归一为 engine.ErrImageMissing。

func (*Client) InspectImage

func (c *Client) InspectImage(ctx context.Context, ref string) (build.ImageInfo, error)

InspectImage 实现 build.ImageSource 端口:返回本机镜像 ID(不可变配置 摘要,D9 部署引用形态);缺失归一为 build.ErrImageNotFound。

func (*Client) ListNodeObservations

func (c *Client) ListNodeObservations(ctx context.Context) ([]state.SubstrateNode, error)

ListNodeObservations 返回全量节点快照(逐字镜像底座语义,平台不加工)。

func (*Client) LoadImage

func (c *Client) LoadImage(ctx context.Context, dockerTar io.Reader) error

LoadImage 实现 build.ImageSource 端口:把 docker-format tar 流装入本机 daemon(构建产物落本机;响应流必须排空——流未读完装载未完成)。

func (*Client) ManagedServiceProcesses

func (c *Client) ManagedServiceProcesses(ctx context.Context, app string) ([]string, error)

ManagedServiceProcesses 返回指定应用的受管服务 compose 进程名集 (label 过滤 fleetly.managed=true + fleetly.app=<app>,取 fleetly.process label;字典序稳定)。日志采集的 per-app 服务发现入口 (T2.20);平台外同名服务不进结果。

func (*Client) NetworkEnsure

func (c *Client) NetworkEnsure(ctx context.Context, name string) error

NetworkEnsure 确认 overlay 网络存在(幂等:已有即 no-op;缺失创建—— 每应用专属 overlay 网络,architecture §2.4 服务命名与网络行)。

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping 实现端口探测。

func (*Client) RemoveImage

func (c *Client) RemoveImage(ctx context.Context, ref string) error

RemoveImage 按引用删除镜像(显式管理动作;平台永不自动调用—— build/imagestore.go 清理策略)。

func (*Client) ResolveObjectVersion

func (c *Client) ResolveObjectVersion(ctx context.Context, kind state.ObjectKind, id string) (state.ObjectVersion, error)

ResolveObjectVersion 直读底座对象版本(node/service 两类)。

func (*Client) SelfNodeID

func (c *Client) SelfNodeID(ctx context.Context) (string, error)

SelfNodeID 返回本机 Swarm node ID;未启用 Swarm 返回 state.ErrNotSwarmManager。

func (*Client) ServiceCreate

func (c *Client) ServiceCreate(ctx context.Context, spec engine.ServiceSpec) error

ServiceCreate 实现 engine.Substrate:创建服务(调用方对账保证仅缺失时 调用;已存在不覆盖——按 ErrObjectConflict 语义失败暴露竞态)。

func (*Client) ServiceInspect

func (c *Client) ServiceInspect(ctx context.Context, name string) (engine.ServiceState, error)

ServiceInspect 实现 engine.Substrate:按名取服务实况投影。

func (*Client) ServiceList

func (c *Client) ServiceList(ctx context.Context, labels map[string]string) ([]engine.ServiceState, error)

ServiceList 实现 engine.Substrate:按 label 选择器返回服务投影。

func (*Client) ServiceRemove

func (c *Client) ServiceRemove(ctx context.Context, name string) error

ServiceRemove 实现 engine.Substrate:删除服务(省略=删除;幂等——缺失 视为成功,对账重放的常见形态)。

func (*Client) ServiceUpdate

func (c *Client) ServiceUpdate(ctx context.Context, name string, spec engine.ServiceSpec) error

ServiceUpdate 实现 engine.Substrate:读当前版本 → 以目标 spec 推进。 ForceUpdate 恒不递增(归位零成本,Spike B2)。并发冲突短重试。

func (*Client) StreamServiceLogs

func (c *Client) StreamServiceLogs(ctx context.Context, service string, since time.Time, follow bool) (<-chan LogLine, error)

StreamServiceLogs 打开 Swarm 服务日志流(service 传 Swarm 服务名, fleetly 命名 = naming.ServiceName(app, service))。follow=false 时读至 流自然结束(配合 since 做轮询拉取);follow=true 持续跟随。since 非零 时只取该时刻之后的行。返回 channel 在流结束、出错或 ctx 取消时关闭 (错误语义:日志流尽力而为,故障由采集器下轮重试,不单独暴露错误通道)。 服务不存在 / 底座不可达按 state 端口哨兵归类(mapSubstrateErr)。

func (*Client) SubscribeEvents

func (c *Client) SubscribeEvents(ctx context.Context) (<-chan state.SubstrateEvent, error)

SubscribeEvents 订阅底座事件流:仅转发 node/service/task 类事件(观测 缓存失效信号),channel 在 ctx 取消或流结束时关闭。

func (*Client) SwarmReady

func (c *Client) SwarmReady(ctx context.Context) error

SwarmReady 确认本机为 active swarm manager:未 init / 非 manager 返回 errors.Is(err, engine.ErrNotSwarmReady)(engine 据此映射 E_RUNTIME_UNAVAILABLE + swarm init 建议)。

func (*Client) TagImage

func (c *Client) TagImage(ctx context.Context, source, target string) error

TagImage 给既有镜像打新 tag(镜像身份操作;preflight 实机工作流与镜像 管理面使用)。

func (*Client) TaskList

func (c *Client) TaskList(ctx context.Context, serviceName string) ([]engine.TaskState, error)

TaskList 实现 engine.Substrate:返回服务的全部任务(service ps 语义)。

func (*Client) UpdateNodeLabel

func (c *Client) UpdateNodeLabel(ctx context.Context, swarmNodeID, key, value string, expected state.ObjectVersion) error

UpdateNodeLabel 以乐观令牌更新节点 label:幂等(label 已是目标值时 no-op);令牌失效返回 state.ErrVersionConflict。

type LogLine

type LogLine struct {
	// At 是 Docker 侧记录时间(timestamps=true 头部解析;解析失败取零值,
	// 调用方可回退本机时钟)。
	At time.Time
	// Stderr 报告该行来自 stderr 多路复用通道。
	Stderr bool
	// Line 是剥离时间戳头部后的原始内容(尾部换行已去除)。
	Line string
}

LogLine 是服务日志单行(核心类型)。

Jump to

Keyboard shortcuts

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