From 5ed6f8b9e32b045cae08c41c96e6c5799a9e896b Mon Sep 17 00:00:00 2001 From: "pat@pulumi.com" Date: Fri, 20 Apr 2018 14:36:15 -0700 Subject: [PATCH] Add deployment version fields to more types. This completes the rollout of deployment version fields in the API types. --- pkg/apitype/history.go | 11 +++++++---- pkg/apitype/stacks.go | 7 ++++++- pkg/backend/cloud/backend.go | 12 +++++++++++- pkg/backend/updates.go | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/pkg/apitype/history.go b/pkg/apitype/history.go index 26e48f32a..b73278313 100644 --- a/pkg/apitype/history.go +++ b/pkg/apitype/history.go @@ -2,6 +2,8 @@ package apitype +import "encoding/json" + // UpdateKind is an enum for the type of update performed. // // Should generally mirror backend.UpdateKind, but we clone it in this package to add @@ -70,10 +72,11 @@ type UpdateInfo struct { Config map[string]ConfigValue `json:"config"` // Information obtained from an update completing. - Result UpdateResult `json:"result"` - EndTime int64 `json:"endTime"` - Deployment *DeploymentV1 `json:"deployment,omitempty"` - ResourceChanges map[OpType]int `json:"resourceChanges,omitempty"` + Result UpdateResult `json:"result"` + EndTime int64 `json:"endTime"` + Version int `json:"version"` + Deployment json.RawMessage `json:"deployment,omitempty"` + ResourceChanges map[OpType]int `json:"resourceChanges,omitempty"` } // GetHistoryResponse is the response from the Pulumi Service when requesting diff --git a/pkg/apitype/stacks.go b/pkg/apitype/stacks.go index 0bf8e348b..31ef66a2a 100644 --- a/pkg/apitype/stacks.go +++ b/pkg/apitype/stacks.go @@ -2,6 +2,8 @@ package apitype +import "encoding/json" + // StackSummary presents an overview of a particular stack without enumerating its current resource set. type StackSummary struct { // ID is the unique identifier for a stack in the context of its PPC. @@ -59,6 +61,9 @@ type GetStackResponse struct { // TODO: [pulumi/pulumi-ppc#29]: make this state recoverable. This could be as simple as import/export. UnknownState bool `json:"unknownState"` + // Version indicates the schema of the Resources, Manifest, and Deployment fields below. + Version int `json:"version"` + // Resources provides the list of cloud resources managed by this stack. Resources []ResourceV1 `json:"resources"` @@ -66,7 +71,7 @@ type GetStackResponse struct { Manifest ManifestV1 `json:"manifest"` // Deployment provides a view of the stack as an opaque Pulumi deployment. - Deployment *DeploymentV1 `json:"deployment,omitempty"` + Deployment json.RawMessage `json:"deployment,omitempty"` } // EncryptValueRequest defines the request body for encrypting a value. diff --git a/pkg/backend/cloud/backend.go b/pkg/backend/cloud/backend.go index dbefb848e..67d8068bb 100644 --- a/pkg/backend/cloud/backend.go +++ b/pkg/backend/cloud/backend.go @@ -6,6 +6,7 @@ import ( "bytes" "context" "encoding/base64" + "encoding/json" "fmt" "io" "io/ioutil" @@ -871,6 +872,15 @@ func (b *cloudBackend) GetHistory(stackRef backend.StackReference) ([]backend.Up // Convert apitype.UpdateInfo objects to the backend type. var beUpdates []backend.UpdateInfo for _, update := range updates { + // Decode the deployment. + if update.Version > 1 { + return nil, errors.Errorf("unsupported checkpoint version %v", update.Version) + } + var deployment apitype.DeploymentV1 + if err := json.Unmarshal([]byte(update.Deployment), &deployment); err != nil { + return nil, err + } + // Convert types from the apitype package into their internal counterparts. cfg, err := convertConfig(update.Config) if err != nil { @@ -885,7 +895,7 @@ func (b *cloudBackend) GetHistory(stackRef backend.StackReference) ([]backend.Up Result: backend.UpdateResult(update.Result), StartTime: update.StartTime, EndTime: update.EndTime, - Deployment: update.Deployment, + Deployment: &deployment, ResourceChanges: convertResourceChanges(update.ResourceChanges), }) } diff --git a/pkg/backend/updates.go b/pkg/backend/updates.go index db49f0a79..83c4e5cbf 100644 --- a/pkg/backend/updates.go +++ b/pkg/backend/updates.go @@ -75,6 +75,6 @@ type UpdateInfo struct { // Information obtained from an update completing. Result UpdateResult `json:"result"` EndTime int64 `json:"endTime"` - Deployment *apitype.Deployment `json:"deployment,omitempty"` + Deployment *apitype.DeploymentV1 `json:"deployment,omitempty"` ResourceChanges engine.ResourceChanges `json:"resourceChanges,omitempty"` }