diff --git a/tests/e2e/README.md b/tests/e2e/README.md index a324d8668..5cb68fb6a 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -11,13 +11,14 @@ This end-to-end test suite utilizes Ginkgo, a testing framework known for its ex 1. [Adding a Test Suite](#adding-a-test-suite) 1. [Sub-Tests](#sub-tests) 1. [Best practices](#best-practices) -1. [Running Tests](#running-tests) - 1. [Pre-requisites](#Pre-requisites) - 1. [How to Run the test](#How-to-Run-the-test) - 1. [Running the test locally](#Running-the-test-locally) - 1. [Settings for end-to-end test execution](#Settings-for-end-to-end-test-execution) - 1. [Customizing the test run](#Customizing-the-test-run) - 1. [Get test definitions for the end-to-end test](#Get-test-definitions-for-the-end-to-end-test) +1. [Running Tests](#running-the-tests) + 1. [Pre-requisites](#pre-requisites) + 1. [How to Run the test](#how-to-run-the-test) + 1. [Running the test locally](#running-the-test-locally) + 1. [Test Run scenarios while running on OCP](#test-run-scenarios-while-running-on-ocp) + 1. [Settings for end-to-end test execution](#settings-for-end-to-end-test-execution) + 1. [Customizing the test run](#customizing-the-test-run) + 1. [Get test definitions for the end-to-end test](#get-test-definitions-for-the-end-to-end-test) 1. [Contributing](#contributing) ## Overview @@ -248,6 +249,35 @@ Note: if you are running the test against a cluster that has a different archite TARGET_ARCH=arm64 make test.e2e.ocp ``` +#### Test Run scenarios while running on OCP +When running the E2E test on OpenShift clusters, the framework supports three different registry scenarios: + +**Scenario 1: Test run with Internal Registry (Default behaviour)** +For test run on OpenShift with the default settings, no additional configuration is needed. The test scripts will automatically configure and use the OpenShift internal registry: + +```sh +# No HUB setting needed - uses internal registry by default +make test.e2e.ocp +``` + +**Scenario 2: Test run with CI Mode with External Registry** +In CI environments, set `CI=true` to use external registries with proper tagging: + +```sh +export CI=true +# Uses default HUB=quay.io/sail-dev with auto-generated tags if no PR_NUMBER var is being set +make test.e2e.ocp +``` + +**Scenario 3: Test run with custom External Registry** +For custom external registries, specify your own HUB value: + +```sh +export HUB=your-registry.com/your-namespace +export TAG=your-tag +make test.e2e.ocp +``` + ### Settings for end-to-end test execution The following environment variables define the behavior of the test run: diff --git a/tests/e2e/common-operator-integ-suite.sh b/tests/e2e/common-operator-integ-suite.sh index 1ea600ec7..e669bccb6 100755 --- a/tests/e2e/common-operator-integ-suite.sh +++ b/tests/e2e/common-operator-integ-suite.sh @@ -123,12 +123,60 @@ initialize_variables() { OPERATOR_SDK=${LOCALBIN}/operator-sdk IP_FAMILY=${IP_FAMILY:-ipv4} ISTIO_MANIFEST="chart/samples/istio-sample.yaml" + CI=${CI:-"false"} + USE_INTERNAL_REGISTRY=${USE_INTERNAL_REGISTRY:-"false"} + + # Debug logging and fallback for GINKGO_FLAGS + echo "CI environment: ${CI}" + echo "GINKGO_FLAGS received: '${GINKGO_FLAGS:-}'" + + # Fallback: Generate GINKGO_FLAGS if empty and CI=true + if [ -z "${GINKGO_FLAGS:-}" ] && [ "${CI}" == "true" ]; then + GINKGO_FLAGS="--no-color" + echo "Generated GINKGO_FLAGS fallback: '${GINKGO_FLAGS}'" + fi # export to be sure that the variables are available in the subshell export IMAGE_BASE="${IMAGE_BASE:-sail-operator}" export TAG="${TAG:-latest}" export HUB="${HUB:-localhost:5000}" + # Handle OCP registry scenarios + # Note: Makefile.core.mk sets HUB=quay.io/sail-dev and TAG=1.29-latest by default + if [ "${OCP}" == "true" ]; then + # Debug output for troubleshooting + echo "DEBUG: CI='${CI}', HUB='${HUB}'" + + if [ "${CI}" == "true" ] && [ "${HUB}" == "quay.io/sail-dev" ]; then + # Scenario 2: CI mode with default HUB -> use external registry with proper CI tag + echo "CI mode detected for OCP, using external registry ${HUB}" + export USE_INTERNAL_REGISTRY="false" + # Use PR_NUMBER if available, otherwise generate timestamp tag + # Use TARGET_ARCH to differentiate tags for different architectures in CI, avoid race conditions in CI when multiple runs are pushing to the same default tag + if [ -n "${PR_NUMBER:-}" ]; then + TAG="pr-${PR_NUMBER}-${TARGET_ARCH}" + export TAG + echo "Using PR-based tag: ${TAG}" + else + TAG="ci-test-$(date +%s)-${TARGET_ARCH}" + export TAG + echo "Using timestamp-based tag: ${TAG}" + fi + elif [ "${CI}" == "true" ]; then + # Additional CI mode check - handle CI mode regardless of HUB value + echo "CI mode detected for OCP with custom HUB (${HUB}), using external registry" + export USE_INTERNAL_REGISTRY="false" + elif [ "${HUB}" != "quay.io/sail-dev" ]; then + # Scenario 3: Custom registry provided by user + echo "Using custom registry: ${HUB}" + export USE_INTERNAL_REGISTRY="false" + else + # Scenario 1: Local development -> use internal OCP registry + echo "Local development mode, will use OCP internal registry" + export USE_INTERNAL_REGISTRY="true" + fi + fi + echo "Setting Istio manifest file: ${ISTIO_MANIFEST}" ISTIO_NAME=$(yq eval '.metadata.name' "${WD}/../../$ISTIO_MANIFEST") @@ -215,7 +263,7 @@ parse_flags "$@" initialize_variables # Export necessary vars -export COMMAND OCP HUB IMAGE_BASE TAG NAMESPACE +export COMMAND OCP HUB IMAGE_BASE TAG NAMESPACE USE_INTERNAL_REGISTRY if [ "${SKIP_BUILD}" == "false" ]; then "${WD}/setup/build-and-push-operator.sh" @@ -224,9 +272,13 @@ if [ "${SKIP_BUILD}" == "false" ]; then # This is a workaround when pulling the image from internal registry # To avoid errors of certificates meanwhile we are pulling the operator image from the internal registry # We need to set image $HUB to a fixed known value after the push - # This value always will be equal to the svc url of the internal registry - HUB="image-registry.openshift-image-registry.svc:5000/istio-images" - echo "Using internal registry: ${HUB}" + # Convert from route URL to service URL format for image pulling + if [[ "${HUB}" == *"/istio-images" ]]; then + HUB="image-registry.openshift-image-registry.svc:5000/istio-images" + echo "Using internal registry service URL: ${HUB}" + else + echo "Using external registry: ${HUB}" + fi # Workaround for OCP helm operator installation issues: # To avoid any cleanup issues, after we build and push the image we check if the namespace exists and delete it if it does. @@ -272,7 +324,7 @@ if [ "${SKIP_BUILD}" == "false" ]; then fi fi -export SKIP_DEPLOY IP_FAMILY ISTIO_MANIFEST NAMESPACE CONTROL_PLANE_NS DEPLOYMENT_NAME MULTICLUSTER ARTIFACTS ISTIO_NAME COMMAND KUBECONFIG ISTIOCTL_PATH +export SKIP_DEPLOY IP_FAMILY ISTIO_MANIFEST NAMESPACE CONTROL_PLANE_NS DEPLOYMENT_NAME MULTICLUSTER ARTIFACTS ISTIO_NAME COMMAND KUBECONFIG ISTIOCTL_PATH GINKGO_FLAGS if [ "${OLM}" != "true" ] && [ "${SKIP_DEPLOY}" != "true" ]; then # shellcheck disable=SC2153 diff --git a/tests/e2e/integ-suite-kind.sh b/tests/e2e/integ-suite-kind.sh index f796ad3bd..29cd3427c 100755 --- a/tests/e2e/integ-suite-kind.sh +++ b/tests/e2e/integ-suite-kind.sh @@ -35,10 +35,10 @@ function check_prerequisites() { function run_integration_tests() { echo "Running integration tests" if [ "${MULTICLUSTER}" == "true" ]; then - ARTIFACTS="${ARTIFACTS}" ISTIOCTL="${ISTIOCTL}" "${ROOT}/tests/e2e/common-operator-integ-suite.sh" --kind --multicluster + ARTIFACTS="${ARTIFACTS}" ISTIOCTL="${ISTIOCTL}" GINKGO_FLAGS="${GINKGO_FLAGS}" "${ROOT}/tests/e2e/common-operator-integ-suite.sh" --kind --multicluster else KUBECONFIG="${ARTIFACTS}/config" - ARTIFACTS="${ARTIFACTS}" IP_FAMILY="${IP_FAMILY}" "${ROOT}/tests/e2e/common-operator-integ-suite.sh" --kind + ARTIFACTS="${ARTIFACTS}" IP_FAMILY="${IP_FAMILY}" GINKGO_FLAGS="${GINKGO_FLAGS}" "${ROOT}/tests/e2e/common-operator-integ-suite.sh" --kind fi } diff --git a/tests/e2e/integ-suite-ocp.sh b/tests/e2e/integ-suite-ocp.sh index 83566be1a..a075dd269 100755 --- a/tests/e2e/integ-suite-ocp.sh +++ b/tests/e2e/integ-suite-ocp.sh @@ -27,4 +27,4 @@ if [ -z "${KUBECONFIG}" ]; then exit 1 fi -KUBECONFIG="${KUBECONFIG}" ./tests/e2e/common-operator-integ-suite.sh --ocp \ No newline at end of file +KUBECONFIG="${KUBECONFIG}" GINKGO_FLAGS="${GINKGO_FLAGS}" ./tests/e2e/common-operator-integ-suite.sh --ocp \ No newline at end of file diff --git a/tests/e2e/setup/build-and-push-operator.sh b/tests/e2e/setup/build-and-push-operator.sh index f4527fa45..4be9123fa 100755 --- a/tests/e2e/setup/build-and-push-operator.sh +++ b/tests/e2e/setup/build-and-push-operator.sh @@ -85,8 +85,15 @@ build_and_push_operator_image() { } # Main logic -if [ "${OCP}" == "true" ]; then +# Only use internal registry for OCP local development (when USE_INTERNAL_REGISTRY is set) +echo "DEBUG: OCP='${OCP}', USE_INTERNAL_REGISTRY='${USE_INTERNAL_REGISTRY:-false}'" +if [ "${OCP}" == "true" ] && [ "${USE_INTERNAL_REGISTRY:-false}" == "true" ]; then + echo "Setting up OCP internal registry for local development..." get_internal_registry +else + echo "Skipping internal registry setup - using external registry" fi +echo "Registry: ${HUB}" + build_and_push_operator_image \ No newline at end of file