Skip to content

Commit 9792438

Browse files
committed
test: Add e2e tests for multiple installs in the same cluster
Signed-off-by: Jonathan Stacks <[email protected]>
1 parent 029fd83 commit 9792438

File tree

12 files changed

+231
-1
lines changed

12 files changed

+231
-1
lines changed

.github/actions/build-and-test/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ inputs:
1717
kind-version:
1818
description: "KIND version to use"
1919
required: false
20-
default: "v0.26.0"
20+
default: "v0.30.0"
2121

2222
runs:
2323
using: "composite"

.github/workflows/ci.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,50 @@ jobs:
182182
run-e2e: true
183183
ngrok-api-key: ${{ secrets.NGROK_CI_API_KEY }}
184184
ngrok-authtoken: ${{ secrets.NGROK_CI_AUTHTOKEN }}
185+
186+
e2e-multi-namespace:
187+
runs-on: ubuntu-latest
188+
needs:
189+
- changes
190+
- kubebuilder-diff
191+
- lint
192+
- e2e
193+
concurrency:
194+
group: e2e
195+
cancel-in-progress: false
196+
timeout-minutes: 30
197+
if: |
198+
(github.repository == 'ngrok/ngrok-operator') &&
199+
(
200+
(github.event_name == 'push' && github.ref_name == 'main') ||
201+
(github.event_name == 'merge_group')
202+
) &&
203+
(
204+
(needs.changes.outputs.go == 'true') ||
205+
(needs.changes.outputs.charts == 'true') ||
206+
(needs.changes.outputs.chartyaml == 'true') ||
207+
(needs.changes.outputs.tests == 'true') ||
208+
(needs.changes.outputs.make == 'true')
209+
)
210+
steps:
211+
- uses: actions/checkout@v6
212+
- uses: nixbuild/nix-quick-install-action@v34
213+
- uses: DeterminateSystems/magic-nix-cache-action@b8276522d77f21bf19d3574e5bc99186a6c7aa6c
214+
- name: Create Kind Cluster
215+
run: nix develop --command make kind-create
216+
- name: Deploy
217+
run: nix develop --command make deploy_multi_namespace
218+
env:
219+
NGROK_API_KEY: ${{ secrets.NGROK_CI_API_KEY }}
220+
NGROK_AUTHTOKEN: ${{ secrets.NGROK_CI_AUTHTOKEN }}
221+
- name: Test
222+
run: nix develop --command make e2e-tests-multi-ns
223+
- name: Cleanup
224+
if: always()
225+
run: |
226+
echo "Deleting kubernetesoperators..."
227+
kubectl -n namespace-a delete kubernetesoperator ngrok-operator-a || true
228+
kubectl -n namespace-b delete kubernetesoperator ngrok-operator-b || true
229+
echo "Uninstalling the operators..."
230+
helm uninstall ngrok-operator-a -n namespace-a || true
231+
helm uninstall ngrok-operator-b -n namespace-b || true

