From 9fc31ad3eba8bbdf9987fea5ce9d8a843acea53b Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Thu, 5 Mar 2020 23:16:15 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Plug=20DryRunWrapper=20into=20clien?= =?UTF-8?q?t=20and=20manager=20constructors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/client/client.go | 7 +++++++ pkg/manager/manager.go | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/pkg/client/client.go b/pkg/client/client.go index c1c4d5d691..2b1c169f3f 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -37,6 +37,9 @@ type Options struct { // Mapper, if provided, will be used to map GroupVersionKinds to Resources Mapper meta.RESTMapper + + // DryRun specifies whether dry run mode should be enforced + DryRun bool } // New returns a new Client using the provided config and Options. @@ -87,6 +90,10 @@ func New(config *rest.Config, options Options) (Client, error) { }, } + if options.DryRun { + return NewDryRunClient(c), nil + } + return c, nil } diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index 852eb787b9..dbd23d197e 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -184,6 +184,10 @@ type Options struct { // use the cache for reads and the client for writes. NewClient NewClientFunc + // DryRunClient specifies whether the client should be configured to enforce + // dryRun mode. + DryRunClient bool + // EventBroadcaster records Events emitted by the manager and sends them to the Kubernetes API // Use this to customize the event correlator and spam filter EventBroadcaster record.EventBroadcaster @@ -257,6 +261,11 @@ func New(config *rest.Config, options Options) (Manager, error) { if err != nil { return nil, err } + + if options.DryRunClient { + writeObj = client.NewDryRunClient(writeObj) + } + // Create the recorder provider to inject event recorders for the components. // TODO(directxman12): the log for the event provider should have a context (name, tags, etc) specific // to the particular controller that it's being injected into, rather than a generic one like is here.