Skip to content

Commit 214ee83

Browse files
authored
feat: introduce e2e test (#608)
* test: introduce e2e test * remove routes * cleanup * check pods * rbac * fix: correct event callback handling as action is now required * print controller logs * print controller logs * check for erro in log
1 parent 6eec60a commit 214ee83

17 files changed

Lines changed: 229 additions & 116 deletions

.github/workflows/e2e.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: e2e tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
12+
cancel-in-progress: true
13+
jobs:
14+
e2e:
15+
name: Run end-2-end Tests
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: 🛒 Checkout
19+
uses: actions/checkout@v6
20+
21+
- name: 🖼 Build image
22+
run: docker build -f Dockerfile --build-arg VERSION=e2e-tests -t batch-job-controller:e2e .
23+
24+
- name: 🤖 Install kind with registry
25+
uses: bakito/kind-with-registry-action@main
26+
with:
27+
docker_image_name: batch-job-controller:e2e
28+
29+
- name: 🚀 Install helm chart
30+
run: ./testdata/e2e/installChart.sh
31+
- name: ⏳ Wait for a job pod to be executed
32+
run: ./testdata/e2e/findExecutedJobPod.sh
33+
- name: 🧾 Print and check controller logs/events
34+
run: ./testdata/e2e/checkAndPrintControllerLogsAndEvents.sh
35+
36+

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ lint: tb.golangci-lint
2222

2323
# Run tests
2424
helm-lint: helm
25-
helm lint helm/example-batch-job-controller/ --set routes.hostSuffix=test.com --strict
25+
helm lint helm/example-batch-job-controller/ --strict
2626

2727
helm-template: helm-lint
28-
helm template helm/example-batch-job-controller/ --debug --set routes.hostSuffix=test.com
28+
helm template helm/example-batch-job-controller/ --debug
2929

3030
# Build docker image
3131
build-docker:

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,25 @@ metrics:
5757
5858
### pod-template.yaml
5959
60-
The template of the pod to be started for each job. When a pod is created it gets enriched by the controller specific
61-
configuration. [pkg\job\job.go](pkg\job\job.go)
60+
The template of the pod to be started for each job. When a pod is created, it gets enriched by the controller-specific
61+
configuration. [pkg/job/job.go](pkg/job/job.go)
6262
6363
## Job Pod
6464
6565
The job pod has the following env variables provided by the controller:
6666
6767
### Environment
6868
69-
| Name | Value |
70-
| --- | --- |
71-
| NAMESPACE | The current namespace |
72-
| NODE_NAME | The name of the node it is running on |
73-
| EXECUTION_ID | The id of the current job execution |
74-
| CALLBACK_SERVICE_NAME | The name/host/ip of the callback service to send the report to |
75-
| CALLBACK_SERVICE_PORT | The port of the callback service to send the report to |
76-
| CALLBACK_SERVICE_RESULT_URL | The full qualified URL of the result callback service |
77-
| CALLBACK_SERVICE_FILE_URL | The full qualified URL of the file callback service, to send files to the controller |
78-
| CALLBACK_SERVICE_EVENT_URL | The full qualified URL of the event callback service, to create k8s event |
69+
| Name | Value |
70+
|-----------------------------|--------------------------------------------------------------------------------------|
71+
| NAMESPACE | The current namespace |
72+
| NODE_NAME | The name of the node it is running on |
73+
| EXECUTION_ID | The id of the current job execution |
74+
| CALLBACK_SERVICE_NAME | The name/host/ip of the callback service to send the report to |
75+
| CALLBACK_SERVICE_PORT | The port of the callback service to send the report to |
76+
| CALLBACK_SERVICE_RESULT_URL | The full qualified URL of the result callback service |
77+
| CALLBACK_SERVICE_FILE_URL | The full qualified URL of the file callback service, to send files to the controller |
78+
| CALLBACK_SERVICE_EVENT_URL | The full qualified URL of the event callback service, to create k8s event |
7979
8080
### Callback
8181
@@ -112,7 +112,7 @@ decimal value and a map where the key is the label name and value is the value t
112112
}
113113
```
114114

115-
Example job script: [helm\batch-job-controller\bin\run.sh](helm\batch-job-controller\bin\run.sh)
115+
Example job script: [helm/example-batch-job-controller/bin/run.sh](helm/example-batch-job-controller/bin/run.sh)
116116

117117
### Upload additional files
118118

helm/example-batch-job-controller/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v2
22
name: batch-job-controller
3-
version: 1.4.8
4-
appVersion: v1.4.8
3+
version: 1.4.9
4+
appVersion: v1.4.9
55
description: Install batch job controller
66
icon: https://emojigraph.org/media/google/man-construction-worker_1f477-200d-2642-fe0f.png
77
sources:
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# batch-job-controller
22

3-
![Version: 1.4.8](https://img.shields.io/badge/Version-1.4.8-informational?style=flat-square) ![AppVersion: v1.4.8](https://img.shields.io/badge/AppVersion-v1.4.8-informational?style=flat-square)
3+
![Version: 1.4.9](https://img.shields.io/badge/Version-1.4.9-informational?style=flat-square) ![AppVersion: v1.4.9](https://img.shields.io/badge/AppVersion-v1.4.9-informational?style=flat-square)
44

55
Install batch job controller
66

@@ -9,14 +9,14 @@ Install batch job controller
99
### oci
1010

1111
```console
12-
helm install my-batch-job-controller oci://ghcr.io/bakito/helm-charts/batch-job-controller --version 1.4.8
12+
helm install my-batch-job-controller oci://ghcr.io/bakito/helm-charts/batch-job-controller --version 1.4.9
1313
```
1414

1515
### helm repository
1616

1717
```console
1818
helm repo add bakito https://charts.bakito.net
19-
helm install my-batch-job-controller bakito/batch-job-controller --version 1.4.8
19+
helm install my-batch-job-controller bakito/batch-job-controller --version 1.4.9
2020
```
2121

2222
## Values
@@ -27,6 +27,7 @@ helm install my-batch-job-controller bakito/batch-job-controller --version 1.4.8
2727
| deployment.cronExpression | string | `"* * * * *"` | Cron expression to start the jobs with |
2828
| deployment.env | string | `nil` | additional pod env |
2929
| deployment.image | string | `"ghcr.io/bakito/batch-job-controller"` | Repository to use |
30+
| deployment.imagePullPolicy | string | `"Always"` | Overrides the image pull policy. |
3031
| deployment.imageTag | string | `nil` | Overrides the image tag whose default is the chart appVersion. |
3132
| deployment.labels | string | `nil` | additional pod labels |
3233
| deployment.podPoolSize | int | `10` | The parallel pod pool size |
@@ -35,14 +36,12 @@ helm install my-batch-job-controller bakito/batch-job-controller --version 1.4.8
3536
| deployment.probes.startup | bool | `true` | Enable startup probes |
3637
| deployment.replicas | int | `1` | Controller pod count |
3738
| deployment.reportDirectory | string | `"/var/www"` | Report directory |
38-
| deployment.reportHistory | int | `10` | Define for how many jobs the reports sould be kept |
39+
| deployment.reportHistory | int | `10` | Define for how many jobs the reports should be kept |
3940
| deployment.runOnStartup | bool | `false` | Run jobs on startup |
4041
| deployment.storageClassName | string | `""` | Storage class name to be used if storage is enabled |
41-
| deployment.withPersistentVolume | bool | `true` | Enable persistent storage |
42-
| jobPod.image | string | `"registry.access.redhat.com/ubi8/ubi"` | The iabe to be uses as job pod |
42+
| deployment.withPersistentVolume | bool | `false` | Enable persistent storage |
43+
| jobPod.image | string | `"redhat/ubi10:latest"` | The image to be uses as job pod |
4344
| name | string | `"example-job-controller"` | Name |
44-
| routes.internal | bool | `true` | enable a route to access the internal files |
45-
| routes.metrics | bool | `true` | enable a route to access metrics |
4645

4746
----------------------------------------------
4847
Autogenerated from chart metadata using [helm-docs](https://github.com/norwoodj/helm-docs)
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
#!/bin/bash
22
trap '>&2 echo ERROR: Command on line $LINENO failed: $(tail -n+$LINENO $0 | head -n1) && exit 1' ERR
33

4-
echo "starting"
4+
echo "👷 starting job"
5+
echo
6+
echo "🔡 printing env"
57
env
8+
echo "😴 sleep 10s"
69
sleep 10
7-
echo "calling report callback: ${CALLBACK_SERVICE_RESULT_URL}"
10+
echo "📞 calling report callback: ${CALLBACK_SERVICE_RESULT_URL}"
811

12+
echo "- send file"
13+
curl --silent --show-error -X POST -H 'Content-Disposition: attachment;filename="test.txt"' --data-binary 'This is an uploaded file' "${CALLBACK_SERVICE_FILE_URL}"
914

15+
echo "- trigger event"
16+
curl --silent --show-error -X POST -H "Content-Type: application/json; charset=utf-8" --data-binary '{"warning": false,"reason": "TestReason","message": "test message with %s","args": ["arg"]}' "${CALLBACK_SERVICE_EVENT_URL}"
1017

11-
curl --silent --show-error -X POST -H 'Content-Disposition: attachment;filename="test.txt"' --data-binary 'This is an uploaded file' "${CALLBACK_SERVICE_FILE_URL}"
12-
curl --silent --show-error -X POST -H "Content-Type: application/json; charset=utf-8" --data-binary '{"warning": false,"action": "callback","reason": "TestReason","message": "test message with %s","args": ["arg"]}' "${CALLBACK_SERVICE_EVENT_URL}"
18+
echo "- send metric"
1319
curl --silent --show-error -X POST -H "Content-Type: application/json; charset=utf-8" --data-binary '{ "my_metric": [{ "value": 1.0, "labels": { "label_a": "AAA", "label_b": "BBB" }}] }' "${CALLBACK_SERVICE_RESULT_URL}"
1420

15-
echo "done"
21+
echo "🏁 done"

helm/example-batch-job-controller/templates/deployment.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ spec:
4040
fieldPath: status.podIP
4141
{{ include "batch-job-controller.deployment-env" . | indent 12 }}
4242
image: {{ .Values.deployment.image }}:{{- default .Chart.AppVersion .Values.deployment.imageTag }}
43-
imagePullPolicy: Always
43+
imagePullPolicy: {{ .Values.deployment.imagePullPolicy }}
4444
name: {{ template "batch-job-controller.name" . }}
4545
ports:
4646
- containerPort: 8080
@@ -102,10 +102,7 @@ spec:
102102
- mountPath: /tmp
103103
name: tmp-data
104104
dnsPolicy: ClusterFirst
105-
nodeSelector:
106-
node-group: app
107105
restartPolicy: Always
108-
serviceAccount: {{ template "batch-job-controller.name" . }}
109106
serviceAccountName: {{ template "batch-job-controller.name" . }}
110107
volumes:
111108
- name: tmp-data

helm/example-batch-job-controller/templates/job-template/_job-pod-template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spec:
77
- /opt/job/run.sh
88
image: {{ $.Values.jobPod.image }}
99
imagePullPolicy: Always
10-
name: openscap-scanner
10+
name: test-job
1111
resources:
1212
limits:
1313
cpu: 100m

helm/example-batch-job-controller/templates/rbac.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ rules:
7070
- deploymentconfigs
7171
verbs:
7272
- get
73+
- apiGroups:
74+
- coordination.k8s.io
75+
resources:
76+
- leases
77+
verbs:
78+
- get
79+
- list
80+
- watch
81+
- create
82+
- update
83+
- patch
84+
- delete
85+
- verbs:
86+
- create
87+
apiGroups:
88+
- events.k8s.io
89+
resources:
90+
- events
7391

7492
---
7593
# RoleBinding for the new role to the batch-job-controller service account

helm/example-batch-job-controller/templates/route-internal.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)