diff --git a/tests/sdk/nodejs/nodejs_test.go b/tests/sdk/nodejs/nodejs_test.go index a5fab3ea02..9644aaee36 100644 --- a/tests/sdk/nodejs/nodejs_test.go +++ b/tests/sdk/nodejs/nodejs_test.go @@ -1037,3 +1037,43 @@ func TestYAMLURL(t *testing.T) { }) integration.ProgramTest(t, &test) } + +func TestReplaceDaemonSet(t *testing.T) { + daemonSetName := "" + test := baseOptions.With(integration.ProgramTestOptions{ + Dir: filepath.Join("replace-daemonset", "step1"), + Quick: true, + ExpectFailure: false, + SkipRefresh: true, + ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) { + assert.NotNil(t, stackInfo.Deployment) + assert.Equal(t, 3, len(stackInfo.Deployment.Resources)) + + // Save the DaemonSet name to compare it in the step2 + daemonSetName = stackInfo.Outputs["name"].(string) + + // Assert that the DaemonSet was created + assert.True(t, strings.HasPrefix(stackInfo.Outputs["name"].(string), "test-replacement-")) + }, + EditDirs: []integration.EditDir{ + { + Dir: filepath.Join("replace-daemonset", "step2"), + Additive: true, + ExpectFailure: false, + ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) { + assert.NotNil(t, stackInfo.Deployment) + assert.Equal(t, 3, len(stackInfo.Deployment.Resources)) + + newDaemonSetName := stackInfo.Outputs["name"].(string) + + // Assert that the DaemonSet still exists + assert.True(t, strings.HasPrefix(newDaemonSetName, "test-replacement-")) + + // DaemonSet should have a different name as it was replaced + assert.True(t, daemonSetName != newDaemonSetName) + }, + }, + }, + }) + integration.ProgramTest(t, &test) +} diff --git a/tests/sdk/nodejs/replace-daemonset/step1/Pulumi.yaml b/tests/sdk/nodejs/replace-daemonset/step1/Pulumi.yaml new file mode 100644 index 0000000000..937c9c9149 --- /dev/null +++ b/tests/sdk/nodejs/replace-daemonset/step1/Pulumi.yaml @@ -0,0 +1,3 @@ +name: replace-daemonset +description: A program to test if the DaemonSet is replaced when the .spec.selector is updated +runtime: nodejs diff --git a/tests/sdk/nodejs/replace-daemonset/step1/index.ts b/tests/sdk/nodejs/replace-daemonset/step1/index.ts new file mode 100644 index 0000000000..65f56e7377 --- /dev/null +++ b/tests/sdk/nodejs/replace-daemonset/step1/index.ts @@ -0,0 +1,17 @@ +import * as k8s from "@pulumi/kubernetes"; + +const appLabels = { + app: "nginx", +}; + +const daemonset = new k8s.apps.v1.DaemonSet("test-replacement", { + spec: { + selector: { matchLabels: appLabels }, + template: { + metadata: { labels: appLabels }, + spec: { containers: [{ name: "nginx", image: "nginx" }] }, + }, + }, +}); + +export const name = daemonset.metadata.name; diff --git a/tests/sdk/nodejs/replace-daemonset/step1/package.json b/tests/sdk/nodejs/replace-daemonset/step1/package.json new file mode 100644 index 0000000000..8063d83833 --- /dev/null +++ b/tests/sdk/nodejs/replace-daemonset/step1/package.json @@ -0,0 +1,12 @@ +{ + "name": "daemonset-replacement", + "version": "0.1.0", + "dependencies": { + "@pulumi/pulumi": "latest" + }, + "devDependencies": { + }, + "peerDependencies": { + "@pulumi/kubernetes": "latest" + } +} diff --git a/tests/sdk/nodejs/replace-daemonset/step1/tsconfig.json b/tests/sdk/nodejs/replace-daemonset/step1/tsconfig.json new file mode 100644 index 0000000000..3086b63abd --- /dev/null +++ b/tests/sdk/nodejs/replace-daemonset/step1/tsconfig.json @@ -0,0 +1,21 @@ +{ + "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" + ] +} diff --git a/tests/sdk/nodejs/replace-daemonset/step2/index.ts b/tests/sdk/nodejs/replace-daemonset/step2/index.ts new file mode 100644 index 0000000000..e629546512 --- /dev/null +++ b/tests/sdk/nodejs/replace-daemonset/step2/index.ts @@ -0,0 +1,18 @@ +import * as k8s from "@pulumi/kubernetes"; + +const appLabels = { + app: "nginx", + test: "new-value", +}; + +const daemonset = new k8s.apps.v1.DaemonSet("test-replacement", { + spec: { + selector: { matchLabels: appLabels }, + template: { + metadata: { labels: appLabels }, + spec: { containers: [{ name: "nginx", image: "nginx" }] }, + }, + }, +}); + +export const name = daemonset.metadata.name;