Triggering Periodic Integration Tests
In Konflux, you can run integration tests on a schedule using Kubernetes CronJobs.
Procedure
To trigger a periodic Integration Test, complete the following steps:
-
Create an integration test by following the Creating a integration test guide.
If the Integration Test is designed to only run periodically rather than during Pull Request checks or post-merge, you need to add the disabled context to the Integration Test. |
-
Create RBAC rules in your tenant to allow CronJob ServiceAccount to access snapshot.
-
Create a CronJob that will trigger periodic Integration Tests via snapshot labels.
Procedure with example
This procedure details how to grant the necessary snapshot access to a ServiceAccount, which is required to run periodic Integration Tests. It assumes you have an integration test created and a ServiceAccount available in your tenant namespace.
-
Identify an Existing Role (Recommended)
-
Check for an existing
Role
orClusterRole
that already has permissions to create snapshots. -
Many environments have roles with broad access (e.g., a
ClusterRole
withverbs: ["*"]
). Examine the roles available and compare to the example below to ensure the correct permissions are available within the role.
-
-
If No Existing Role, Create a New Role and RoleBinding
If you cannot use an existing role with snapshot permissions, a tenant administrator must manually create a new Role
and RoleBinding
, as outlined in the example.
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: periodic-jobs-role
namespace: default-tenant
rules:
- verbs:
- get
- watch
- list
- update
- patch
apiGroups:
- appstudio.redhat.com
resources:
- snapshots
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: periodic-jobs-rolebinding
namespace: default-tenant
subjects:
- kind: ServiceAccount
name: default-tenant
namespace:
roleRef:
kind: Role
name: periodic-jobs-role
apiGroup: rbac.authorization.k8s.io
---
-
Create a CronJob that will trigger a Periodic Integration Test scenario via snaphot labels.
The following CronJob example configured to run every two days (*/2
in the schedule). It triggers an integration test scenario in Konflux by:
-
Fetching the latest valid snapshot associated with push events in the specified tenant.
-
Checking if a valid snapshot exists and is autoreleased successfully; if not, the job exits with an error.
-
Labeling the snapshot to initiate the integration test scenario
This process helps ensure that the integration tests are executed periodically using the most recent in main branch.
kind: CronJob
apiVersion: batch/v1
metadata:
name: periodic-integration-test
namespace: default-tenant (1)
spec:
schedule: '0 0 */2 * *'
jobTemplate:
spec:
template:
spec:
containers:
- name: trigger-e2e-scenario
image: 'quay.io/konflux-ci/appstudio-utils:latest'
imagePullPolicy: Always
command:
- /bin/bash
- '-c'
args:
- |
#!/bin/bash
set -euo pipefail
export KONFLUX_SCENARIO_NAME="integration-test" (2)
export KONFLUX_TENANT_NAME="default-tenant" (3)
export KONFLUX_APPLICATION_NAME="application-default" (4)
export KONFLUX_COMPONENT_NAME="component-default" (5)
echo -e "[INFO] Fetching latest snapshot from ${KONFLUX_TENANT_NAME} related to push events."
LATEST_SNAPSHOT=$(kubectl get snapshots -n "${KONFLUX_TENANT_NAME}" -o json | \
jq --arg application "$KONFLUX_APPLICATION_NAME" --arg component "$KONFLUX_COMPONENT_NAME" -r '
.items
| map(select(
.metadata.labels."appstudio.openshift.io/application" == $application and
.metadata.labels."appstudio.openshift.io/component" == $component and
.metadata.labels."pac.test.appstudio.openshift.io/event-type" == "push" and
(.status.conditions // [] | map(select(
.type == "AutoReleased" and
.reason == "AutoReleased" and
.status == "True"
))
| length > 0)
))
| sort_by(.metadata.creationTimestamp) | last | .metadata.name')
if [[ -z "${LATEST_SNAPSHOT}" || "${LATEST_SNAPSHOT}" == "null" ]]; then
echo -e "[ERROR] No valid snapshot found. The job will not be triggered."
exit 1
fi
echo -e "[INFO] Triggering test scenario ${KONFLUX_SCENARIO_NAME} from snapshot ${LATEST_SNAPSHOT}."
kubectl -n "${KONFLUX_TENANT_NAME}" label snapshot "${LATEST_SNAPSHOT}" test.appstudio.openshift.io/run="${KONFLUX_SCENARIO_NAME}"
echo "[INFO] Integration Service E2E tests successfully triggered!"
restartPolicy: Never (6)
serviceAccountName: default
serviceAccount: default
1 | The name of the tenant. |
2 | The Integration Test name to be triggered by the CronJob. |
3 | The tenant from where to annotate the component snapshot to trigger Periodic Integration Test. |
4 | The Konflux application name associated with the Integration Test that will be triggered by the CronJob. |
5 | The Konflux component name. |
6 | Restart Policy can be "Never" or "OnFailure". |
Once the CronJob is triggered and completes, your integration test pipelines should begin executing in the Konflux UI.