diff --git a/vendor.conf b/vendor.conf index 7ffc3a57..85785139 100644 --- a/vendor.conf +++ b/vendor.conf @@ -2,5 +2,5 @@ github.com/rancher/types github.com/pkg/errors v0.8.0 -github.com/rancher/norman f5744043a6fb81330ee78e4f7a0f04d0ef65c9f1 transitive=true +github.com/rancher/norman 2da1bd2ffcacdef4bdf7e2c193d32f3b04ebd6d0 transitive=true github.com/coreos/prometheus-operator v0.25.0 diff --git a/vendor/github.com/rancher/norman/generator/controller_template.go b/vendor/github.com/rancher/norman/generator/controller_template.go index 122a74a7..123a6158 100644 --- a/vendor/github.com/rancher/norman/generator/controller_template.go +++ b/vendor/github.com/rancher/norman/generator/controller_template.go @@ -74,7 +74,9 @@ type {{.schema.CodeName}}Controller interface { Informer() cache.SharedIndexInformer Lister() {{.schema.CodeName}}Lister AddHandler(ctx context.Context, name string, handler {{.schema.CodeName}}HandlerFunc) + AddFeatureHandler(ctx context.Context, enabled func() bool, name string, sync {{.schema.CodeName}}HandlerFunc) AddClusterScopedHandler(ctx context.Context, name, clusterName string, handler {{.schema.CodeName}}HandlerFunc) + AddClusterScopedFeatureHandler(ctx context.Context, enabled func() bool, name, clusterName string, handler {{.schema.CodeName}}HandlerFunc) Enqueue(namespace, name string) Sync(ctx context.Context) error Start(ctx context.Context, threadiness int) error @@ -93,9 +95,13 @@ type {{.schema.CodeName}}Interface interface { DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error Controller() {{.schema.CodeName}}Controller AddHandler(ctx context.Context, name string, sync {{.schema.CodeName}}HandlerFunc) + AddFeatureHandler(ctx context.Context, enabled func() bool, name string, sync {{.schema.CodeName}}HandlerFunc) AddLifecycle(ctx context.Context, name string, lifecycle {{.schema.CodeName}}Lifecycle) + AddFeatureLifecycle(ctx context.Context, enabled func() bool, name string, lifecycle {{.schema.CodeName}}Lifecycle) AddClusterScopedHandler(ctx context.Context, name, clusterName string, sync {{.schema.CodeName}}HandlerFunc) + AddClusterScopedFeatureHandler(ctx context.Context, enabled func() bool, name, clusterName string, sync {{.schema.CodeName}}HandlerFunc) AddClusterScopedLifecycle(ctx context.Context, name, clusterName string, lifecycle {{.schema.CodeName}}Lifecycle) + AddClusterScopedFeatureLifecycle(ctx context.Context, enabled func() bool, name, clusterName string, lifecycle {{.schema.CodeName}}Lifecycle) } type {{.schema.ID}}Lister struct { @@ -156,6 +162,20 @@ func (c *{{.schema.ID}}Controller) AddHandler(ctx context.Context, name string, }) } +func (c *{{.schema.ID}}Controller) AddFeatureHandler(ctx context.Context, enabled func() bool, name string, handler {{.schema.CodeName}}HandlerFunc) { + c.GenericController.AddHandler(ctx, name, func(key string, obj interface{}) (interface{}, error) { + if !enabled() { + return nil, nil + } else if obj == nil { + return handler(key, nil) + } else if v, ok := obj.(*{{.prefix}}{{.schema.CodeName}}); ok { + return handler(key, v) + } else { + return nil, nil + } + }) +} + func (c *{{.schema.ID}}Controller) AddClusterScopedHandler(ctx context.Context, name, cluster string, handler {{.schema.CodeName}}HandlerFunc) { resource.PutClusterScoped({{.schema.CodeName}}GroupVersionResource) c.GenericController.AddHandler(ctx, name, func(key string, obj interface{}) (interface{}, error) { @@ -169,6 +189,21 @@ func (c *{{.schema.ID}}Controller) AddClusterScopedHandler(ctx context.Context, }) } +func (c *{{.schema.ID}}Controller) AddClusterScopedFeatureHandler(ctx context.Context, enabled func() bool, name, cluster string, handler {{.schema.CodeName}}HandlerFunc) { + resource.PutClusterScoped({{.schema.CodeName}}GroupVersionResource) + c.GenericController.AddHandler(ctx, name, func(key string, obj interface{}) (interface{}, error) { + if !enabled() { + return nil, nil + } else if obj == nil { + return handler(key, nil) + } else if v, ok := obj.(*{{.prefix}}{{.schema.CodeName}}); ok && controller.ObjectInCluster(cluster, obj) { + return handler(key, v) + } else { + return nil, nil + } + }) +} + type {{.schema.ID}}Factory struct { } @@ -264,20 +299,38 @@ func (s *{{.schema.ID}}Client) AddHandler(ctx context.Context, name string, sync s.Controller().AddHandler(ctx, name, sync) } +func (s *{{.schema.ID}}Client) AddFeatureHandler(ctx context.Context, enabled func() bool, name string, sync {{.schema.CodeName}}HandlerFunc) { + s.Controller().AddFeatureHandler(ctx, enabled, name, sync) +} + func (s *{{.schema.ID}}Client) AddLifecycle(ctx context.Context, name string, lifecycle {{.schema.CodeName}}Lifecycle) { sync := New{{.schema.CodeName}}LifecycleAdapter(name, false, s, lifecycle) s.Controller().AddHandler(ctx, name, sync) } +func (s *{{.schema.ID}}Client) AddFeatureLifecycle(ctx context.Context, enabled func() bool, name string, lifecycle {{.schema.CodeName}}Lifecycle) { + sync := New{{.schema.CodeName}}LifecycleAdapter(name, false, s, lifecycle) + s.Controller().AddFeatureHandler(ctx, enabled, name, sync) +} + func (s *{{.schema.ID}}Client) AddClusterScopedHandler(ctx context.Context, name, clusterName string, sync {{.schema.CodeName}}HandlerFunc) { s.Controller().AddClusterScopedHandler(ctx, name, clusterName, sync) } +func (s *{{.schema.ID}}Client) AddClusterScopedFeatureHandler(ctx context.Context, enabled func() bool, name, clusterName string, sync {{.schema.CodeName}}HandlerFunc) { + s.Controller().AddClusterScopedFeatureHandler(ctx, enabled, name, clusterName, sync) +} + func (s *{{.schema.ID}}Client) AddClusterScopedLifecycle(ctx context.Context, name, clusterName string, lifecycle {{.schema.CodeName}}Lifecycle) { sync := New{{.schema.CodeName}}LifecycleAdapter(name+"_"+clusterName, true, s, lifecycle) s.Controller().AddClusterScopedHandler(ctx, name, clusterName, sync) } +func (s *{{.schema.ID}}Client) AddClusterScopedFeatureLifecycle(ctx context.Context, enabled func() bool, name, clusterName string, lifecycle {{.schema.CodeName}}Lifecycle) { + sync := New{{.schema.CodeName}}LifecycleAdapter(name+"_"+clusterName, true, s, lifecycle) + s.Controller().AddClusterScopedFeatureHandler(ctx, enabled, name, clusterName, sync) +} + type {{.schema.CodeName}}Indexer func(obj *{{.prefix}}{{.schema.CodeName}}) ([]string, error) type {{.schema.CodeName}}ClientCache interface { diff --git a/vendor/github.com/rancher/norman/types/types.go b/vendor/github.com/rancher/norman/types/types.go index 9edfd764..1d729ac5 100644 --- a/vendor/github.com/rancher/norman/types/types.go +++ b/vendor/github.com/rancher/norman/types/types.go @@ -114,6 +114,7 @@ type Schema struct { CollectionFilters map[string]Filter `json:"collectionFilters,omitempty"` DynamicSchemaVersion string `json:"dynamicSchemaVersion,omitempty"` Scope TypeScope `json:"-"` + Enabled func() bool `json:"-"` InternalSchema *Schema `json:"-"` Mapper Mapper `json:"-"`