-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not patch field managers for Patch resources (#2640)
### Proposed changes This pull request addresses the issue where Patch resources unintentionally patch field managers during update operations (ie. when a Patch resource is updated and reused). Such modification results in the Patch resource taking control of all fields managed owned by a field manager with the prefix `kubectl`. This, in turn, leads to unintended unset fields when running `pulumi up`. Patch resources are designed to contain a specific subset of fields for updating, and they should not interfere with the field managers of normal resources. It's important to note that field managers still need to be patched for regular resources, as they facilitate the transition from Client-Side Apply (CSA) to Server-Side Apply (SSA) for existing Pulumi-managed resources. Additionally, this PR includes a new test to validate this behavior. The test will fail if the logic to avoid field manager patching for Patch resources is not implemented. ### Related issues: Fixes: #2639
- Loading branch information
Showing
9 changed files
with
262 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
37 changes: 37 additions & 0 deletions
37
tests/sdk/nodejs/field-manager-patch-resources/deployment.yaml
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 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: test-mgr-nginx | ||
labels: | ||
app: nginx | ||
spec: | ||
progressDeadlineSeconds: 600 | ||
replicas: 2 | ||
revisionHistoryLimit: 10 | ||
selector: | ||
matchLabels: | ||
app: nginx | ||
strategy: | ||
rollingUpdate: | ||
maxSurge: 25% | ||
maxUnavailable: 25% | ||
type: RollingUpdate | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- image: nginx:1.14.2 | ||
imagePullPolicy: IfNotPresent | ||
name: nginx | ||
ports: | ||
- containerPort: 80 | ||
protocol: TCP | ||
terminationMessagePath: /dev/termination-log | ||
terminationMessagePolicy: File | ||
dnsPolicy: ClusterFirst | ||
restartPolicy: Always | ||
schedulerName: default-scheduler | ||
securityContext: {} | ||
terminationGracePeriodSeconds: 30 |
3 changes: 3 additions & 0 deletions
3
tests/sdk/nodejs/field-manager-patch-resources/step1/Pulumi.yaml
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,3 @@ | ||
name: field-mgr-patch-resources-tests | ||
description: Tests Field Manager with Patch resources | ||
runtime: nodejs |
49 changes: 49 additions & 0 deletions
49
tests/sdk/nodejs/field-manager-patch-resources/step1/index.ts
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,49 @@ | ||
// Copyright 2016-2023, 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. | ||
|
||
import * as k8s from "@pulumi/kubernetes"; | ||
import * as pulumi from "@pulumi/pulumi"; | ||
|
||
// Create provider with SSA enabled. | ||
const provider = new k8s.Provider("k8s", { enableServerSideApply: true }); | ||
|
||
const config = new pulumi.Config(); | ||
const namespace = config.require("namespace"); | ||
|
||
const depPatch = new k8s.apps.v1.DeploymentPatch( | ||
"nginx-patch", | ||
{ | ||
metadata: { | ||
namespace: namespace, | ||
name: "test-mgr-nginx", | ||
annotations: { | ||
"pulumi.com/patchForce": "true", | ||
}, | ||
}, | ||
spec: { | ||
template: { | ||
metadata: { | ||
labels: undefined, | ||
}, | ||
spec: { | ||
containers: [ | ||
{ | ||
name: "nginx", | ||
image: "nginx:1.14.1", | ||
}, | ||
], | ||
}, | ||
} | ||
}, | ||
}, { provider: provider, retainOnDelete: true }); |
11 changes: 11 additions & 0 deletions
11
tests/sdk/nodejs/field-manager-patch-resources/step1/package.json
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,11 @@ | ||
{ | ||
"name": "server-side-apply", | ||
"version": "0.1.0", | ||
"dependencies": { | ||
"@pulumi/pulumi": "latest", | ||
"@pulumi/random": "latest" | ||
}, | ||
"peerDependencies": { | ||
"@pulumi/kubernetes": "latest" | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/sdk/nodejs/field-manager-patch-resources/step1/tsconfig.json
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,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es6", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"stripInternal": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strictNullChecks": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} | ||
|
49 changes: 49 additions & 0 deletions
49
tests/sdk/nodejs/field-manager-patch-resources/step2/index.ts
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,49 @@ | ||
// Copyright 2016-2023, 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. | ||
|
||
import * as k8s from "@pulumi/kubernetes"; | ||
import * as pulumi from "@pulumi/pulumi"; | ||
|
||
// Create provider with SSA enabled. | ||
const provider = new k8s.Provider("k8s", { enableServerSideApply: true }); | ||
|
||
const config = new pulumi.Config(); | ||
const namespace = config.require("namespace"); | ||
|
||
const depPatch = new k8s.apps.v1.DeploymentPatch( | ||
"nginx-patch", | ||
{ | ||
metadata: { | ||
namespace: namespace, | ||
name: "test-mgr-nginx", | ||
annotations: { | ||
"pulumi.com/patchForce": "true", | ||
}, | ||
}, | ||
spec: { | ||
template: { | ||
metadata: { | ||
labels: undefined, | ||
}, | ||
spec: { | ||
containers: [ | ||
{ | ||
name: "nginx", | ||
image: "nginx:1.14.0", | ||
}, | ||
], | ||
}, | ||
} | ||
}, | ||
}, { provider: provider, retainOnDelete: true }); |
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