From 107f667b876808017261f45c7140f512b627bd83 Mon Sep 17 00:00:00 2001 From: "pat@pulumi.com" Date: Thu, 12 Oct 2017 14:16:44 -0700 Subject: [PATCH 1/3] Accept a send-only event channel in Deploy and Preview. Just what it says on the tin. --- pkg/engine/deploy.go | 26 +++++++++++++------------- pkg/engine/eventsink.go | 4 ++-- pkg/engine/preview.go | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/engine/deploy.go b/pkg/engine/deploy.go index ac50bad64..8ae98dd93 100644 --- a/pkg/engine/deploy.go +++ b/pkg/engine/deploy.go @@ -29,7 +29,7 @@ type DeployOptions struct { Summary bool // true if we should only summarize resources and operations. } -func (eng *Engine) Deploy(environment tokens.QName, events chan Event, opts DeployOptions) error { +func (eng *Engine) Deploy(environment tokens.QName, events chan<- Event, opts DeployOptions) error { contract.Require(environment != tokens.QName(""), "environment") contract.Require(events != nil, "events") @@ -59,18 +59,18 @@ func (eng *Engine) Deploy(environment tokens.QName, events chan Event, opts Depl } type deployOptions struct { - Create bool // true if we are creating resources. - Destroy bool // true if we are destroying the environment. - DryRun bool // true if we should just print the plan without performing it. - Analyzers []string // an optional set of analyzers to run as part of this deployment. - Parallel int // the degree of parallelism for resource operations (<=1 for serial). - ShowConfig bool // true to show the configuration variables being used. - ShowReplacementSteps bool // true to show the replacement steps in the plan. - ShowSames bool // true to show the resources that aren't updated, in addition to those that are. - Summary bool // true if we should only summarize resources and operations. - DOT bool // true if we should print the DOT file for this plan. - Events chan Event // the channel to write events from the engine to. - Diag diag.Sink // the sink to use for diag'ing. + Create bool // true if we are creating resources. + Destroy bool // true if we are destroying the environment. + DryRun bool // true if we should just print the plan without performing it. + Analyzers []string // an optional set of analyzers to run as part of this deployment. + Parallel int // the degree of parallelism for resource operations (<=1 for serial). + ShowConfig bool // true to show the configuration variables being used. + ShowReplacementSteps bool // true to show the replacement steps in the plan. + ShowSames bool // true to show the resources that aren't updated, in addition to those that are. + Summary bool // true if we should only summarize resources and operations. + DOT bool // true if we should print the DOT file for this plan. + Events chan<- Event // the channel to write events from the engine to. + Diag diag.Sink // the sink to use for diag'ing. } func (eng *Engine) deployLatest(info *planContext, opts deployOptions) error { diff --git a/pkg/engine/eventsink.go b/pkg/engine/eventsink.go index c421533d8..4d7b68ed2 100644 --- a/pkg/engine/eventsink.go +++ b/pkg/engine/eventsink.go @@ -14,7 +14,7 @@ import ( "github.com/pulumi/pulumi/pkg/util/contract" ) -func newEventSink(events chan Event, opts diag.FormatOptions) diag.Sink { +func newEventSink(events chan<- Event, opts diag.FormatOptions) diag.Sink { contract.Require(events != nil, "events") return &eventSink{ @@ -28,7 +28,7 @@ const eventSinkIDPrefix = "PU" // eventSink is a sink which writes all events to a channel type eventSink struct { - events chan Event // the channel to emit events into. + events chan<- Event // the channel to emit events into. opts diag.FormatOptions // a set of options that control output style and content. counts map[diag.Severity]int // the number of messages that have been issued per severity. mutex sync.RWMutex // a mutex for guarding updates to the counts map diff --git a/pkg/engine/preview.go b/pkg/engine/preview.go index ec0c7c45d..bd6de8eab 100644 --- a/pkg/engine/preview.go +++ b/pkg/engine/preview.go @@ -19,7 +19,7 @@ type PreviewOptions struct { Summary bool // true if we should only summarize resources and operations. } -func (eng *Engine) Preview(environment tokens.QName, events chan Event, opts PreviewOptions) error { +func (eng *Engine) Preview(environment tokens.QName, events chan<- Event, opts PreviewOptions) error { contract.Require(environment != tokens.QName(""), "environment") contract.Require(events != nil, "events") From 73bb5851c8ae275a3143ee1b4925732dd0d43239 Mon Sep 17 00:00:00 2001 From: "pat@pulumi.com" Date: Thu, 12 Oct 2017 14:20:01 -0700 Subject: [PATCH 2/3] Accept a receive-only channel in displayEvents. --- cmd/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/util.go b/cmd/util.go index d82e65860..255807533 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -71,7 +71,7 @@ func setCurrentEnv(name tokens.QName, verify bool) error { // displayEvents reads events from the `events` channel until it is closed, displaying each event as it comes in. // Once all events have been read from the channel and displayed, it closes the `done` channel so the caller can // await all the events being written. -func displayEvents(events chan engine.Event, done chan bool, debug bool) { +func displayEvents(events <-chan engine.Event, done chan bool, debug bool) { defer close(done) for event := range events { From aaf46c12f407ba87e665511633c5468600f9be5a Mon Sep 17 00:00:00 2001 From: Pat Gavlin Date: Fri, 13 Oct 2017 10:12:09 -0700 Subject: [PATCH 3/3] Narrow destroy events as well. --- pkg/engine/destroy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/engine/destroy.go b/pkg/engine/destroy.go index a07767c17..bf38ca550 100644 --- a/pkg/engine/destroy.go +++ b/pkg/engine/destroy.go @@ -15,7 +15,7 @@ type DestroyOptions struct { Summary bool } -func (eng *Engine) Destroy(environment tokens.QName, events chan Event, opts DestroyOptions) error { +func (eng *Engine) Destroy(environment tokens.QName, events chan<- Event, opts DestroyOptions) error { contract.Require(environment != tokens.QName(""), "environment") info, err := eng.planContextFromEnvironment(environment, opts.Package)