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:

  1. 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.

  1. Create RBAC rules in your tenant to allow CronJob ServiceAccount to access snapshot.

  2. Create a CronJob that will trigger periodic Integration Tests via snapshot labels.

Procedure with example

This procedure assumes that you already have an integration test created and a ServiceAccount available in your tenant.

  1. Create a Role and RoleBinding to grant the necessary snapshot access to the ServiceAccount, which will be used to trigger the periodic Integration Tests

    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
  2. 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!"
          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 componet name.

Once the CronJob is triggered and completes, your integration test pipelines should begin executing in the Konflux UI.