Skip to content

Commit

Permalink
Merge #11006
Browse files Browse the repository at this point in the history
11006: Send update metadata about update plans r=AaronFriel a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Send update metadata to the service about if we're using update plans.

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
  • Loading branch information
bors[bot] and Frassle committed Oct 20, 2022
2 parents 973740b + bb5cb18 commit c6e7f5b
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 11 deletions.
4 changes: 4 additions & 0 deletions pkg/backend/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ const (
ExecutionKind = "exec.kind"
// ExecutionAgent indicates the user agent of the updater for automated scenarios (GHA, Kubernetes Operator).
ExecutionAgent = "exec.agent"

// UpdatePlan ("true", "false") indicates if an explicit update plan was used for the update (either
// saving one, or constraining to one).
UpdatePlan = "updatePlan"
)

// UpdateInfo describes a previous update.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/pulumi/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func newDestroyCmd() *cobra.Command {
return result.FromError(err)
}

m, err := getUpdateMetadata(message, root, execKind, execAgent)
m, err := getUpdateMetadata(message, root, execKind, execAgent, false)
if err != nil {
return result.FromError(fmt.Errorf("gathering environment metadata: %w", err))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/pulumi/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func newImportCmd() *cobra.Command {
return result.FromError(err)
}

m, err := getUpdateMetadata(message, root, execKind, execAgent)
m, err := getUpdateMetadata(message, root, execKind, execAgent, false)
if err != nil {
return result.FromError(fmt.Errorf("gathering environment metadata: %w", err))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/pulumi/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func newPreviewCmd() *cobra.Command {
return result.FromError(err)
}

m, err := getUpdateMetadata(message, root, execKind, execAgent)
m, err := getUpdateMetadata(message, root, execKind, execAgent, planFilePath != "")
if err != nil {
return result.FromError(fmt.Errorf("gathering environment metadata: %w", err))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/pulumi/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func newRefreshCmd() *cobra.Command {
return result.FromError(err)
}

m, err := getUpdateMetadata(message, root, execKind, execAgent)
m, err := getUpdateMetadata(message, root, execKind, execAgent, false)
if err != nil {
return result.FromError(fmt.Errorf("gathering environment metadata: %w", err))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/pulumi/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func newUpCmd() *cobra.Command {
return result.FromError(err)
}

m, err := getUpdateMetadata(message, root, execKind, execAgent)
m, err := getUpdateMetadata(message, root, execKind, execAgent, planFilePath != "")
if err != nil {
return result.FromError(fmt.Errorf("gathering environment metadata: %w", err))
}
Expand Down Expand Up @@ -335,7 +335,7 @@ func newUpCmd() *cobra.Command {
return result.FromError(err)
}

m, err := getUpdateMetadata(message, root, execKind, execAgent)
m, err := getUpdateMetadata(message, root, execKind, execAgent, planFilePath != "")
if err != nil {
return result.FromError(fmt.Errorf("gathering environment metadata: %w", err))
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/cmd/pulumi/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func isGitWorkTreeDirty(repoRoot string) (bool, error) {

// getUpdateMetadata returns an UpdateMetadata object, with optional data about the environment
// performing the update.
func getUpdateMetadata(msg, root, execKind, execAgent string) (*backend.UpdateMetadata, error) {
func getUpdateMetadata(msg, root, execKind, execAgent string, updatePlan bool) (*backend.UpdateMetadata, error) {
m := &backend.UpdateMetadata{
Message: msg,
Environment: make(map[string]string),
Expand All @@ -566,6 +566,8 @@ func getUpdateMetadata(msg, root, execKind, execAgent string) (*backend.UpdateMe

addExecutionMetadataToEnvironment(m.Environment, execKind, execAgent)

addUpdatePlanMetadataToEnvironment(m.Environment, updatePlan)

return m, nil
}

Expand Down Expand Up @@ -735,6 +737,11 @@ func addExecutionMetadataToEnvironment(env map[string]string, execKind, execAgen
}
}

// addUpdatePlanMetadataToEnvironment populates the environment metadata bag with update plan related values.
func addUpdatePlanMetadataToEnvironment(env map[string]string, updatePlan bool) {
env[backend.UpdatePlan] = strconv.FormatBool(updatePlan)
}

type cancellationScope struct {
context *cancel.Context
sigint chan os.Signal
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/pulumi/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func newWatchCmd() *cobra.Command {
return result.FromError(err)
}

m, err := getUpdateMetadata(message, root, execKind, "" /* execAgent */)
m, err := getUpdateMetadata(message, root, execKind, "" /* execAgent */, false)
if err != nil {
return result.FromError(fmt.Errorf("gathering environment metadata: %w", err))
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/go/common/constant/exec_kind.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package constant

// ExecKindAutoLocal is a flag used to indentify a command as originating
// ExecKindAutoLocal is a flag used to identify a command as originating
// from automation API using a traditional Pulumi project.
const ExecKindAutoLocal = "auto.local"

// ExecKindAutoInline is a flag used to indentify a command as originating
// ExecKindAutoInline is a flag used to identify a command as originating
// from automation API using an inline Pulumi project.
const ExecKindAutoInline = "auto.inline"

// ExecKindCLI is a flag used to indentify a command as originating
// ExecKindCLI is a flag used to identify a command as originating
// from the CLI using a traditional Pulumi project.
const ExecKindCLI = "cli"

Expand Down

0 comments on commit c6e7f5b

Please sign in to comment.