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.
|
2018-01-25 03:22:41 +01:00
|
|
|
|
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pulumi/pulumi/pkg/engine"
|
|
|
|
"github.com/pulumi/pulumi/pkg/resource/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
// UpdateMetadata describes optional metadata about an update.
|
|
|
|
type UpdateMetadata struct {
|
|
|
|
// Message is an optional message associated with the update.
|
|
|
|
Message string `json:"message"`
|
|
|
|
// Environment contains optional data from the deploying environment. e.g. the current
|
|
|
|
// source code control commit information.
|
|
|
|
Environment map[string]string `json:"environment"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateKind is an enum for the type of update performed.
|
|
|
|
type UpdateKind string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// DeployUpdate is the prototypical Pulumi program update.
|
|
|
|
DeployUpdate UpdateKind = "update"
|
|
|
|
// PreviewUpdate is a preview of an update, without impacting resources.
|
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
|
|
|
PreviewUpdate UpdateKind = "preview"
|
Implement a refresh command
This change implements a `pulumi refresh` command. It operates a bit
like `pulumi update`, and friends, in that it supports `--preview` and
`--diff`, along with the usual flags, and will update your checkpoint.
It works through substitution of the deploy.Source abstraction, which
generates a sequence of resource registration events. This new
deploy.RefreshSource takes in a prior checkpoint and will walk it,
refreshing the state via the associated resource providers by invoking
Read for each resource encountered, and merging the resulting state with
the prior checkpoint, to yield a new resource.Goal state. This state is
then fed through the engine in the usual ways with a few minor caveats:
namely, although the engine must generate steps for the logical
operations (permitting us to get nice summaries, progress, and diffs),
it mustn't actually carry them out because the state being imported
already reflects reality (a deleted resource has *already* been deleted,
so of course the engine need not perform the deletion). The diffing
logic also needs to know how to treat the case of refresh slightly
differently, because we are going to be diffing outputs and not inputs.
Note that support for managed stacks is not yet complete, since that
requires updates to the service to support a refresh endpoint. That
will be coming soon ...
2018-04-10 20:22:39 +02:00
|
|
|
// RefreshUpdate is an update that adopts a cloud's existing resource state.
|
|
|
|
RefreshUpdate UpdateKind = "refresh"
|
2018-01-25 03:22:41 +01:00
|
|
|
// DestroyUpdate is an update which removes all resources.
|
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
|
|
|
DestroyUpdate UpdateKind = "destroy"
|
2018-01-25 03:22:41 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// UpdateResult is an enum for the result of the update.
|
|
|
|
type UpdateResult string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// InProgressResult is for updates that have not yet completed.
|
|
|
|
InProgressResult = "in-progress"
|
|
|
|
// SucceededResult is for updates that completed successfully.
|
|
|
|
SucceededResult UpdateResult = "succeeded"
|
|
|
|
// FailedResult is for updates that have failed.
|
|
|
|
FailedResult = "failed"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Keys we use for values put into UpdateInfo.Environment.
|
|
|
|
const (
|
|
|
|
// GitHead is the commit hash of HEAD.
|
|
|
|
GitHead = "git.head"
|
|
|
|
// GitDirty ("true", "false") indiciates if there are any unstaged or modified files in the local repo.
|
|
|
|
GitDirty = "git.dirty"
|
|
|
|
|
2018-05-08 18:58:33 +02:00
|
|
|
// GitCommitter is the name of the person who committed the commit at HEAD.
|
|
|
|
GitCommitter = "git.committer"
|
|
|
|
// GitCommitterEmail is the Email address associated with the committer.
|
|
|
|
GitCommitterEmail = "git.committer.email"
|
|
|
|
// GitAuthor is the name of the person who authored the commit at HEAD.
|
|
|
|
GitAuthor = "git.author"
|
|
|
|
// GitAuthorEmail is the email address associated with the commit's author.
|
|
|
|
GitAuthorEmail = "git.author.email"
|
|
|
|
|
2018-01-25 03:22:41 +01:00
|
|
|
// GitHubLogin is the user/organization who owns the local repo, if the origin remote is hosted on GitHub.com.
|
|
|
|
GitHubLogin = "github.login"
|
|
|
|
// GitHubRepo is the name of the GitHub repo, if the local git repo's remote origin is hosted on GitHub.com.
|
|
|
|
GitHubRepo = "github.repo"
|
2018-08-01 06:38:07 +02:00
|
|
|
|
|
|
|
// CISystem is the name of the CI system running the pulumi operation.
|
|
|
|
CISystem = "ci.system"
|
2018-08-08 23:12:47 +02:00
|
|
|
// CIBuildID is an opaque ID of the build in the CI system.
|
|
|
|
CIBuildID = "ci.build.id"
|
|
|
|
// CIBuildType is the type of build of the CI system, e.g. "push", "pull_request", "test_only".
|
|
|
|
CIBuildType = "ci.build.type"
|
|
|
|
// CIBuildURL is a URL to get more information about the particular CI build.
|
|
|
|
CIBuildURL = "ci.build.url"
|
2018-08-01 06:38:07 +02:00
|
|
|
|
|
|
|
// CIPRHeadSHA is the SHA of the HEAD commit of a pull request running on CI. This is needed since the CI
|
|
|
|
// server will run at a different, merge commit. (headSHA merged into the target branch.)
|
|
|
|
CIPRHeadSHA = "ci.pr.headSHA"
|
2018-01-25 03:22:41 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// UpdateInfo describes a previous update.
|
|
|
|
type UpdateInfo struct {
|
|
|
|
// Information known before an update is started.
|
|
|
|
Kind UpdateKind `json:"kind"`
|
|
|
|
StartTime int64 `json:"startTime"`
|
2018-03-08 22:56:59 +01:00
|
|
|
|
2018-01-25 03:22:41 +01:00
|
|
|
// Message is an optional message associated with the update.
|
|
|
|
Message string `json:"message"`
|
2018-03-08 22:56:59 +01:00
|
|
|
|
2018-01-25 03:22:41 +01:00
|
|
|
// Environment contains optional data from the deploying environment. e.g. the current
|
|
|
|
// source code control commit information.
|
|
|
|
Environment map[string]string `json:"environment"`
|
|
|
|
|
|
|
|
// Config used for the update.
|
|
|
|
Config config.Map `json:"config"`
|
|
|
|
|
|
|
|
// Information obtained from an update completing.
|
2018-03-08 22:56:59 +01:00
|
|
|
Result UpdateResult `json:"result"`
|
|
|
|
EndTime int64 `json:"endTime"`
|
|
|
|
ResourceChanges engine.ResourceChanges `json:"resourceChanges,omitempty"`
|
2018-01-25 03:22:41 +01:00
|
|
|
}
|