From 73518bbe200e384893cc4b232fb765da40a433d2 Mon Sep 17 00:00:00 2001 From: Mikhail Mazurskiy Date: Thu, 16 Mar 2023 16:07:45 +1100 Subject: [PATCH] Allow to pass watcher strategy --- pkg/apply/applier.go | 7 ++++++- pkg/apply/taskrunner/runner.go | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/apply/applier.go b/pkg/apply/applier.go index 75b30b6a..cf1cd798 100644 --- a/pkg/apply/applier.go +++ b/pkg/apply/applier.go @@ -242,7 +242,8 @@ func (a *Applier) Run(ctx context.Context, invInfo inventory.Info, objects objec runner := taskrunner.NewTaskStatusRunner(allIds, statusWatcher) klog.V(4).Infoln("applier running TaskStatusRunner...") err = runner.Run(ctx, taskContext, taskQueue.ToChannel(), taskrunner.Options{ - EmitStatusEvents: options.EmitStatusEvents, + EmitStatusEvents: options.EmitStatusEvents, + WatcherRESTScopeStrategy: options.WatcherRESTScopeStrategy, }) if err != nil { handleError(eventChannel, err) @@ -288,6 +289,10 @@ type ApplierOptions struct { // ValidationPolicy defines how to handle invalid objects. ValidationPolicy validation.Policy + + // RESTScopeStrategy specifies which strategy to use when listing and + // watching resources. By default, the strategy is selected automatically. + WatcherRESTScopeStrategy watcher.RESTScopeStrategy } // setDefaults set the options to the default values if they diff --git a/pkg/apply/taskrunner/runner.go b/pkg/apply/taskrunner/runner.go index c355d732..ece59ac0 100644 --- a/pkg/apply/taskrunner/runner.go +++ b/pkg/apply/taskrunner/runner.go @@ -35,6 +35,9 @@ type TaskStatusRunner struct { // the statusPoller. type Options struct { EmitStatusEvents bool + // RESTScopeStrategy specifies which strategy to use when listing and + // watching resources. By default, the strategy is selected automatically. + WatcherRESTScopeStrategy watcher.RESTScopeStrategy } // Run executes the tasks in the taskqueue, with the statusPoller running in the @@ -57,7 +60,9 @@ func (tsr *TaskStatusRunner) Run( // If taskStatusRunner.Run is cancelled, baseRunner.run will exit early, // causing the poller to be cancelled. statusCtx, cancelFunc := context.WithCancel(context.Background()) - statusChannel := tsr.StatusWatcher.Watch(statusCtx, tsr.Identifiers, watcher.Options{}) + statusChannel := tsr.StatusWatcher.Watch(statusCtx, tsr.Identifiers, watcher.Options{ + RESTScopeStrategy: opts.WatcherRESTScopeStrategy, + }) // complete stops the statusPoller, drains the statusChannel, and returns // the provided error.