Skip to content

Commit 9927dce

Browse files
committed
tests: add e2e test to validate auth err does not destroy pod
1 parent 352471d commit 9927dce

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-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+
"workspaces/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: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
# ServiceAccount for the random-yaml-auth-error namespace.
36+
# No permissions are granted to this service account.
37+
apiVersion: v1
38+
kind: ServiceAccount
39+
metadata:
40+
name: random-yaml-auth-error
41+
namespace: random-yaml-auth-error
42+
---
43+
# Define a Flux Source GitRepository object for syncing Pulumi examples from a GitHub repository
44+
apiVersion: source.toolkit.fluxcd.io/v1
45+
kind: GitRepository
46+
metadata:
47+
name: pulumi-examples
48+
namespace: random-yaml-auth-error
49+
spec:
50+
interval: 10m
51+
ref:
52+
branch: master
53+
timeout: 60s
54+
url: https://github.com/pulumi/examples
55+
---
56+
apiVersion: pulumi.com/v1
57+
kind: Stack
58+
metadata:
59+
name: random-yaml-auth-error
60+
namespace: random-yaml-auth-error
61+
spec:
62+
fluxSource:
63+
sourceRef:
64+
apiVersion: source.toolkit.fluxcd.io/v1
65+
kind: GitRepository
66+
name: pulumi-examples
67+
dir: random-yaml
68+
stack: dev
69+
refresh: false
70+
continueResyncOnCommitMatch: false
71+
resyncFrequencySeconds: 60
72+
destroyOnFinalize: true
73+
# Enable file state for testing.
74+
envRefs:
75+
PULUMI_BACKEND_URL:
76+
type: Literal
77+
literal:
78+
value: "file:///state/"
79+
PULUMI_CONFIG_PASSPHRASE:
80+
type: Literal
81+
literal:
82+
value: "test"
83+
workspaceTemplate:
84+
spec:
85+
serviceAccountName: random-yaml-auth-error
86+
podTemplate:
87+
spec:
88+
containers:
89+
- name: pulumi

0 commit comments

Comments
 (0)