1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-16 15:21:33 +00:00

Add suport for cluster scoped controllers

Some worload controllers need to watch resoruces in the mangement plane
and react to them. But, they should only react to resources that
correspond to their cluster. This adds framework support for that.
This commit is contained in:
Craig Jellick
2018-01-15 13:38:10 -07:00
parent af105c2bc7
commit 905797b50f
4 changed files with 107 additions and 12 deletions

View File

@@ -11,8 +11,9 @@ import (
)
var (
created = "lifecycle.cattle.io/create"
finalizerKey = "controller.cattle.io/"
created = "lifecycle.cattle.io/create"
finalizerKey = "controller.cattle.io/"
ScopedFinalizerKey = "clusterscoped.controller.cattle.io/"
)
type ObjectLifecycle interface {
@@ -22,16 +23,18 @@ type ObjectLifecycle interface {
}
type objectLifecycleAdapter struct {
name string
lifecycle ObjectLifecycle
objectClient *clientbase.ObjectClient
name string
clusterScoped bool
lifecycle ObjectLifecycle
objectClient *clientbase.ObjectClient
}
func NewObjectLifecycleAdapter(name string, lifecycle ObjectLifecycle, objectClient *clientbase.ObjectClient) func(key string, obj runtime.Object) error {
func NewObjectLifecycleAdapter(name string, clusterScoped bool, lifecycle ObjectLifecycle, objectClient *clientbase.ObjectClient) func(key string, obj runtime.Object) error {
o := objectLifecycleAdapter{
name: name,
lifecycle: lifecycle,
objectClient: objectClient,
name: name,
clusterScoped: clusterScoped,
lifecycle: lifecycle,
objectClient: objectClient,
}
return o.sync
}
@@ -116,6 +119,9 @@ func (o *objectLifecycleAdapter) createKey() string {
}
func (o *objectLifecycleAdapter) constructFinalizerKey() string {
if o.clusterScoped {
return ScopedFinalizerKey + o.name
}
return finalizerKey + o.name
}