Skip to content

Commit

Permalink
Decouple the generation of plans from the automatic use of plans
Browse files Browse the repository at this point in the history
This threads a new option "Experimental" through to the engine which is
used to decided if plans should be used or not. This also generates
plans for any preview with --save-plan, but also now generates plans
during the preview phase of up.
  • Loading branch information
Frassle committed Oct 28, 2022
1 parent bd87211 commit 81b137b
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 28 deletions.
9 changes: 7 additions & 2 deletions pkg/backend/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,14 @@ func PreviewThenPromptThenExecute(ctx context.Context, kind apitype.UpdateKind,
return changes, res
}

// If we had an original plan use it, else use the newly generated plan (might be nil if we've turned
// If we had an original plan use it, else if experimental use the newly generated plan (might be nil if we've turned
// plan generation off)
if originalPlan != nil {
op.Opts.Engine.Plan = originalPlan
} else {
} else if op.Opts.Engine.Experimental {
op.Opts.Engine.Plan = plan
} else {
op.Opts.Engine.Plan = nil
}
}

Expand All @@ -235,6 +237,9 @@ func PreviewThenPromptThenExecute(ctx context.Context, kind apitype.UpdateKind,
DryRun: false,
ShowLink: true,
}
// No need to generate a plan at this stage, there's no way for the system or user to extract the plan
// after here.
op.Opts.Engine.GeneratePlan = false
_, changes, res := apply(ctx, kind, stack, op, opts, nil /*events*/)
return changes, res
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ type UpdateOptions struct {
AutoApprove bool
// SkipPreview, when true, causes the preview step to be skipped.
SkipPreview bool
// GeneratePlan when true cause plans to be generated.
GeneratePlan bool
}

// QueryOptions configures a query to operate against a backend and the engine.
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/pulumi/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func newDestroyCmd() *cobra.Command {
DisableProviderPreview: disableProviderPreview(),
DisableResourceReferences: disableResourceReferences(),
DisableOutputValues: disableOutputValues(),
Experimental: hasExperimentalCommands(),
}

_, res := s.Destroy(ctx, backend.UpdateOperation{
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/pulumi/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ func newImportCmd() *cobra.Command {
Parallel: parallel,
Debug: debug,
UseLegacyDiff: useLegacyDiff(),
Experimental: hasExperimentalCommands(),
}

_, res := s.Import(ctx, backend.UpdateOperation{
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/pulumi/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func newPreviewCmd() *cobra.Command {
// If we're trying to save a plan then we _need_ to generate it. We also turn this on in
// experimental mode to just get more testing of it.
GeneratePlan: hasExperimentalCommands() || planFilePath != "",
Experimental: hasExperimentalCommands(),
},
Display: displayOpts,
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/pulumi/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ func newQueryCmd() *cobra.Command {
return result.FromError(err)
}

opts.Engine = engine.UpdateOptions{}
opts.Engine = engine.UpdateOptions{
Experimental: hasExperimentalCommands(),
}

res := b.Query(ctx, backend.QueryOperation{
Proj: proj,
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/pulumi/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func newRefreshCmd() *cobra.Command {
DisableResourceReferences: disableResourceReferences(),
DisableOutputValues: disableOutputValues(),
RefreshTargets: deploy.NewUrnTargets(targetUrns),
Experimental: hasExperimentalCommands(),
}

changes, res := s.Refresh(ctx, backend.UpdateOperation{
Expand Down
8 changes: 5 additions & 3 deletions pkg/cmd/pulumi/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ func newUpCmd() *cobra.Command {
DisableOutputValues: disableOutputValues(),
UpdateTargets: deploy.NewUrnTargets(targetURNs),
TargetDependents: targetDependents,
// If we're in experimental mode then we trigger a plan to be generated during the preview phase
// which will be constrained to during the update phase.
GeneratePlan: hasExperimentalCommands(),
// Trigger a plan to be generated during the preview phase which can be constrained to during the
// update phase.
GeneratePlan: true,
Experimental: hasExperimentalCommands(),
}

if planFilePath != "" {
Expand Down Expand Up @@ -360,6 +361,7 @@ func newUpCmd() *cobra.Command {
// If we're in experimental mode then we trigger a plan to be generated during the preview phase
// which will be constrained to during the update phase.
GeneratePlan: hasExperimentalCommands(),
Experimental: hasExperimentalCommands(),
}

// TODO for the URL case:
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/pulumi/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func newWatchCmd() *cobra.Command {
DisableProviderPreview: disableProviderPreview(),
DisableResourceReferences: disableResourceReferences(),
DisableOutputValues: disableOutputValues(),
Experimental: hasExperimentalCommands(),
}

res := s.Watch(ctx, backend.UpdateOperation{
Expand Down
38 changes: 19 additions & 19 deletions pkg/engine/lifecycletest/update_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestPlannedUpdate(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestUnplannedCreate(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestUnplannedDelete(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestExpectedDelete(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestExpectedCreate(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -443,7 +443,7 @@ func TestPropertySetChange(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -494,7 +494,7 @@ func TestExpectedUnneededCreate(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -559,7 +559,7 @@ func TestExpectedUnneededDelete(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -636,7 +636,7 @@ func TestResoucesWithSames(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -727,7 +727,7 @@ func TestPlannedPreviews(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -812,7 +812,7 @@ func TestPlannedUpdateChangedStack(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -895,7 +895,7 @@ func TestPlannedOutputChanges(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -962,7 +962,7 @@ func TestPlannedInputOutputDifferences(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -1046,7 +1046,7 @@ func TestAliasWithPlans(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -1111,7 +1111,7 @@ func TestComputedCanBeDropped(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -1263,7 +1263,7 @@ func TestPlannedUpdateWithNondeterministicCheck(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -1337,7 +1337,7 @@ func TestPlannedUpdateWithCheckFailure(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -1397,7 +1397,7 @@ func TestPluginsAreDownloaded(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down Expand Up @@ -1474,7 +1474,7 @@ func TestProviderDeterministicPreview(t *testing.T) {
host := deploytest.NewPluginHost(nil, nil, program, loaders...)

p := &TestPlan{
Options: UpdateOptions{Host: host, GeneratePlan: true},
Options: UpdateOptions{Host: host, GeneratePlan: true, Experimental: true},
}

project := p.GetProject()
Expand Down
5 changes: 4 additions & 1 deletion pkg/engine/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,11 @@ type UpdateOptions struct {
// The plan to use for the update, if any.
Plan *deploy.Plan

// true if plans should be generated.
// GeneratePlan when true cause plans to be generated, we skip this if we know their not needed (e.g. during up)
GeneratePlan bool

// Experimental is true if the engine is in experimental mode (i.e. PULUMI_EXPERIMENTAL was set)
Experimental bool
}

// HasChanges returns true if there are any non-same changes in the resulting summary.
Expand Down

0 comments on commit 81b137b

Please sign in to comment.