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.
41 lines
2.3 KiB
Go
41 lines
2.3 KiB
Go
// Copyright 2018, Pulumi Corporation. All rights reserved.
|
|
|
|
package engine
|
|
|
|
import (
|
|
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
|
"github.com/pulumi/pulumi/pkg/workspace"
|
|
)
|
|
|
|
// UpdateInfo abstracts away information about an apply, preview, or destroy.
|
|
type UpdateInfo interface {
|
|
// GetRoot returns the root directory for this update. This defines the scope for any filesystem resources
|
|
// accessed by this update.
|
|
GetRoot() string
|
|
// GetProject returns information about the project associated with this update. This includes information such as
|
|
// the runtime that will be used to execute the Pulumi program and the program's relative working directory.
|
|
GetProject() *workspace.Project
|
|
// GetTarget returns information about the target of this update. This includes the name of the stack being
|
|
// updated, the configuration values associated with the target and the target's latest snapshot.
|
|
GetTarget() *deploy.Target
|
|
|
|
// BeginMutation and SnapshotMutation.End allow a snapshot provider to be robust in the face of failures that occur
|
|
// between the points at which they are called. The semantics are as follows:
|
|
// 1. The engine calls `SnapshotProvider.Begin` to indicate that it is about to mutate the state of the
|
|
// resources tracked by the snapshot.
|
|
// 2. The engine mutates the state of the resoures tracked by the snapshot.
|
|
// 3. The engine calls `SnapshotMutation.End` with the new snapshot to indicate that the mutation(s) it was
|
|
// performing has/have finished.
|
|
// During (1), the snapshot provider should record the fact that any currently persisted snapshot is being mutated
|
|
// and cannot be assumed to represent the actual state of the system. This ensures that if the engine crashes during
|
|
// (2), then the current snapshot is known to be unreliable. During (3), the snapshot provider should persist the
|
|
// provided snapshot and record that it is known to be reliable.
|
|
BeginMutation() (SnapshotMutation, error)
|
|
}
|
|
|
|
// SnapshotMutation abstracts away managing changes to snapshots.
|
|
type SnapshotMutation interface {
|
|
// End indicates that the current mutation has completed and that its results (given by snapshot) should be
|
|
// persisted. See the comments on SnapshotProvider.BeginMutation for more details.
|
|
End(snapshot *deploy.Snapshot) error
|
|
}
|