Skip to content

Commit

Permalink
tests: add test case to repro #3022 with Jobs and unreachable clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
rquitales committed May 24, 2024
1 parent fa7330c commit 4941116
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/sdk/java/testdata/job-unreachable/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions tests/sdk/java/testdata/job-unreachable/step2/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions tests/sdk/java/yamlv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
}

0 comments on commit 4941116

Please sign in to comment.