2018-03-21 20:43:21 +01:00
|
|
|
// Copyright 2018, Pulumi Corporation. All rights reserved.
|
2017-08-30 03:24:12 +02:00
|
|
|
|
2017-08-23 01:56:15 +02:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2017-09-22 04:18:21 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/diag"
|
|
|
|
"github.com/pulumi/pulumi/pkg/resource"
|
|
|
|
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/resource/plugin"
|
2017-09-22 04:18:21 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/util/contract"
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
"github.com/pulumi/pulumi/pkg/workspace"
|
2017-08-23 01:56:15 +02:00
|
|
|
)
|
|
|
|
|
2018-01-18 20:10:15 +01:00
|
|
|
// UpdateOptions contains all the settings for customizing how an update (deploy, preview, or destroy) is performed.
|
|
|
|
type UpdateOptions struct {
|
2018-04-14 07:26:01 +02:00
|
|
|
// an optional set of analyzers to run as part of this deployment.
|
|
|
|
Analyzers []string
|
|
|
|
|
|
|
|
// the degree of parallelism for resource operations (<=1 for serial).
|
|
|
|
Parallel int
|
|
|
|
|
|
|
|
// true if debugging output it enabled
|
|
|
|
Debug bool
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
|
2018-01-20 21:07:03 +01:00
|
|
|
// ResourceChanges contains the aggregate resource changes by operation type.
|
|
|
|
type ResourceChanges map[deploy.StepOp]int
|
|
|
|
|
2018-05-05 20:57:09 +02:00
|
|
|
// HasChanges returns true if there are any non-same changes in the resulting summary.
|
|
|
|
func (changes ResourceChanges) HasChanges() bool {
|
|
|
|
var c int
|
|
|
|
for op, count := range changes {
|
|
|
|
if op != deploy.OpSame {
|
|
|
|
c += count
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c > 0
|
|
|
|
}
|
|
|
|
|
2018-04-20 03:59:14 +02:00
|
|
|
func Update(u UpdateInfo, ctx *Context, opts UpdateOptions, dryRun bool) (ResourceChanges, error) {
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
contract.Require(u != nil, "update")
|
2018-04-20 03:59:14 +02:00
|
|
|
contract.Require(ctx != nil, "ctx")
|
2017-09-09 22:43:51 +02:00
|
|
|
|
2018-04-20 03:59:14 +02:00
|
|
|
defer func() { ctx.Events <- cancelEvent() }()
|
2017-10-23 00:52:00 +02:00
|
|
|
|
2018-05-05 02:01:35 +02:00
|
|
|
info, err := newPlanContext(u, "update", ctx.ParentSpan)
|
2017-08-23 01:56:15 +02:00
|
|
|
if err != nil {
|
2018-01-20 21:07:03 +01:00
|
|
|
return nil, err
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
2018-04-20 03:59:14 +02:00
|
|
|
defer info.Close()
|
2017-10-05 23:08:46 +02:00
|
|
|
|
2018-04-20 03:59:14 +02:00
|
|
|
emitter := makeEventEmitter(ctx.Events, u)
|
|
|
|
return update(ctx, info, planOptions{
|
2018-01-18 20:10:15 +01:00
|
|
|
UpdateOptions: opts,
|
2018-03-29 17:57:25 +02:00
|
|
|
SourceFunc: newUpdateSource,
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
Events: emitter,
|
|
|
|
Diag: newEventSink(emitter),
|
2018-04-26 02:20:08 +02:00
|
|
|
PluginEvents: &pluginActions{ctx},
|
2018-04-14 07:26:01 +02:00
|
|
|
}, dryRun)
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
|
2018-04-14 07:26:01 +02:00
|
|
|
func newUpdateSource(
|
|
|
|
opts planOptions, proj *workspace.Project, pwd, main string,
|
|
|
|
target *deploy.Target, plugctx *plugin.Context, dryRun bool) (deploy.Source, error) {
|
|
|
|
|
2018-03-29 17:57:25 +02:00
|
|
|
// Figure out which plugins to load by inspecting the program contents.
|
|
|
|
plugins, err := plugctx.Host.GetRequiredPlugins(plugin.ProgInfo{
|
|
|
|
Proj: proj,
|
|
|
|
Pwd: pwd,
|
|
|
|
Program: main,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
}
|
2018-03-29 17:57:25 +02:00
|
|
|
|
|
|
|
// Now ensure that we have loaded up any plugins that the program will need in advance.
|
|
|
|
if err = plugctx.Host.EnsurePlugins(plugins); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// If that succeeded, create a new source that will perform interpretation of the compiled program.
|
|
|
|
// TODO[pulumi/pulumi#88]: we are passing `nil` as the arguments map; we need to allow a way to pass these.
|
|
|
|
return deploy.NewEvalSource(plugctx, &deploy.EvalRunInfo{
|
|
|
|
Proj: proj,
|
|
|
|
Pwd: pwd,
|
|
|
|
Program: main,
|
|
|
|
Target: target,
|
2018-04-14 07:26:01 +02:00
|
|
|
}, dryRun), nil
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 03:59:14 +02:00
|
|
|
func update(ctx *Context, info *planContext, opts planOptions, dryRun bool) (ResourceChanges, error) {
|
2018-04-14 07:26:01 +02:00
|
|
|
result, err := plan(info, opts, dryRun)
|
2017-08-23 01:56:15 +02:00
|
|
|
if err != nil {
|
2018-01-20 21:07:03 +01:00
|
|
|
return nil, err
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
2018-01-20 21:07:03 +01:00
|
|
|
|
|
|
|
var resourceChanges ResourceChanges
|
2017-08-23 01:56:15 +02:00
|
|
|
if result != nil {
|
|
|
|
defer contract.IgnoreClose(result)
|
2017-12-12 21:31:09 +01:00
|
|
|
|
|
|
|
// Make the current working directory the same as the program's, and restore it upon exit.
|
|
|
|
done, err := result.Chdir()
|
|
|
|
if err != nil {
|
2018-01-20 21:07:03 +01:00
|
|
|
return nil, err
|
2017-12-12 21:31:09 +01:00
|
|
|
}
|
|
|
|
defer done()
|
|
|
|
|
2018-04-14 07:26:01 +02:00
|
|
|
if dryRun {
|
2018-01-25 03:22:41 +01:00
|
|
|
// If a dry run, just print the plan, don't actually carry out the deployment.
|
2018-04-20 03:59:14 +02:00
|
|
|
resourceChanges, err = printPlan(ctx, result, dryRun)
|
2018-01-25 03:22:41 +01:00
|
|
|
if err != nil {
|
2018-01-20 21:07:03 +01:00
|
|
|
return resourceChanges, err
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Otherwise, we will actually deploy the latest bits.
|
2018-04-14 07:26:01 +02:00
|
|
|
opts.Events.preludeEvent(dryRun, result.Ctx.Update.GetTarget().Config)
|
2017-08-23 01:56:15 +02:00
|
|
|
|
2017-10-02 23:26:51 +02:00
|
|
|
// Walk the plan, reporting progress and executing the actual operations as we go.
|
2017-08-23 01:56:15 +02:00
|
|
|
start := time.Now()
|
2018-04-20 03:59:14 +02:00
|
|
|
actions := newUpdateActions(ctx, info.Update, opts)
|
2018-04-30 19:27:04 +02:00
|
|
|
summary, step, _, err := result.Walk(ctx, actions, false)
|
2017-08-27 09:38:17 +02:00
|
|
|
if err != nil && summary == nil {
|
2017-10-03 20:07:36 +02:00
|
|
|
// Something went wrong, and no changes were made.
|
2018-01-20 21:07:03 +01:00
|
|
|
return resourceChanges, err
|
2017-08-27 09:38:17 +02:00
|
|
|
}
|
2018-04-30 19:27:04 +02:00
|
|
|
|
2017-08-23 01:56:15 +02:00
|
|
|
contract.Assert(summary != nil)
|
2018-04-30 19:27:04 +02:00
|
|
|
if err != nil {
|
|
|
|
var failedUrn resource.URN
|
|
|
|
if step != nil {
|
|
|
|
failedUrn = step.URN()
|
|
|
|
}
|
|
|
|
|
|
|
|
opts.Diag.Errorf(diag.Message(failedUrn, err.Error()))
|
|
|
|
}
|
2017-08-23 01:56:15 +02:00
|
|
|
|
|
|
|
// Print out the total number of steps performed (and their kinds), the duration, and any summary info.
|
2018-01-20 21:07:03 +01:00
|
|
|
resourceChanges = ResourceChanges(actions.Ops)
|
2018-03-05 20:39:50 +01:00
|
|
|
opts.Events.updateSummaryEvent(actions.MaybeCorrupt, time.Since(start), resourceChanges)
|
2017-10-05 23:08:46 +02:00
|
|
|
|
2017-09-09 21:42:04 +02:00
|
|
|
if err != nil {
|
2018-01-20 21:07:03 +01:00
|
|
|
return resourceChanges, err
|
2017-09-09 21:42:04 +02:00
|
|
|
}
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
}
|
2018-01-20 21:07:03 +01:00
|
|
|
|
|
|
|
return resourceChanges, nil
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 02:20:08 +02:00
|
|
|
// pluginActions listens for plugin events and persists the set of loaded plugins
|
|
|
|
// to the snapshot.
|
|
|
|
type pluginActions struct {
|
|
|
|
Context *Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *pluginActions) OnPluginLoad(loadedPlug workspace.PluginInfo) error {
|
|
|
|
return p.Context.SnapshotManager.RecordPlugin(loadedPlug)
|
|
|
|
}
|
|
|
|
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
// updateActions pretty-prints the plan application process as it goes.
|
|
|
|
type updateActions struct {
|
2018-04-20 03:59:14 +02:00
|
|
|
Context *Context
|
2018-04-17 08:04:56 +02:00
|
|
|
Steps int
|
|
|
|
Ops map[deploy.StepOp]int
|
|
|
|
Seen map[resource.URN]deploy.Step
|
|
|
|
MaybeCorrupt bool
|
|
|
|
Update UpdateInfo
|
|
|
|
Opts planOptions
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 03:59:14 +02:00
|
|
|
func newUpdateActions(context *Context, u UpdateInfo, opts planOptions) *updateActions {
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
return &updateActions{
|
2018-04-20 03:59:14 +02:00
|
|
|
Context: context,
|
|
|
|
Ops: make(map[deploy.StepOp]int),
|
|
|
|
Seen: make(map[resource.URN]deploy.Step),
|
|
|
|
Update: u,
|
|
|
|
Opts: opts,
|
2017-11-17 03:21:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
func (acts *updateActions) OnResourceStepPre(step deploy.Step) (interface{}, error) {
|
2018-02-03 01:02:50 +01:00
|
|
|
// Ensure we've marked this step as observed.
|
|
|
|
acts.Seen[step.URN()] = step
|
|
|
|
|
2018-03-31 21:08:48 +02:00
|
|
|
acts.Opts.Events.resourcePreEvent(step, false /*planning*/, acts.Opts.Debug)
|
2017-08-23 01:56:15 +02:00
|
|
|
|
2017-10-21 18:31:01 +02:00
|
|
|
// Inform the snapshot service that we are about to perform a step.
|
2018-04-26 02:20:08 +02:00
|
|
|
return acts.Context.SnapshotManager.BeginMutation(step)
|
Bring back component outputs
This change brings back component outputs to the overall system again.
In doing so, it generally overhauls the way we do resource RPCs a bit:
* Instead of RegisterResource and CompleteResource, we call these
BeginRegisterResource and EndRegisterResource, which begins to model
these as effectively "asynchronous" resource requests. This should also
help with parallelism (https://github.com/pulumi/pulumi/issues/106).
* Flip the CLI/engine a little on its head. Rather than it driving the
planning and deployment process, we move more to a model where it
simply observes it. This is done by implementing an event handler
interface with three events: OnResourceStepPre, OnResourceStepPost,
and OnResourceComplete. The first two are invoked immediately before
and after any step operation, and the latter is invoked whenever a
EndRegisterResource comes in. The reason for the asymmetry here is
that the checkpointing logic in the deployment engine is largely
untouched (intentionally, as this is a sensitive part of the system),
and so the "begin"/"end" nature doesn't flow through faithfully.
* Also make the engine more event-oriented in its terminology and the
way it handles the incoming BeginRegisterResource and
EndRegisterResource events from the language host. This is the first
step down a long road of incrementally refactoring the engine to work
this way, a necessary prerequisite for parallelism.
2017-11-29 16:42:14 +01:00
|
|
|
}
|
2017-08-23 01:56:15 +02:00
|
|
|
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
func (acts *updateActions) OnResourceStepPost(ctx interface{},
|
2017-11-30 00:05:58 +01:00
|
|
|
step deploy.Step, status resource.Status, err error) error {
|
2018-03-31 21:08:48 +02:00
|
|
|
|
2018-02-03 01:02:50 +01:00
|
|
|
assertSeen(acts.Seen, step)
|
|
|
|
|
2018-04-20 03:59:14 +02:00
|
|
|
// If we've already been terminated, exit without writing the checkpoint. We explicitly want to leave the
|
|
|
|
// checkpoint in an inconsistent state in this event.
|
|
|
|
if acts.Context.Cancel.TerminateErr() != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-10-03 19:27:59 +02:00
|
|
|
// Report the result of the step.
|
2017-08-23 01:56:15 +02:00
|
|
|
stepop := step.Op()
|
|
|
|
if err != nil {
|
2018-02-04 10:18:06 +01:00
|
|
|
if status == resource.StatusUnknown {
|
2017-10-02 23:26:51 +02:00
|
|
|
acts.MaybeCorrupt = true
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
2018-02-04 10:18:06 +01:00
|
|
|
|
|
|
|
// Issue a true, bonafide error.
|
2018-04-10 21:03:11 +02:00
|
|
|
acts.Opts.Diag.Errorf(diag.GetPlanApplyFailedError(step.URN()), err)
|
2018-03-31 21:08:48 +02:00
|
|
|
acts.Opts.Events.resourceOperationFailedEvent(step, status, acts.Steps, acts.Opts.Debug)
|
2017-11-29 20:27:32 +01:00
|
|
|
} else {
|
|
|
|
if step.Logical() {
|
|
|
|
// Increment the counters.
|
|
|
|
acts.Steps++
|
|
|
|
acts.Ops[stepop]++
|
|
|
|
}
|
|
|
|
|
2018-04-20 20:52:33 +02:00
|
|
|
// Also show outputs here for custom resources, since there might be some from the initial registration. We do
|
|
|
|
// not show outputs for component resources at this point: any that exist must be from a previous execution of
|
|
|
|
// the Pulumi program, as component resources only report outputs via calls to RegisterResourceOutputs.
|
2018-04-20 20:44:28 +02:00
|
|
|
if step.Res().Custom {
|
|
|
|
acts.Opts.Events.resourceOutputsEvent(step, false /*planning*/, acts.Opts.Debug)
|
|
|
|
}
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|
2017-10-02 23:27:50 +02:00
|
|
|
|
Implement resource protection (#751)
This change implements resource protection, as per pulumi/pulumi#689.
The overall idea is that a resource can be marked as "protect: true",
which will prevent deletion of that resource for any reason whatsoever
(straight deletion, replacement, etc). This is expressed in the
program. To "unprotect" a resource, one must perform an update setting
"protect: false", and then afterwards, they can delete the resource.
For example:
let res = new MyResource("precious", { .. }, { protect: true });
Afterwards, the resource will display in the CLI with a lock icon, and
any attempts to remove it will fail in the usual ways (in planning or,
worst case, during an actual update).
This was done by adding a new ResourceOptions bag parameter to the
base Resource types. This is unfortunately a breaking change, but now
is the right time to take this one. We had been adding new settings
one by one -- like parent and dependsOn -- and this new approach will
set us up to add any number of additional settings down the road,
without needing to worry about breaking anything ever again.
This is related to protected stacks, as described in
pulumi/pulumi-service#399. Most likely this will serve as a foundational
building block that enables the coarser grained policy management.
2017-12-20 23:31:07 +01:00
|
|
|
// Write out the current snapshot. Note that even if a failure has occurred, we should still have a
|
2018-04-26 02:20:08 +02:00
|
|
|
// safe checkpoint. Note that any error that occurs when writing the checkpoint trumps the error
|
|
|
|
// reported above.
|
|
|
|
return ctx.(SnapshotMutation).End(step, err == nil)
|
Bring back component outputs
This change brings back component outputs to the overall system again.
In doing so, it generally overhauls the way we do resource RPCs a bit:
* Instead of RegisterResource and CompleteResource, we call these
BeginRegisterResource and EndRegisterResource, which begins to model
these as effectively "asynchronous" resource requests. This should also
help with parallelism (https://github.com/pulumi/pulumi/issues/106).
* Flip the CLI/engine a little on its head. Rather than it driving the
planning and deployment process, we move more to a model where it
simply observes it. This is done by implementing an event handler
interface with three events: OnResourceStepPre, OnResourceStepPost,
and OnResourceComplete. The first two are invoked immediately before
and after any step operation, and the latter is invoked whenever a
EndRegisterResource comes in. The reason for the asymmetry here is
that the checkpointing logic in the deployment engine is largely
untouched (intentionally, as this is a sensitive part of the system),
and so the "begin"/"end" nature doesn't flow through faithfully.
* Also make the engine more event-oriented in its terminology and the
way it handles the incoming BeginRegisterResource and
EndRegisterResource events from the language host. This is the first
step down a long road of incrementally refactoring the engine to work
this way, a necessary prerequisite for parallelism.
2017-11-29 16:42:14 +01:00
|
|
|
}
|
2017-10-03 19:27:59 +02:00
|
|
|
|
General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):
* The primary change is to change the way the engine's core update
functionality works with respect to deploy.Source. This is the
way we can plug in new sources of resource information during
planning (and, soon, diffing). The way I intend to model refresh
is by having a new kind of source, deploy.RefreshSource, which
will let us do virtually everything about an update/diff the same
way with refreshes, which avoid otherwise duplicative effort.
This includes changing the planOptions (nee deployOptions) to
take a new SourceFunc callback, which is responsible for creating
a source specific to the kind of plan being requested.
Preview, Update, and Destroy now are primarily differentiated by
the kind of deploy.Source that they return, rather than sprinkling
things like `if Destroying` throughout. This tidies up some logic
and, more importantly, gives us precisely the refresh hook we need.
* Originally, we used the deploy.NullSource for Destroy operations.
This simply returns nothing, which is how Destroy works. For some
reason, we were no longer doing this, and instead had some
`if Destroying` cases sprinkled throughout the deploy.EvalSource.
I think this is a vestige of some old way we did configuration, at
least judging by a comment, which is apparently no longer relevant.
* Move diff and diff-printing logic within the engine into its own
pkg/engine/diff.go file, to prepare for upcoming work.
* I keep noticing benign diffs anytime I regenerate protobufs. I
suspect this is because we're also on different versions. I changed
generate.sh to also dump the version into grpc_version.txt. At
least we can understand where the diffs are coming from, decide
whether to take them (i.e., a newer version), and ensure that as
a team we are monotonically increasing, and not going backwards.
* I also tidied up some tiny things I noticed while in there, like
comments, incorrect types, lint suppressions, and so on.
2018-03-28 16:45:23 +02:00
|
|
|
func (acts *updateActions) OnResourceOutputs(step deploy.Step) error {
|
2018-02-03 01:02:50 +01:00
|
|
|
assertSeen(acts.Seen, step)
|
|
|
|
|
2018-04-17 08:04:56 +02:00
|
|
|
acts.Opts.Events.resourceOutputsEvent(step, false /*planning*/, acts.Opts.Debug)
|
|
|
|
|
|
|
|
// There's a chance there are new outputs that weren't written out last time.
|
|
|
|
// We need to perform another snapshot write to ensure they get written out.
|
2018-04-26 02:20:08 +02:00
|
|
|
return acts.Context.SnapshotManager.RegisterResourceOutputs(step)
|
2017-08-23 01:56:15 +02:00
|
|
|
}
|