代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。