37 Star 403 Fork 75

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
controller.go 1.95 KB
一键复制 编辑 原始数据 按行查看 历史
package usercontrollers
import (
"context"
"github.com/rancher/rancher/pkg/clustermanager"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
)
/*
RegisterLate registers ClusterLifecycle controller which is responsible for starting rancher agent in user cluster,
and registering k8s controllers, on cluster.update
*/
func RegisterLate(ctx context.Context, management *config.ManagementContext, manager *clustermanager.Manager) {
lifecycle := &ClusterLifecycle{
Manager: manager,
ctx: ctx,
}
clusterClient := management.Management.Clusters("")
clusterClient.AddLifecycle("cluster-agent-controller", lifecycle)
}
/*
RegisterEarly registers ClusterLifecycleCleanup controller which is responsible for stopping rancher agent in user cluster,
and de-registering k8s controllers, on cluster.remove
*/
func RegisterEarly(ctx context.Context, management *config.ManagementContext, manager *clustermanager.Manager) {
lifecycle := &ClusterLifecycleCleanup{
Manager: manager,
ctx: ctx,
}
clusterClient := management.Management.Clusters("")
clusterClient.AddLifecycle("cluster-agent-controller-cleanup", lifecycle)
}
type ClusterLifecycle struct {
Manager *clustermanager.Manager
ctx context.Context
}
type ClusterLifecycleCleanup struct {
Manager *clustermanager.Manager
ctx context.Context
}
func (c *ClusterLifecycle) Create(obj *v3.Cluster) (*v3.Cluster, error) {
return nil, nil
}
func (c *ClusterLifecycle) Remove(obj *v3.Cluster) (*v3.Cluster, error) {
return nil, nil
}
func (c *ClusterLifecycle) Updated(obj *v3.Cluster) (*v3.Cluster, error) {
return nil, c.Manager.Start(c.ctx, obj)
}
func (c *ClusterLifecycleCleanup) Create(obj *v3.Cluster) (*v3.Cluster, error) {
return nil, nil
}
func (c *ClusterLifecycleCleanup) Remove(obj *v3.Cluster) (*v3.Cluster, error) {
c.Manager.Stop(obj)
return nil, nil
}
func (c *ClusterLifecycleCleanup) Updated(obj *v3.Cluster) (*v3.Cluster, error) {
return nil, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.7-rc2

搜索帮助