tests/chainsaw-multi-ns/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Multi-Namespace E2E Tests
2+
3+
This directory contains Chainsaw tests for validating multi-namespace operator deployments.
4+
5+
## Prerequisites
6+
7+
These tests assume the cluster has been set up using `make deploy_multi_namespace`, which deploys:
8+
9+
1. **CRDs** installed once in `kube-system` via `ngrok-operator-crds` helm chart
10+
2. **Operator A** (`ngrok-operator-a`) in `namespace-a`:
11+
- Watches only `namespace-a`
12+
- Uses ingress class `ngrok-a`
13+
- Controller name: `k8s.ngrok.com/ingress-controller-a`
14+
3. **Operator B** (`ngrok-operator-b`) in `namespace-b`:
15+
- Watches only `namespace-b`
16+
- Uses ingress class `ngrok-b`
17+
- Controller name: `k8s.ngrok.com/ingress-controller-b`
18+
19+
## Running Locally
20+
21+
```bash
22+
# Set up the multi-namespace deployment
23+
make deploy_multi_namespace
24+
25+
# Run the tests
26+
make e2e-tests-multi-ns
27+
```
28+
29+
## Test Structure
30+
31+
- **sanity-checks/**: Validates both operators are running and ingress classes exist
32+
- **operator-registration/**: Tests that the operators correctly register with ngrok and receive an ID.
33+
34+
## Writing New Tests
35+
36+
When adding tests to this directory:
37+
38+
- Use explicit `metadata.namespace` values (`namespace-a` or `namespace-b`)
39+
- Use the correct `ingressClassName` (`ngrok-a` or `ngrok-b`)
40+
- Focus on multi-operator isolation behaviors that can't be tested with a single operator
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Test
4+
metadata:
5+
name: multi-ns-operator-registration
6+
spec:
7+
steps:
8+
- name: assert KubernetesOperator/ngrok-operator-a is registered in namespace-a
9+
try:
10+
- assert:
11+
resource:
12+
apiVersion: ngrok.k8s.ngrok.com/v1alpha1
13+
kind: KubernetesOperator
14+
metadata:
15+
name: ngrok-operator-a
16+
namespace: namespace-a
17+
spec:
18+
deployment:
19+
name: ngrok-operator-a
20+
namespace: namespace-a
21+
status:
22+
registrationStatus: registered
23+
(id != null && starts_with(id, 'k8sop_')): true
24+
(uri != null): true
25+
26+
- name: assert KubernetesOperator/ngrok-operator-b is registered in namespace-b
27+
try:
28+
- assert:
29+
resource:
30+
apiVersion: ngrok.k8s.ngrok.com/v1alpha1
31+
kind: KubernetesOperator
32+
metadata:
33+
name: ngrok-operator-b
34+
namespace: namespace-b
35+
spec:
36+
deployment:
37+
name: ngrok-operator-b
38+
namespace: namespace-b
39+
status:
40+
registrationStatus: registered
41+
(id != null && starts_with(id, 'k8sop_')): true
42+
(uri != null): true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
labels:
5+
app.kubernetes.io/component: agent
6+
namespace: namespace-a
7+
status:
8+
(conditions[?type == 'Ready']):
9+
- status: "True"
10+
~.containerStatuses:
11+
ready: true
12+
restartCount: 0
13+
phase: Running
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
labels:
5+
app.kubernetes.io/component: agent
6+
namespace: namespace-b
7+
status:
8+
(conditions[?type == 'Ready']):
9+
- status: "True"
10+
~.containerStatuses:
11+
ready: true
12+
restartCount: 0
13+
phase: Running
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Test
4+
metadata:
5+
name: multi-ns-sanity-checks
6+
spec:
7+
steps:
8+
- name: check ingress class ngrok-a exists
9+
try:
10+
- assert:
11+
file: ./ingress-class-a.yaml
12+
- name: check ingress class ngrok-b exists
13+
try:
14+
- assert:
15+
file: ./ingress-class-b.yaml
16+
- name: check operator-a pods are running
17+
try:
18+
- assert:
19+
file: ./operator-pod-a.yaml
20+
- name: check operator-b pods are running
21+
try:
22+
- assert:
23+
file: ./operator-pod-b.yaml
24+
- name: check agent-a pods are running
25+
try:
26+
- assert:
27+
file: ./agent-pod-a.yaml
28+
- name: check agent-b pods are running
29+
try:
30+
- assert:
31+
file: ./agent-pod-b.yaml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: IngressClass
3+
metadata:
4+
name: ngrok-a
5+
spec:
6+
controller: k8s.ngrok.com/ingress-controller-a
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: IngressClass
3+
metadata:
4+
name: ngrok-b
5+
spec:
6+
controller: k8s.ngrok.com/ingress-controller-b
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
labels:
5+
app.kubernetes.io/component: controller
6+
namespace: namespace-a
7+
status:
8+
(conditions[?type == 'Ready']):
9+
- status: "True"
10+
~.containerStatuses:
11+
ready: true
12+
restartCount: 0
13+
phase: Running

0 commit comments

Comments
 (0)