Skip to content

Commit 856207d

Browse files
committed
tests: add e2e test to validate auth err does not destroy pod
1 parent 7b2f293 commit 856207d

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

operator/e2e/e2e_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,35 @@ func TestE2E(t *testing.T) {
153153
assert.NotContains(t, stack.Status.Outputs, "notTargeted")
154154
},
155155
},
156+
{
157+
name: "random-yaml-auth-error",
158+
f: func(t *testing.T) {
159+
t.Parallel()
160+
161+
cmd := exec.Command("kubectl", "apply", "-f", "e2e/testdata/random-yaml-auth-error")
162+
require.NoError(t, run(cmd))
163+
dumpLogs(t, "random-yaml-auth-error", "pod/random-yaml-auth-error-workspace-0")
164+
165+
// Ensure the stack is in a failed state with Unauthenticated.
166+
_, err := waitFor[pulumiv1.Stack](
167+
"stacks/random-yaml-auth-error",
168+
"random-yaml-auth-error",
169+
5*time.Minute,
170+
`jsonpath={.status.conditions[?(@.type=="Ready")].reason}=Unauthenticated`)
171+
assert.NoError(t, err)
172+
173+
// Ensure that we see the event for a succesful StatefulSet creation.
174+
found, err := foundEvent("StatefulSet", "random-yaml-auth-error-workspace", "random-yaml-auth-error", "SuccessfulCreate")
175+
assert.NoError(t, err)
176+
assert.True(t, found)
177+
178+
// Ensure that the workspace pod was not deleted after reconciling the failed stack.
179+
time.Sleep(10 * time.Second)
180+
found, err = foundEvent("Pod", "random-yaml-auth-error-workspace-0", "random-yaml-auth-error", "Killing")
181+
assert.NoError(t, err)
182+
assert.False(t, found)
183+
},
184+
},
156185
}
157186

158187
for _, tt := range tests {
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
# This NetworkPolicy allows ingress traffic to the source-controller pods
3+
# from specific namespaces and pods managed by pulumi-kubernetes-operator.
4+
apiVersion: networking.k8s.io/v1
5+
kind: NetworkPolicy
6+
metadata:
7+
name: allow-random-yaml-auth-error-fetch
8+
namespace: flux-system
9+
spec:
10+
podSelector:
11+
matchLabels:
12+
app: source-controller
13+
ingress:
14+
- ports:
15+
- protocol: TCP
16+
port: http
17+
from:
18+
- namespaceSelector:
19+
matchLabels:
20+
kubernetes.io/metadata.name: random-yaml-auth-error
21+
- podSelector:
22+
matchLabels:
23+
app.kubernetes.io/managed-by: pulumi-kubernetes-operator
24+
app.kubernetes.io/name: pulumi
25+
app.kubernetes.io/component: workspace
26+
policyTypes:
27+
- Ingress
28+
---
29+
# Namespace to isolate the random-yaml-auth-error test.
30+
apiVersion: v1
31+
kind: Namespace
32+
metadata:
33+
name: random-yaml-auth-error
34+
---
35+
# Define a Flux Source GitRepository object for syncing Pulumi examples from a GitHub repository
36+
apiVersion: source.toolkit.fluxcd.io/v1
37+
kind: GitRepository
38+
metadata:
39+
name: pulumi-examples
40+
namespace: random-yaml-auth-error
41+
spec:
42+
interval: 10m
43+
ref:
44+
branch: master
45+
timeout: 60s
46+
url: https://github.com/pulumi/examples
47+
---
48+
apiVersion: pulumi.com/v1
49+
kind: Stack
50+
metadata:
51+
name: random-yaml-auth-error
52+
namespace: random-yaml-auth-error
53+
spec:
54+
fluxSource:
55+
sourceRef:
56+
apiVersion: source.toolkit.fluxcd.io/v1
57+
kind: GitRepository
58+
name: pulumi-examples
59+
dir: random-yaml
60+
stack: dev
61+
refresh: false
62+
continueResyncOnCommitMatch: false
63+
resyncFrequencySeconds: 60
64+
destroyOnFinalize: true
65+
# Enable file state for testing.
66+
envRefs:
67+
PULUMI_BACKEND_URL:
68+
type: Literal
69+
literal:
70+
value: "file:///state/"
71+
PULUMI_CONFIG_PASSPHRASE:
72+
type: Literal
73+
literal:
74+
value: "test"
75+
workspaceTemplate:
76+
spec:
77+
serviceAccountName: nonexistent-service-account # Purposefully incorrect service account name, to trigger authz error.
78+
podTemplate:
79+
spec:
80+
containers:
81+
- name: pulumi
82+
volumeMounts:
83+
- name: state
84+
mountPath: /state
85+
volumes:
86+
- name: state
87+
persistentVolumeClaim:
88+
claimName: state

0 commit comments

Comments
 (0)