1ecdc83a33
This implements the new algorithm for deciding which resources must be deleted due to a delete-before-replace operation. We need to compute the set of resources that may be replaced by a change to the resource under consideration. We do this by taking the complete set of transitive dependents on the resource under consideration and removing any resources that would not be replaced by changes to their dependencies. We determine whether or not a resource may be replaced by substituting unknowns for input properties that may change due to deletion of the resources their value depends on and calling the resource provider's Diff method. This is perhaps clearer when described by example. Consider the following dependency graph: A __|__ B C | _|_ D E F In this graph, all of B, C, D, E, and F transitively depend on A. It may be the case, however, that changes to the specific properties of any of those resources R that would occur if a resource on the path to A were deleted and recreated may not cause R to be replaced. For example, the edge from B to A may be a simple dependsOn edge such that a change to B does not actually influence any of B's input properties. In that case, neither B nor D would need to be deleted before A could be deleted. In order to make the above algorithm a reality, the resource monitor interface has been updated to include a map that associates an input property key with the list of resources that input property depends on. Older clients of the resource monitor will leave this map empty, in which case all input properties will be treated as depending on all dependencies of the resource. This is probably overly conservative, but it is less conservative than what we currently implement, and is certainly correct.
100 lines
3.3 KiB
Go
100 lines
3.3 KiB
Go
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
|
|
|
package ints
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/pulumi/pulumi/pkg/apitype"
|
|
"github.com/pulumi/pulumi/pkg/resource"
|
|
"github.com/pulumi/pulumi/pkg/resource/deploy/providers"
|
|
"github.com/pulumi/pulumi/pkg/testing/integration"
|
|
)
|
|
|
|
func validateResources(t *testing.T, resources []apitype.ResourceV3, expectedNames ...string) {
|
|
// Build the lookup table of expected resource names.
|
|
expectedNamesTable := make(map[string]struct{})
|
|
for _, n := range expectedNames {
|
|
expectedNamesTable[n] = struct{}{}
|
|
}
|
|
|
|
// Pull out the stack resource, which must be the first resource in the checkpoint.
|
|
stackRes, resources := resources[0], resources[1:]
|
|
assert.Equal(t, resource.RootStackType, stackRes.URN.Type())
|
|
|
|
// If there are more resources than just the stack, the second resource will be the default provider.
|
|
if len(resources) > 0 {
|
|
// Pull out the single provider resource, which should be the second resource in the checkpoint.
|
|
providerRes := resources[0]
|
|
resources = resources[1:]
|
|
assert.True(t, providers.IsProviderType(providerRes.URN.Type()))
|
|
}
|
|
|
|
// Ensure that the resource count is correct.
|
|
assert.Equal(t, len(resources), len(expectedNames))
|
|
|
|
// Ensure that exactly the provided resources are in the array.
|
|
for _, res := range resources {
|
|
name := string(res.URN.Name())
|
|
_, ok := expectedNamesTable[name]
|
|
assert.True(t, ok)
|
|
delete(expectedNamesTable, name)
|
|
}
|
|
}
|
|
|
|
// TestSteps tests many combinations of creates, updates, deletes, replacements, and so on.
|
|
func TestSteps(t *testing.T) {
|
|
integration.ProgramTest(t, &integration.ProgramTestOptions{
|
|
Dir: "step1",
|
|
Dependencies: []string{"@pulumi/pulumi"},
|
|
Quick: true,
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
assert.NotNil(t, stackInfo.Deployment)
|
|
validateResources(t, stackInfo.Deployment.Resources, "a", "b", "c", "d")
|
|
},
|
|
EditDirs: []integration.EditDir{
|
|
{
|
|
Dir: "step2",
|
|
Additive: true,
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
assert.NotNil(t, stackInfo.Deployment)
|
|
validateResources(t, stackInfo.Deployment.Resources, "a", "b", "c", "e")
|
|
},
|
|
},
|
|
{
|
|
Dir: "step3",
|
|
Additive: true,
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
assert.NotNil(t, stackInfo.Deployment)
|
|
validateResources(t, stackInfo.Deployment.Resources, "a", "c", "e")
|
|
},
|
|
},
|
|
{
|
|
Dir: "step4",
|
|
Additive: true,
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
assert.NotNil(t, stackInfo.Deployment)
|
|
validateResources(t, stackInfo.Deployment.Resources, "a", "c", "e")
|
|
},
|
|
},
|
|
{
|
|
Dir: "step5",
|
|
Additive: true,
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
assert.NotNil(t, stackInfo.Deployment)
|
|
validateResources(t, stackInfo.Deployment.Resources, "a", "c", "e")
|
|
},
|
|
},
|
|
{
|
|
Dir: "step6",
|
|
Additive: true,
|
|
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
|
|
assert.NotNil(t, stackInfo.Deployment)
|
|
validateResources(t, stackInfo.Deployment.Resources)
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|