37 Star 407 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
controller.go 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
Daishan Peng 提交于 2018-02-15 16:00 . refactor helm
package catalog
import (
"context"
"path"
"time"
"github.com/rancher/rancher/pkg/catalog/manager"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
"github.com/sirupsen/logrus"
)
func Register(ctx context.Context, management *config.ManagementContext) {
// TODO: Get values from settings
if err := Run(ctx, "", 3600, management); err != nil {
panic(err)
}
}
func runRefresh(ctx context.Context, interval int, controller v3.CatalogController, m *manager.Manager) {
ticker := time.NewTicker(time.Duration(interval) * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
break
case <-ticker.C:
catalogs, err := m.GetCatalogs()
if err != nil {
logrus.Error(err)
continue
}
for _, catalog := range catalogs {
controller.Enqueue("", catalog.Name)
}
}
}
}
func Run(ctx context.Context, cacheRoot string, refreshInterval int, management *config.ManagementContext) error {
if cacheRoot == "" {
cacheRoot = path.Join("./management-state", "catalog-controller", "cache")
}
logrus.Infof("Starting catalog controller")
m := manager.New(management, cacheRoot)
controller := management.Management.Catalogs("").Controller()
controller.AddHandler("catalog", m.Sync)
go runRefresh(ctx, refreshInterval, controller, m)
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.4-rc1

搜索帮助