diff --git a/controller/generic_controller.go b/controller/generic_controller.go index 88f2410d..51269b19 100644 --- a/controller/generic_controller.go +++ b/controller/generic_controller.go @@ -50,6 +50,7 @@ type GenericController interface { AddHandler(ctx context.Context, name string, handler HandlerFunc) HandlerCount() int Enqueue(namespace, name string) + EnqueueAfter(namespace, name string, after time.Duration) Sync(ctx context.Context) error Start(ctx context.Context, threadiness int) error } @@ -122,6 +123,16 @@ func (g *genericController) Enqueue(namespace, name string) { } } +func (g *genericController) EnqueueAfter(namespace, name string, after time.Duration) { + key := name + if namespace != "" { + key = namespace + "/" + name + } + if g.queue != nil { + g.queue.AddAfter(key, after) + } +} + func (g *genericController) AddHandler(ctx context.Context, name string, handler HandlerFunc) { t := getHandlerTransaction(ctx) if t == nil { diff --git a/generator/controller_template.go b/generator/controller_template.go index 5fc32748..115a8168 100644 --- a/generator/controller_template.go +++ b/generator/controller_template.go @@ -4,6 +4,7 @@ var controllerTemplate = `package {{.schema.Version.Version}} import ( "context" + "time" {{.importPackage}} "github.com/rancher/norman/objectclient" @@ -78,6 +79,7 @@ type {{.schema.CodeName}}Controller interface { 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) + EnqueueAfter(namespace, name string, after time.Duration) Sync(ctx context.Context) error Start(ctx context.Context, threadiness int) error }