Skip to content

Commit

Permalink
✨ Plug DryRunWrapper into client and manager constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaroaleman committed Mar 5, 2020
1 parent 4484d6e commit 535b63c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -87,6 +90,10 @@ func New(config *rest.Config, options Options) (Client, error) {
},
}

if options.DryRun {
return NewDryRunClient(c), nil
}

return c, nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 535b63c

Please sign in to comment.