Documentation
¶
Index ¶
- func FromSlashForHost(p string) string
- func IsRuntimeMonitoring(runtimeID string) bool
- func IsWindowsHostPath(p string) bool
- func MarkIfNotMonitoring(runtimeID string) bool
- func MarkRuntimeMonitoring(runtimeID string)
- func RuntimeMonitoringSnapshot() map[string]int
- func SetMonitoringRegistry(reg MonitoringRegistry)
- func ToContainerPath(p string) string
- func ToHostPath(containerPath, windowsDrivePrefix string) string
- func UnmarkRuntimeMonitoring(runtimeID string)
- type MonitoringRegistry
- type Registry
- type Runtime
- type RuntimeDescriber
- type RuntimeDescription
- type RuntimeEvent
- type RuntimeEventHandler
- type RuntimeHealth
- type RuntimeHealthChecker
- type RuntimeImageManager
- type RuntimeInspection
- type RuntimeInspector
- type RuntimeMonitor
- type RuntimeTerminal
- type TerminalOptions
- type TerminalSession
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromSlashForHost ¶ added in v0.2.0
FromSlashForHost 把可能存在的正斜杠宿主路径转成当前操作系统习惯的分隔符。 Windows 上返回 C:\a\b,Linux 上返回 /a/b,可直接给 filepath/os 使用。
func IsRuntimeMonitoring ¶
IsRuntimeMonitoring reports whether runtimeID is currently monitored.
func IsWindowsHostPath ¶ added in v0.2.0
IsWindowsHostPath 报告 p 是否是 Windows 宿主路径(含盘符或 UNC 前缀)。
仅凭字符串判断而不看 runtime.GOOS,原因是:
- 路径可能来自数据库 / 配置文件 / 前端表单,由别的操作系统写入;
- Docker bind 语法的转义规则只取决于「宿主是 Windows 还是 Unix」, 而宿主形态可以从路径本身看出来。
func MarkIfNotMonitoring ¶
MarkIfNotMonitoring atomically marks runtimeID as monitored if it is not already. Returns true if the runtimeID was newly marked.
func MarkRuntimeMonitoring ¶
func MarkRuntimeMonitoring(runtimeID string)
MarkRuntimeMonitoring marks runtimeID as actively monitored. It is reference-counted so multiple monitor goroutines for the same runtimeID can coexist safely.
func RuntimeMonitoringSnapshot ¶
RuntimeMonitoringSnapshot returns a copy of the process-global monitoring table. Key is runtimeID and value is monitoring reference count.
func SetMonitoringRegistry ¶
func SetMonitoringRegistry(reg MonitoringRegistry)
SetMonitoringRegistry replaces the process-global monitoring registry. Passing nil is ignored.
func ToContainerPath ¶ added in v0.2.0
ToContainerPath 把宿主路径转成容器内的 POSIX 路径。
容器(linux 镜像)里没有盘符概念,所以 Windows 宿主路径需要重写成容器路径:
- 盘符前缀 C:\ / C:/ 去掉,反斜杠换成 /,例如 D:\workspace\go-project\gobrave\.gobrave → /workspace/go-project/gobrave/.gobrave
- UNC 路径 \\server\share\dir → //server/share/dir
已经是 POSIX 路径(Linux/macOS 宿主)时原样返回,保证 Linux 行为零变化。
func ToHostPath ¶ added in v0.2.0
ToHostPath 把容器路径映射回宿主路径(Windows 时需要 C:/... 形式)。
func UnmarkRuntimeMonitoring ¶
func UnmarkRuntimeMonitoring(runtimeID string)
UnmarkRuntimeMonitoring releases one monitoring reference for runtimeID.
Types ¶
type MonitoringRegistry ¶
type MonitoringRegistry interface {
Mark(runtimeID string)
Unmark(runtimeID string)
IsMonitoring(runtimeID string) bool
MarkIfNotMonitoring(runtimeID string) bool
Snapshot() map[string]int
}
MonitoringRegistry abstracts runtime monitoring membership operations. Implementations can be in-memory, Redis-backed, etc.
func NewInMemoryMonitoringRegistry ¶
func NewInMemoryMonitoringRegistry() MonitoringRegistry
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *Registry
type Runtime ¶
type Runtime interface {
Name() string
Create(ctx context.Context, spec *types.ContainerSpec) (string, error)
Start(ctx context.Context, runtimeID string) error
Stop(ctx context.Context, runtimeID string) error
Pause(ctx context.Context, runtimeID string) error
Resume(ctx context.Context, runtimeID string) error
Delete(ctx context.Context, runtimeID string) error
Logs(ctx context.Context, runtimeID string, tail int) (string, error)
SetEventHandler(handler RuntimeEventHandler)
Exec(ctx context.Context, runtimeID string, cmd []string) (string, error)
}
type RuntimeDescriber ¶ added in v0.1.4
type RuntimeDescriber interface {
Describe(ctx context.Context, runtimeID string) (*RuntimeDescription, error)
}
RuntimeDescriber 是可选扩展接口。实现该接口的运行时可通过 runtimeID 返回 资源的详情(docker inspect / kubectl describe)。
type RuntimeDescription ¶ added in v0.1.4
type RuntimeDescription struct {
// Kind 标识资源类型,例如 container / deployment / job / service。
Kind string `json:"kind"`
// Name 资源名称(docker 容器名,或 k8s workload/service 名)。
Name string `json:"name"`
// Format 描述 Raw 的格式,便于前端渲染,例如 json / yaml / text。
Format string `json:"format"`
// Raw 原始 inspect/describe 输出,保持后端运行时的原生格式。
Raw string `json:"raw"`
}
RuntimeDescription 描述一个运行时的详情信息(对应 docker inspect / kubectl describe)。
type RuntimeEvent ¶
type RuntimeEventHandler ¶
type RuntimeEventHandler interface {
OnEvent(event RuntimeEvent)
}
type RuntimeHealth ¶ added in v0.2.2
type RuntimeHealth struct {
// Name 运行时名称(docker / k8s / k3s)。
Name string `json:"name"`
// Registered 是否在运行时注册表中(即启动装配阶段是否成功注册)。
Registered bool `json:"registered"`
// Healthy 依赖探测是否通过;未注册时必然为 false。
Healthy bool `json:"healthy"`
// Checkable 运行时是否实现了 RuntimeHealthChecker(false 表示只做了注册检查)。
Checkable bool `json:"checkable"`
// Error 检测失败原因,正常时为空。
Error string `json:"error,omitempty"`
}
RuntimeHealth 描述运行时注册 / 可用性检测结果。
type RuntimeHealthChecker ¶ added in v0.2.2
type RuntimeHealthChecker interface {
// HealthCheck 探测运行时依赖是否可用;返回 error 表示不可用(包含具体原因)。
// ctx 由调用方设置超时,实现应尽量快速返回。
HealthCheck(ctx context.Context) error
}
RuntimeHealthChecker 是可选扩展接口:运行时探测自身依赖(docker daemon / k8s apiserver) 是否可用,供启动自检与配置检测接口使用。未实现该接口的运行时按「已注册即正常」处理。
type RuntimeImageManager ¶
type RuntimeImageManager interface {
EnsureImage(ctx context.Context, image string, pullPolicy string) error
}
RuntimeImageManager is an optional extension interface for runtime-side image lifecycle operations used by ImageManager.
type RuntimeInspection ¶
RuntimeInspection carries runtime-specific inspect data used by manager/service.
type RuntimeInspector ¶
type RuntimeInspector interface {
Inspect(ctx context.Context, runtimeID string) (*RuntimeInspection, error)
}
RuntimeInspector is an optional extension interface. Implementations can expose inspect metadata (such as container internal IP) without forcing all runtimes.
type RuntimeMonitor ¶
RuntimeMonitor is an optional extension interface for reconnecting runtime lifecycle monitoring after process restarts.
type RuntimeTerminal ¶ added in v0.2.0
type RuntimeTerminal interface {
OpenTerminal(ctx context.Context, runtimeID string, opts TerminalOptions) (TerminalSession, error)
}
RuntimeTerminal 是可选扩展接口:支持交互式 exec 的运行时实现它。
它与 Runtime.Exec 的区别:Exec 是非交互式的一次性命令(无 stdin / 无 TTY), 这里则等价于 `kubectl exec -it` / `docker exec -it`。