pulumi/pkg/engine/engine.go

57 lines
2.4 KiB
Go
Raw Normal View History

2018-05-22 21:43:36 +02:00
// Copyright 2016-2018, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package engine
import (
"github.com/opentracing/opentracing-go"
"github.com/pulumi/pulumi/pkg/resource/deploy"
"github.com/pulumi/pulumi/pkg/util/cancel"
"github.com/pulumi/pulumi/sdk/go/common/workspace"
)
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
// 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
2017-08-30 03:19:10 +02:00
}
// QueryInfo abstracts away information about a query operation.
type QueryInfo 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
}
// Context provides cancellation, termination, and eventing options for an engine operation. It also provides
// a way for the engine to persist snapshots, using the `SnapshotManager`.
type Context struct {
Cancel *cancel.Context
Events chan<- Event
SnapshotManager SnapshotManager
BackendClient deploy.BackendClient
ParentSpan opentracing.SpanContext
}