-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't delete resources unless field managers match
- Loading branch information
Showing
9 changed files
with
287 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/pulumi/providertest/pulumitest" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDeleteDueToRename(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
test := pulumitest.NewPulumiTest(t, "delete/rename") | ||
t.Cleanup(func() { | ||
test.Destroy() | ||
}) | ||
|
||
test.Up() | ||
|
||
// Change our Pod's resource name | ||
test.UpdateSource("testdata/delete/rename/step2") | ||
test.Up() | ||
|
||
// Renaming the namespace should not have deleted it. Perform a refresh and | ||
// make sure our pod is still running -- if it's not, Pulumi will have | ||
// deleted it from our state. | ||
refresh, err := test.CurrentStack().Refresh(ctx) | ||
assert.NoError(t, err) | ||
assert.NotContains(t, refresh.StdOut, "deleted", refresh.StdOut) | ||
} | ||
|
||
func TestDeletePatchResource(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
test := pulumitest.NewPulumiTest(t, "testdata/delete/patch") | ||
t.Cleanup(func() { | ||
test.Destroy() | ||
}) | ||
|
||
test.Up() | ||
|
||
time.Sleep(60 * time.Second) | ||
|
||
outputs, err := test.CurrentStack().Outputs(ctx) | ||
require.NoError(t, err) | ||
|
||
// The ConfigMap should have 3 managed fields -- one for the URN annotation | ||
// and 2 for the patches. | ||
mf, ok := outputs["managedFields"] | ||
require.True(t, ok) | ||
assert.Len(t, mf.Value, 3) | ||
|
||
// Delete a patch. | ||
test.UpdateSource("testdata/delete/patch/step2") | ||
test.Up() | ||
|
||
// One ConfigMapPatch should still be applied, plus a manager for our URN | ||
// annotation. | ||
outputs, err = test.CurrentStack().Outputs(ctx) | ||
require.NoError(t, err) | ||
mf, ok = outputs["managedFields"] | ||
require.True(t, ok) | ||
assert.Len(t, mf.Value, 2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: delete-patch-resource | ||
runtime: yaml | ||
description: | | ||
Deleting a logical patch resource should not delete the underlying physical | ||
resource. | ||
outputs: | ||
managedFields: ${patch2.metadata.managedFields} | ||
|
||
resources: | ||
configmap: | ||
type: kubernetes:core/v1:ConfigMap | ||
properties: | ||
metadata: | ||
name: patched-configmap | ||
|
||
patch1: | ||
type: kubernetes:core/v1:ConfigMapPatch | ||
properties: | ||
metadata: | ||
name: patched-configmap | ||
data: | ||
foo: bar | ||
options: | ||
dependsOn: | ||
- ${configmap} | ||
|
||
patch2: | ||
type: kubernetes:core/v1:ConfigMapPatch | ||
properties: | ||
metadata: | ||
name: patched-configmap | ||
data: | ||
boo: baz | ||
options: | ||
dependsOn: | ||
- ${patch1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: delete-patch-resource | ||
runtime: yaml | ||
description: | | ||
Deleting a logical patch resource should not delete the underlying physical | ||
resource. | ||
outputs: | ||
managedFields: ${patch1.metadata.managedFields} | ||
|
||
resources: | ||
configmap: | ||
type: kubernetes:core/v1:ConfigMap | ||
properties: | ||
metadata: | ||
name: patched-configmap | ||
|
||
patch1: | ||
type: kubernetes:core/v1:ConfigMapPatch | ||
properties: | ||
metadata: | ||
name: patched-configmap | ||
data: | ||
foo: bar | ||
options: | ||
dependsOn: | ||
- ${configmap} | ||
|
||
# Delete patch2 - the underlying ConfigMap should not be deleted, and patch1 | ||
# should still be applied. | ||
# | ||
# patch2: | ||
# type: kubernetes:core/v1:ConfigMapPatch | ||
# properties: | ||
# metadata: | ||
# name: patched-configmap | ||
# data: | ||
# boo: baz | ||
# options: | ||
# dependsOn: | ||
# - ${patch1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: delete-with-rename | ||
runtime: yaml | ||
description: | | ||
Changing a resource's name, but leaving .metadata untouched, should not | ||
result in a deletion from the cluster. | ||
resources: | ||
pod: | ||
type: kubernetes:core/v1:Pod | ||
properties: | ||
spec: | ||
containers: | ||
- image: nginx:1.14.2 | ||
name: nginx | ||
ports: | ||
- containerPort: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: delete-with-rename | ||
runtime: yaml | ||
description: | | ||
Changing a resource's name, but leaving .metadata untouched, should not | ||
result in a deletion from the cluster. | ||
resources: | ||
# Change the resource's name from "pod" to "mypod" but leave everything | ||
# else the same. | ||
mypod: | ||
type: kubernetes:core/v1:Pod | ||
properties: | ||
spec: | ||
containers: | ||
- image: nginx:1.14.2 | ||
name: nginx | ||
ports: | ||
- containerPort: 80 |