sysdeploy

package
v0.0.0-...-2d4ef54 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const GatewayConflictWindow = 5 * time.Minute

Variables

View Source
var ErrInvalidTopology = errors.New("invalid host topology")

Functions

func ValidateEventBusNATSURL

func ValidateEventBusNATSURL(raw string) (*url.URL, error)

ValidateEventBusNATSURL 要求地址只含 tls 协议、主机和端口。

Types

type DeploymentRecord

type DeploymentRecord struct {
	HostID      string    `gorm:"column:c_host_id;primaryKey"`
	ComponentID string    `gorm:"column:c_component_id;primaryKey"`
	Status      string    `gorm:"column:c_status"`
	CreatedAt   time.Time `gorm:"column:c_ctime;autoCreateTime"`
	UpdatedAt   time.Time `gorm:"column:c_mtime;autoUpdateTime"`
}

func (DeploymentRecord) TableName

func (DeploymentRecord) TableName() string

type EventBusEndpoint

type EventBusEndpoint struct {
	// HostID 是 EventBus 当前部署的主机。
	HostID string
	// URL 是其他主机访问用的对外地址:tls://<主机地址>:<目录里的端口>。
	URL string
}

EventBusEndpoint 是控制面登记的 EventBus 所在位置。

func ResolveEventBusEndpoint

func ResolveEventBusEndpoint(ctx context.Context, db *gorm.DB, controlHostID string) (EventBusEndpoint, error)

ResolveEventBusEndpoint 按组件部署找出 EventBus 的位置。EventBus 可能不在 Admin 所在的主机上,所以地址跟随部署, 并要求恰好一个启用的部署;签发凭据和代为维护都不改动拓扑。

type HostGatewayStatus

type HostGatewayStatus struct {
	HostID             string     `gorm:"column:c_host_id;primaryKey"`
	InstanceID         string     `gorm:"column:c_instance_id"`
	Version            string     `gorm:"column:c_version"`
	ExpectedHash       string     `gorm:"column:c_expected_hash"`
	AppliedHash        string     `gorm:"column:c_applied_hash"`
	RouteCount         int64      `gorm:"column:c_route_count"`
	LastSeenAt         *time.Time `gorm:"column:c_last_seen_at"`
	LastError          string     `gorm:"column:c_last_error"`
	PreviousInstanceID string     `gorm:"column:c_previous_instance_id"`
	ReplacedAt         *time.Time `gorm:"column:c_replaced_at"`
	ConflictInstanceID string     `gorm:"column:c_conflict_instance_id"`
	ConflictSeenAt     *time.Time `gorm:"column:c_conflict_seen_at"`
	// RelaySessions 是 control 网关上报的反向连接会话(JSON 数组),其他主机为空。
	RelaySessions string `gorm:"column:c_relay_sessions"`
}

func (*HostGatewayStatus) ClearExpiredConflict

func (s *HostGatewayStatus) ClearExpiredConflict(now time.Time)

ClearExpiredConflict gives readers the same expiry even when an offline gateway sends no further heartbeat. The next status write persists it.

func (HostGatewayStatus) TableName

func (HostGatewayStatus) TableName() string

type HostRecord

type HostRecord struct {
	HostID         string `gorm:"column:c_host_id;primaryKey"`
	Label          string `gorm:"column:c_label"`
	Address        string `gorm:"column:c_address"`
	PrivateAddress string `gorm:"column:c_private_address"`
	Region         string `gorm:"column:c_region"`
	Status         string `gorm:"column:c_status"`
	Reachability   string `gorm:"column:c_reachability"`
	Description    string `gorm:"column:c_description"`
	// SSHPort 为 0 表示控制台不能 SSH;指纹由 SSH 服务首次连接时写回,同步不会改它。
	SSHPort        int       `gorm:"column:c_ssh_port"`
	SSHUser        string    `gorm:"column:c_ssh_user"`
	SSHFingerprint string    `gorm:"column:c_ssh_fingerprint"`
	CreatedAt      time.Time `gorm:"column:c_ctime;autoCreateTime"`
	UpdatedAt      time.Time `gorm:"column:c_mtime;autoUpdateTime"`
}

func (HostRecord) TableName

func (HostRecord) TableName() string

type HostSpec

type HostSpec struct {
	HostID         string
	Label          string
	Address        string
	PrivateAddress string
	// Reachability 为空或 direct 表示可直达,outbound 表示只能出站。
	Reachability string
	Region       string
	Description  string
	Components   []string
	// SSH 为空表示控制台不能 SSH 到这台主机,已存的凭据同时被清除。
	SSH *SSHSpec
}

HostSpec contains deployment input, not runtime status. Synchronization keeps the existing host and deployment enablement values.

type SSHSpec

type SSHSpec struct {
	Port       int
	User       string
	Password   string
	PrivateKey string
	Passphrase string
}

SSHSpec 是主机的 SSH 登录信息。凭据明文只在写入事务里使用,加密后存进 t_secrets。

