Documentation
¶
Index ¶
- Variables
- func Run(ctx context.Context, cfg Config) error
- type Config
- type LeaderLifecycle
- func (l *LeaderLifecycle) Disable(ctx plugins.BaseContext) error
- func (l *LeaderLifecycle) Enable(ctx plugins.EnableContext) error
- func (l *LeaderLifecycle) Install(ctx plugins.InstallContext) error
- func (l *LeaderLifecycle) Start(ctx plugins.BaseContext) error
- func (l *LeaderLifecycle) StartCron(ctx plugins.BaseContext, spec string) error
- func (l *LeaderLifecycle) Stop(ctx plugins.BaseContext) error
- func (l *LeaderLifecycle) Uninstall(ctx plugins.UninstallContext) error
- func (l *LeaderLifecycle) Upgrade(ctx plugins.UpgradeContext) error
Constants ¶
This section is empty.
Variables ¶
View Source
var Metadata = plugins.Module{ Meta: plugins.Meta{ Name: modules.PluginNameLeader, Title: "多实例选举插件", Version: "1.0.0", Description: "提供多实例自动选举能力:通过 Kubernetes 原生机制完成选主。使用前请务必启用 /health/ready 就绪探针。启用后访问流量会集中到主实例。", }, Tables: []string{}, Lifecycle: &LeaderLifecycle{}, }
Metadata Leader选举插件的元信息与能力声明
Functions ¶
Types ¶
type Config ¶
type Config struct {
Namespace string
LockName string
LeaseDuration time.Duration // 租约持续时间
RenewDeadline time.Duration // 续租截止时间
RetryPeriod time.Duration // 重试周期
ClusterID string // 指定用于选举的宿主集群ID,留空时自动检测
OnStartedLeading func(ctx context.Context)
OnStoppedLeading func()
}
Config Leader选举配置 包含命名空间、锁名称、选举时长、续租截止、重试周期以及领导开始/结束回调。 要求:LeaseDuration > RenewDeadline > RetryPeriod * 3
type LeaderLifecycle ¶
type LeaderLifecycle struct {
// contains filtered or unexported fields
}
LeaderLifecycle Leader选举插件生命周期实现 负责启动Leader选举,以及在成为Leader时启动/停止平台的后台任务
func (*LeaderLifecycle) Disable ¶
func (l *LeaderLifecycle) Disable(ctx plugins.BaseContext) error
Disable 禁用Leader选举插件 禁用阶段仅打印日志;选举停止与任务收敛由 Stop 方法处理
func (*LeaderLifecycle) Enable ¶
func (l *LeaderLifecycle) Enable(ctx plugins.EnableContext) error
Enable 启用Leader选举插件 启用阶段仅打印日志,真正的后台任务由 Start 中的选举逻辑管理
func (*LeaderLifecycle) Install ¶
func (l *LeaderLifecycle) Install(ctx plugins.InstallContext) error
Install 安装Leader选举插件 该插件不涉及数据库初始化,安装阶段仅打印日志
func (*LeaderLifecycle) Start ¶
func (l *LeaderLifecycle) Start(ctx plugins.BaseContext) error
Start 启动Leader选举的后台任务(不可阻塞) 由插件管理器在系统启动时统一调用,用于启动选举并在成为Leader时执行平台任务
func (*LeaderLifecycle) StartCron ¶
func (l *LeaderLifecycle) StartCron(ctx plugins.BaseContext, spec string) error
StartCron 该插件不使用定时任务,留空实现
func (*LeaderLifecycle) Stop ¶
func (l *LeaderLifecycle) Stop(ctx plugins.BaseContext) error
Stop 停止Leader选举插件的后台任务
func (*LeaderLifecycle) Uninstall ¶
func (l *LeaderLifecycle) Uninstall(ctx plugins.UninstallContext) error
Uninstall 卸载Leader选举插件 该插件不涉及可删除的持久化资源,卸载阶段仅打印日志
func (*LeaderLifecycle) Upgrade ¶
func (l *LeaderLifecycle) Upgrade(ctx plugins.UpgradeContext) error
Upgrade 升级Leader选举插件 该插件暂无升级数据库的需求,升级阶段仅打印日志
Click to show internal directories.
Click to hide internal directories.