forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller.go
72 lines (58 loc) · 1.95 KB
/
controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
}