type Service

type Service interface{ pb.SysDeployService }

type ServiceImpl

type ServiceImpl struct {
	pb.UnimplementedSysDeploy
	// contains filtered or unexported fields
}

func NewService

func NewService(dbManager *database.Manager, adminNodeID string) *ServiceImpl

func (*ServiceImpl) DeleteHost

func (*ServiceImpl) GetCatalog

func (*ServiceImpl) GetDirectory

func (s *ServiceImpl) GetDirectory(ctx context.Context, _ *pb.GetDirectoryReq) (*pb.GetDirectoryRsp, error)

func (*ServiceImpl) GetHostRoutes

func (s *ServiceImpl) GetHostRoutes(ctx context.Context, req *pb.GetHostRoutesReq) (*pb.GetHostRoutesRsp, error)

func (*ServiceImpl) ListDeployments

func (s *ServiceImpl) ListDeployments(ctx context.Context, req *pb.ListDeploymentsReq) (*pb.ListDeploymentsRsp, error)

func (*ServiceImpl) ListHosts

func (*ServiceImpl) SetDeploymentStatus

func (s *ServiceImpl) SetDeploymentStatus(ctx context.Context, req *pb.SetDeploymentStatusReq) (*pb.SetDeploymentStatusRsp, error)

func (*ServiceImpl) SetHostStatus

func (s *ServiceImpl) SetHostStatus(ctx context.Context, req *pb.SetHostStatusReq) (*pb.SetHostStatusRsp, error)

func (*ServiceImpl) SetSessionCloser

func (s *ServiceImpl) SetSessionCloser(closer SessionCloser)

SetSessionCloser 接入 SSH 服务:主机的连接信息变化或主机被删除后,关闭它在线的会话。

func (*ServiceImpl) SyncHostDeployments

func (s *ServiceImpl) SyncHostDeployments(ctx context.Context, req *pb.SyncHostDeploymentsReq) (*pb.SyncHostDeploymentsRsp, error)

type SessionCloser

type SessionCloser interface{ CloseHostSessions(hostID string) }

SessionCloser 关闭某台主机上所有在线的终端与文件会话。

type TopologyDAO

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

TopologyDAO is shared by the live API and offline bootstrap/recovery commands. It never creates schema or seeds deployments during Admin startup.

func NewTopologyDAO

func NewTopologyDAO(db *gorm.DB, controlHostID string) (*TopologyDAO, error)

func (*TopologyDAO) Compile

func (d *TopologyDAO) Compile(ctx context.Context, hostID string) (servicecatalog.CompiledHost, error)

func (*TopologyDAO) CompileSnapshot

func (d *TopologyDAO) CompileSnapshot(ctx context.Context, hostID, encryptionKey string) (servicecatalog.CompiledHost, *pb.HostGatewaySnapshot, error)

CompileSnapshot reads topology and verifier keys in one SQLite snapshot. Missing or corrupt master copies fail closed; reads never provision keys.

func (*TopologyDAO) DeleteHost

func (d *TopologyDAO) DeleteHost(ctx context.Context, hostID string) error

func (*TopologyDAO) GetGatewayStatus

func (d *TopologyDAO) GetGatewayStatus(ctx context.Context, hostID string) (*HostGatewayStatus, error)

func (*TopologyDAO) Read

func (d *TopologyDAO) Read(ctx context.Context) (hosts []HostRecord, deployments []DeploymentRecord, err error)

Read returns a consistent configuration snapshot. Runtime heartbeats are read separately so frequent status writes do not alter the compiled directory.

func (*TopologyDAO) SetDeploymentStatus

func (d *TopologyDAO) SetDeploymentStatus(ctx context.Context, hostID, componentID, status string) error

func (*TopologyDAO) SetHostStatus

func (d *TopologyDAO) SetHostStatus(ctx context.Context, hostID, status string) error

func (*TopologyDAO) SyncHostDeployments

func (d *TopologyDAO) SyncHostDeployments(ctx context.Context, spec HostSpec) error

func (*TopologyDAO) SyncHosts

func (d *TopologyDAO) SyncHosts(ctx context.Context, specs []HostSpec) error

SyncHosts supports offline bootstrap of a complete fleet in one transaction. A live synchronization uses SyncHostDeployments for exactly one host.

func (*TopologyDAO) WithEncryptionKeyFunc

func (d *TopologyDAO) WithEncryptionKeyFunc(fn func() (string, error)) *TopologyDAO

WithEncryptionKeyFunc 指定取得 SSH 凭据主密钥的方式,离线 bootstrap 在进程环境之外使用。 主机拓扑校验通过、真正要写凭据时才会调用,所以拓扑非法时不会因此创建主密钥。

Directories

Path Synopsis
Package rpc exposes SysDeploy through tRPC while keeping business logic in sysdeploy.Service.
Package rpc exposes SysDeploy through tRPC while keeping business logic in sysdeploy.Service.

Jump to

Keyboard shortcuts

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