-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't delete resources unless field managers match #3407
Open
blampe
wants to merge
1
commit into
master
Choose a base branch
from
blampe/delete-after-create-field-manager
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2025, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package test | ||
|
||
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, "testdata/delete/rename") | ||
t.Cleanup(func() { | ||
test.Destroy(t) | ||
}) | ||
|
||
test.Up(t) | ||
|
||
// Change our Pod's resource name | ||
test.UpdateSource(t, "testdata/delete/rename/step2") | ||
test.Up(t) | ||
|
||
// 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(t) | ||
}) | ||
|
||
test.Up(t) | ||
|
||
time.Sleep(60 * time.Second) | ||
|
||
outputs, err := test.CurrentStack().Outputs(ctx) | ||
require.NoError(t, err) | ||
|
||
// The ConfigMap should have 2 managed fields. | ||
mf, ok := outputs["managedFields"] | ||
require.True(t, ok) | ||
assert.Len(t, mf.Value, 2) | ||
|
||
// Delete a patch. | ||
test.UpdateSource(t, "testdata/delete/patch/step2") | ||
test.Up(t) | ||
|
||
// One ConfigMapPatch should still be applied. | ||
outputs, err = test.CurrentStack().Outputs(ctx) | ||
require.NoError(t, err) | ||
mf, ok = outputs["managedFields"] | ||
require.True(t, ok) | ||
assert.Len(t, mf.Value, 1) | ||
} |
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written this would also no-op in cases where the object was updated with CSA.
We can narrow this by also checking
actualSSAManagers
is non-empty, so we know the live object was at least touched by pulumi.