Remove the Engine type entirely.
It no longer carries any state. All of its methods are now package-level functions.
This commit is contained in:
parent
c56e716c31
commit
5f28d52e00
|
@ -31,12 +31,11 @@ type Backend interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type localBackend struct {
|
type localBackend struct {
|
||||||
d diag.Sink
|
d diag.Sink
|
||||||
engineCache map[tokens.QName]engine.Engine
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(d diag.Sink) Backend {
|
func New(d diag.Sink) Backend {
|
||||||
return &localBackend{d: d, engineCache: make(map[tokens.QName]engine.Engine)}
|
return &localBackend{d: d}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *localBackend) Name() string {
|
func (b *localBackend) Name() string {
|
||||||
|
@ -117,8 +116,7 @@ func (b *localBackend) Preview(stackName tokens.QName, pkg *pack.Package, root s
|
||||||
|
|
||||||
go displayEvents(events, done, debug)
|
go displayEvents(events, done, debug)
|
||||||
|
|
||||||
var pulumiEngine engine.Engine
|
if err = engine.Preview(update, events, opts); err != nil {
|
||||||
if err = pulumiEngine.Preview(update, events, opts); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,8 +139,7 @@ func (b *localBackend) Update(stackName tokens.QName, pkg *pack.Package, root st
|
||||||
|
|
||||||
go displayEvents(events, done, debug)
|
go displayEvents(events, done, debug)
|
||||||
|
|
||||||
var pulumiEngine engine.Engine
|
if err = engine.Deploy(update, events, opts); err != nil {
|
||||||
if err = pulumiEngine.Deploy(update, events, opts); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,8 +162,7 @@ func (b *localBackend) Destroy(stackName tokens.QName, pkg *pack.Package, root s
|
||||||
|
|
||||||
go displayEvents(events, done, debug)
|
go displayEvents(events, done, debug)
|
||||||
|
|
||||||
var pulumiEngine engine.Engine
|
if err := engine.Destroy(update, events, opts); err != nil {
|
||||||
if err := pulumiEngine.Destroy(update, events, opts); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,19 +28,19 @@ type DeployOptions struct {
|
||||||
Color colors.Colorization // How output should be colorized.
|
Color colors.Colorization // How output should be colorized.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eng *Engine) Deploy(update Update, events chan<- Event, opts DeployOptions) error {
|
func Deploy(update Update, events chan<- Event, opts DeployOptions) error {
|
||||||
contract.Require(update != nil, "update")
|
contract.Require(update != nil, "update")
|
||||||
contract.Require(events != nil, "events")
|
contract.Require(events != nil, "events")
|
||||||
|
|
||||||
defer func() { events <- cancelEvent() }()
|
defer func() { events <- cancelEvent() }()
|
||||||
|
|
||||||
info, err := eng.planContextFromUpdate(update)
|
info, err := planContextFromUpdate(update)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer info.Close()
|
defer info.Close()
|
||||||
|
|
||||||
return eng.deployLatest(info, deployOptions{
|
return deployLatest(info, deployOptions{
|
||||||
Destroy: false,
|
Destroy: false,
|
||||||
DryRun: opts.DryRun,
|
DryRun: opts.DryRun,
|
||||||
Analyzers: opts.Analyzers,
|
Analyzers: opts.Analyzers,
|
||||||
|
@ -74,8 +74,8 @@ type deployOptions struct {
|
||||||
Diag diag.Sink // the sink to use for diag'ing.
|
Diag diag.Sink // the sink to use for diag'ing.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eng *Engine) deployLatest(info *planContext, opts deployOptions) error {
|
func deployLatest(info *planContext, opts deployOptions) error {
|
||||||
result, err := eng.plan(info, opts)
|
result, err := plan(info, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ func (eng *Engine) deployLatest(info *planContext, opts deployOptions) error {
|
||||||
|
|
||||||
if opts.DryRun {
|
if opts.DryRun {
|
||||||
// If a dry run, just print the plan, don't actually carry out the deployment.
|
// If a dry run, just print the plan, don't actually carry out the deployment.
|
||||||
if err := eng.printPlan(result); err != nil {
|
if err := printPlan(result); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -15,18 +15,18 @@ type DestroyOptions struct {
|
||||||
Color colors.Colorization
|
Color colors.Colorization
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eng *Engine) Destroy(update Update, events chan<- Event, opts DestroyOptions) error {
|
func Destroy(update Update, events chan<- Event, opts DestroyOptions) error {
|
||||||
contract.Require(update != nil, "update")
|
contract.Require(update != nil, "update")
|
||||||
|
|
||||||
defer func() { events <- cancelEvent() }()
|
defer func() { events <- cancelEvent() }()
|
||||||
|
|
||||||
info, err := eng.planContextFromUpdate(update)
|
info, err := planContextFromUpdate(update)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer info.Close()
|
defer info.Close()
|
||||||
|
|
||||||
return eng.deployLatest(info, deployOptions{
|
return deployLatest(info, deployOptions{
|
||||||
Destroy: true,
|
Destroy: true,
|
||||||
DryRun: opts.DryRun,
|
DryRun: opts.DryRun,
|
||||||
Parallel: opts.Parallel,
|
Parallel: opts.Parallel,
|
||||||
|
|
|
@ -7,8 +7,6 @@ import (
|
||||||
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Engine int
|
|
||||||
|
|
||||||
// Update abstracts away information about an apply, preview, or destroy.
|
// Update abstracts away information about an apply, preview, or destroy.
|
||||||
type Update interface {
|
type Update interface {
|
||||||
// GetRoot returns the root directory for this update. This defines the scope for any filesystem resources
|
// GetRoot returns the root directory for this update. This defines the scope for any filesystem resources
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Callers must call Close on the resulting planContext once they have completed the associated planning operation
|
// Callers must call Close on the resulting planContext once they have completed the associated planning operation
|
||||||
func (eng *Engine) planContextFromUpdate(update Update) (*planContext, error) {
|
func planContextFromUpdate(update Update) (*planContext, error) {
|
||||||
contract.Require(update != nil, "update")
|
contract.Require(update != nil, "update")
|
||||||
|
|
||||||
// Create a root span for the operation
|
// Create a root span for the operation
|
||||||
|
|
|
@ -24,7 +24,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// plan just uses the standard logic to parse arguments, options, and to create a snapshot and plan.
|
// plan just uses the standard logic to parse arguments, options, and to create a snapshot and plan.
|
||||||
func (eng *Engine) plan(info *planContext, opts deployOptions) (*planResult, error) {
|
func plan(info *planContext, opts deployOptions) (*planResult, error) {
|
||||||
contract.Assert(info != nil)
|
contract.Assert(info != nil)
|
||||||
contract.Assert(info.Update != nil)
|
contract.Assert(info.Update != nil)
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ func (res *planResult) Close() error {
|
||||||
return res.Ctx.Close()
|
return res.Ctx.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eng *Engine) printPlan(result *planResult) error {
|
func printPlan(result *planResult) error {
|
||||||
// First print config/unchanged/etc. if necessary.
|
// First print config/unchanged/etc. if necessary.
|
||||||
var prelude bytes.Buffer
|
var prelude bytes.Buffer
|
||||||
printPrelude(&prelude, result, true)
|
printPrelude(&prelude, result, true)
|
||||||
|
|
|
@ -23,19 +23,19 @@ type PreviewOptions struct {
|
||||||
Color colors.Colorization
|
Color colors.Colorization
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eng *Engine) Preview(update Update, events chan<- Event, opts PreviewOptions) error {
|
func Preview(update Update, events chan<- Event, opts PreviewOptions) error {
|
||||||
contract.Require(update != nil, "update")
|
contract.Require(update != nil, "update")
|
||||||
contract.Require(events != nil, "events")
|
contract.Require(events != nil, "events")
|
||||||
|
|
||||||
defer func() { events <- cancelEvent() }()
|
defer func() { events <- cancelEvent() }()
|
||||||
|
|
||||||
info, err := eng.planContextFromUpdate(update)
|
info, err := planContextFromUpdate(update)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer info.Close()
|
defer info.Close()
|
||||||
|
|
||||||
return eng.previewLatest(info, deployOptions{
|
return previewLatest(info, deployOptions{
|
||||||
Destroy: false,
|
Destroy: false,
|
||||||
DryRun: true,
|
DryRun: true,
|
||||||
Analyzers: opts.Analyzers,
|
Analyzers: opts.Analyzers,
|
||||||
|
@ -52,8 +52,8 @@ func (eng *Engine) Preview(update Update, events chan<- Event, opts PreviewOptio
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eng *Engine) previewLatest(info *planContext, opts deployOptions) error {
|
func previewLatest(info *planContext, opts deployOptions) error {
|
||||||
result, err := eng.plan(info, opts)
|
result, err := plan(info, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func (eng *Engine) previewLatest(info *planContext, opts deployOptions) error {
|
||||||
}
|
}
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
if err := eng.printPlan(result); err != nil {
|
if err := printPlan(result); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue