diff --git a/tests/sdk/java/testdata/job-unreachable/Pulumi.yaml b/tests/sdk/java/testdata/job-unreachable/Pulumi.yaml new file mode 100644 index 0000000000..1028420cbb --- /dev/null +++ b/tests/sdk/java/testdata/job-unreachable/Pulumi.yaml @@ -0,0 +1,32 @@ +name: job-unreachable +runtime: yaml +resources: + provider: + type: pulumi:providers:kubernetes + job: + type: kubernetes:batch/v1:Job + properties: + metadata: + name: test-job-unreachable + annotations: + pulumi.com/replaceUnready: "true" + spec: + template: + metadata: + name: test-job-unreachable + spec: + containers: + - name: test-job-unreachable-container + image: busybox + # This command will cause the container to exit with a non-zero status code, and fail the job. + command: + - sh + - -c + - exit 1 + restartPolicy: Never + options: + provider: ${provider} + customTimeouts: + create: 15s + update: 15s + delete: 15s \ No newline at end of file diff --git a/tests/sdk/java/testdata/job-unreachable/step2/Pulumi.yaml b/tests/sdk/java/testdata/job-unreachable/step2/Pulumi.yaml new file mode 100644 index 0000000000..5d6063a7f2 --- /dev/null +++ b/tests/sdk/java/testdata/job-unreachable/step2/Pulumi.yaml @@ -0,0 +1,34 @@ +name: job-unreachable +runtime: yaml +resources: + provider: + type: pulumi:providers:kubernetes + properties: + kubeconfig: "fake-kubeconfig-data" + job: + type: kubernetes:batch/v1:Job + properties: + metadata: + name: test-job-unreachable + annotations: + pulumi.com/replaceUnready: "true" + spec: + template: + metadata: + name: test-job-unreachable + spec: + containers: + - name: test-job-unreachable-container + image: busybox + # This command will cause the container to exit with a non-zero status code, and fail the job. + command: + - sh + - -c + - exit 1 + restartPolicy: Never + options: + provider: ${provider} + customTimeouts: + create: 15s + update: 15s + delete: 15s \ No newline at end of file diff --git a/tests/sdk/java/yamlv2_test.go b/tests/sdk/java/yamlv2_test.go index 507de8268b..ec317823b6 100644 --- a/tests/sdk/java/yamlv2_test.go +++ b/tests/sdk/java/yamlv2_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/pulumi/providertest/pulumitest" + "github.com/stretchr/testify/assert" ) // TestYamlV2 deploys a complex stack using yaml/v2 package. @@ -21,3 +22,23 @@ func TestYamlV2(t *testing.T) { test.Preview() test.Up() } + +// TestJobUnreachable ensures that a panic does not occur when diffing Job resources against an unreachable API server. +// https://github.com/pulumi/pulumi-kubernetes/issues/3022 +func TestJobUnreachable(t *testing.T) { + test := pulumitest.NewPulumiTest(t, "testdata/job-unreachable") + t.Logf("into %s", test.Source()) + t.Cleanup(func() { + test.Destroy() + }) + test.Preview() + + // Create the job, but expect it to fail as the job is meant to fail. + _, err := test.CurrentStack().Up(test.Context()) + assert.ErrorContains(t, err, `but the Kubernetes API server reported that it failed to fully initialize or become live`) + + // Re-run the Pulumi program with a malformed kubeconfig to simulate an unreachable API server. + // This should not panic annd preview should succeed. + test.UpdateSource("testdata/job-unreachable/step2") + test.Preview() +}