From 1c6bddb60ace54dec36ef5257ac4029d5bd9b1af Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Tue, 23 Sep 2025 15:27:16 -0300 Subject: [PATCH 1/4] step-registry/sandboxed-containers-operator: create validate_and_set_defaults() in create-prowjob-commands.sh - Extract parameter validation and default setting logic into validate_and_set_defaults() function - Maintain all existing validation rules and error handling Assisted-by: Cursor Signed-off-by: Wainer dos Santos Moschetta --- ...ainers-operator-create-prowjob-commands.sh | 270 +++++++++--------- 1 file changed, 135 insertions(+), 135 deletions(-) diff --git a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh index 01b4b6d9b0f3c..4552c07e8e29c 100755 --- a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh +++ b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh @@ -104,159 +104,159 @@ get_expected_version() { echo "" fi } +# Function to validate parameters and set defaults +validate_and_set_defaults() { + echo "Validating parameters and setting defaults..." + + # OCP version to test + OCP_VERSION="${OCP_VERSION:-4.19}" + # Validate OCP version format + if [[ ! "${OCP_VERSION}" =~ ^[0-9]+\.[0-9]+$ ]]; then + echo "ERROR: Invalid OCP_VERSION format. Expected format: X.Y (e.g., 4.19)" + exit 1 + fi -echo "==========================================" -echo "Sandboxed Containers Operator - Prowjob Configuration Generator" - - -# Validate required parameters and set defaults -echo "Validating parameters and setting defaults..." - -# OCP version to test -OCP_VERSION="${OCP_VERSION:-4.19}" -# Validate OCP version format -if [[ ! "${OCP_VERSION}" =~ ^[0-9]+\.[0-9]+$ ]]; then - echo "ERROR: Invalid OCP_VERSION format. Expected format: X.Y (e.g., 4.19)" - exit 1 -fi - -# AWS Region Configuration -AWS_REGION_OVERRIDE="${AWS_REGION_OVERRIDE:-us-east-2}" - -# Azure Region Configuration -CUSTOM_AZURE_REGION="${CUSTOM_AZURE_REGION:-eastus}" - -# OSC Version Configuration -EXPECTED_OSC_VERSION="${EXPECTED_OSC_VERSION:-1.10.1}" - -# Kata RPM Configuration -INSTALL_KATA_RPM="${INSTALL_KATA_RPM:-true}" -if [[ "${INSTALL_KATA_RPM}" != "true" && "${INSTALL_KATA_RPM}" != "false" ]]; then - echo "ERROR: INSTALL_KATA_RPM should be 'true' or 'false', got: ${INSTALL_KATA_RPM}" - exit 1 -fi - -# Kata RPM version (includes OCP version) -if [[ "${INSTALL_KATA_RPM}" == "true" ]]; then - KATA_RPM_VERSION="${KATA_RPM_VERSION:-3.17.0-3.rhaos4.19.el9}" -else - KATA_RPM_VERSION="${KATA_RPM_VERSION:-}" -fi - -# test is Pre-GA for brew builds or GA for operators/rpms already on OCP -# this triggers the mirror redirect install, creating brew & trustee catsrc, -TEST_RELEASE_TYPE="${TEST_RELEASE_TYPE:-Pre-GA}" -# Validate TEST_RELEASE_TYPE -if [[ "${TEST_RELEASE_TYPE}" != "Pre-GA" && "${TEST_RELEASE_TYPE}" != "GA" ]]; then - echo "ERROR: TEST_RELEASE_TYPE should be 'Pre-GA' or 'GA', got: ${TEST_RELEASE_TYPE}" - exit 1 -fi - -# Prow Run Type depends on TEST_RELEASE_TYPE -if [[ "${TEST_RELEASE_TYPE}" == "Pre-GA" ]]; then - PROW_RUN_TYPE="candidate" -else - PROW_RUN_TYPE="release" - CATALOG_SOURCE_NAME="redhat-operators" - TRUSTEE_CATALOG_SOURCE_NAME="redhat-operators" -fi - -# After the tests finish, wait before killing the cluster -SLEEP_DURATION="${SLEEP_DURATION:-0h}" -# Validate SLEEP_DURATION format (0-12 followed by 'h') -if ! [[ "${SLEEP_DURATION}" =~ ^(1[0-2]|[0-9])h$ ]]; then - echo "ERROR: SLEEP_DURATION must be a number between 0-12 followed by 'h' (e.g., 2h, 8h), got: ${SLEEP_DURATION}" - exit 1 -fi - - -# Allow override of test scenarios -TEST_SCENARIOS="${TEST_SCENARIOS:-sig-kata.*Kata Author}" + # AWS Region Configuration + AWS_REGION_OVERRIDE="${AWS_REGION_OVERRIDE:-us-east-2}" -# Let the tests run for this many minutes before killing the cluster and interupting the test -TEST_TIMEOUT="${TEST_TIMEOUT:-90}" -# Validate TEST_TIMEOUT is numeric -if ! [[ "${TEST_TIMEOUT}" =~ ^[0-9]+$ ]]; then - echo "ERROR: TEST_TIMEOUT should be numeric, got: ${TEST_TIMEOUT}" - exit 1 -fi + # Azure Region Configuration + CUSTOM_AZURE_REGION="${CUSTOM_AZURE_REGION:-eastus}" -# Must-gather Configuration -ENABLE_MUST_GATHER="${ENABLE_MUST_GATHER:-true}" -# Validate ENABLE_MUST_GATHER -if [[ "${ENABLE_MUST_GATHER}" != "true" && "${ENABLE_MUST_GATHER}" != "false" ]]; then - echo "ERROR: ENABLE_MUST_GATHER should be 'true' or 'false', got: ${ENABLE_MUST_GATHER}" - exit 1 -fi + # OSC Version Configuration + EXPECTED_OSC_VERSION="${EXPECTED_OSC_VERSION:-1.10.1}" -# Must-gather image to use for collecting debug information -MUST_GATHER_IMAGE="${MUST_GATHER_IMAGE:-registry.redhat.io/openshift-sandboxed-containers/osc-must-gather-rhel9:latest}" + # Kata RPM Configuration + INSTALL_KATA_RPM="${INSTALL_KATA_RPM:-true}" + if [[ "${INSTALL_KATA_RPM}" != "true" && "${INSTALL_KATA_RPM}" != "false" ]]; then + echo "ERROR: INSTALL_KATA_RPM should be 'true' or 'false', got: ${INSTALL_KATA_RPM}" + exit 1 + fi -# Only collect must-gather on test failure -MUST_GATHER_ON_FAILURE_ONLY="${MUST_GATHER_ON_FAILURE_ONLY:-true}" -# Validate MUST_GATHER_ON_FAILURE_ONLY -if [[ "${MUST_GATHER_ON_FAILURE_ONLY}" != "true" && "${MUST_GATHER_ON_FAILURE_ONLY}" != "false" ]]; then - echo "ERROR: MUST_GATHER_ON_FAILURE_ONLY should be 'true' or 'false', got: ${MUST_GATHER_ON_FAILURE_ONLY}" - exit 1 -fi + # Kata RPM version (includes OCP version) + if [[ "${INSTALL_KATA_RPM}" == "true" ]]; then + KATA_RPM_VERSION="${KATA_RPM_VERSION:-3.17.0-3.rhaos4.19.el9}" + else + KATA_RPM_VERSION="${KATA_RPM_VERSION:-}" + fi + # test is Pre-GA for brew builds or GA for operators/rpms already on OCP + # this triggers the mirror redirect install, creating brew & trustee catsrc, + TEST_RELEASE_TYPE="${TEST_RELEASE_TYPE:-Pre-GA}" + # Validate TEST_RELEASE_TYPE + if [[ "${TEST_RELEASE_TYPE}" != "Pre-GA" && "${TEST_RELEASE_TYPE}" != "GA" ]]; then + echo "ERROR: TEST_RELEASE_TYPE should be 'Pre-GA' or 'GA', got: ${TEST_RELEASE_TYPE}" + exit 1 + fi + # Prow Run Type depends on TEST_RELEASE_TYPE + if [[ "${TEST_RELEASE_TYPE}" == "Pre-GA" ]]; then + PROW_RUN_TYPE="candidate" + else + PROW_RUN_TYPE="release" + CATALOG_SOURCE_NAME="redhat-operators" + TRUSTEE_CATALOG_SOURCE_NAME="redhat-operators" + fi -# Catalog Source Configuration -echo "Configuring catalog sources..." + # After the tests finish, wait before killing the cluster + SLEEP_DURATION="${SLEEP_DURATION:-0h}" + # Validate SLEEP_DURATION format (0-12 followed by 'h') + if ! [[ "${SLEEP_DURATION}" =~ ^(1[0-2]|[0-9])h$ ]]; then + echo "ERROR: SLEEP_DURATION must be a number between 0-12 followed by 'h' (e.g., 2h, 8h), got: ${SLEEP_DURATION}" + exit 1 + fi -# Set catalog source variables based on TEST_RELEASE_TYPE -if [[ "${TEST_RELEASE_TYPE}" == "Pre-GA" ]]; then - # OSC Catalog Configuration - get latest or use provided - if [[ -z "${OSC_CATALOG_TAG:-}" ]]; then - OSC_CATALOG_TAG=$(get_latest_osc_catalog_tag) + # Allow override of test scenarios + TEST_SCENARIOS="${TEST_SCENARIOS:-sig-kata.*Kata Author}" - else - echo "Using provided OSC_CATALOG_TAG: ${OSC_CATALOG_TAG}" + # Let the tests run for this many minutes before killing the cluster and interupting the test + TEST_TIMEOUT="${TEST_TIMEOUT:-90}" + # Validate TEST_TIMEOUT is numeric + if ! [[ "${TEST_TIMEOUT}" =~ ^[0-9]+$ ]]; then + echo "ERROR: TEST_TIMEOUT should be numeric, got: ${TEST_TIMEOUT}" + exit 1 fi - # Extract expected OSC version from catalog tag if it matches X.Y.Z-[0-9]+ format - extracted_version=$(get_expected_version "${OSC_CATALOG_TAG}") - if [[ -n "${extracted_version}" ]]; then - EXPECTED_OSC_VERSION="${extracted_version}" - echo "Extracted EXPECTED_OSC_VERSION from OSC_CATALOG_TAG: ${EXPECTED_OSC_VERSION}" + # Must-gather Configuration + ENABLE_MUST_GATHER="${ENABLE_MUST_GATHER:-true}" + # Validate ENABLE_MUST_GATHER + if [[ "${ENABLE_MUST_GATHER}" != "true" && "${ENABLE_MUST_GATHER}" != "false" ]]; then + echo "ERROR: ENABLE_MUST_GATHER should be 'true' or 'false', got: ${ENABLE_MUST_GATHER}" + exit 1 fi - CATALOG_SOURCE_IMAGE="${CATALOG_SOURCE_IMAGE:-quay.io/redhat-user-workloads/ose-osc-tenant/osc-test-fbc:${OSC_CATALOG_TAG}}" - CATALOG_SOURCE_NAME="${CATALOG_SOURCE_NAME:-brew-catalog}" + # Must-gather image to use for collecting debug information + MUST_GATHER_IMAGE="${MUST_GATHER_IMAGE:-registry.redhat.io/openshift-sandboxed-containers/osc-must-gather-rhel9:latest}" - # Trustee Catalog Configuration - # Convert OCP version for Trustee catalog naming - OCP_VER=$(echo "${OCP_VERSION}" | tr '.' '-') - subfolder="" - if [[ "${OCP_VER}" == "4-16" ]]; then - subfolder="trustee-fbc/" + # Only collect must-gather on test failure + MUST_GATHER_ON_FAILURE_ONLY="${MUST_GATHER_ON_FAILURE_ONLY:-true}" + # Validate MUST_GATHER_ON_FAILURE_ONLY + if [[ "${MUST_GATHER_ON_FAILURE_ONLY}" != "true" && "${MUST_GATHER_ON_FAILURE_ONLY}" != "false" ]]; then + echo "ERROR: MUST_GATHER_ON_FAILURE_ONLY should be 'true' or 'false', got: ${MUST_GATHER_ON_FAILURE_ONLY}" + exit 1 fi - # Get latest Trustee catalog tag with page limit safety - TRUSTEE_REPO_NAME="${subfolder}trustee-fbc-${OCP_VER}" - TRUSTEE_CATALOG_REPO="quay.io/redhat-user-workloads/ose-osc-tenant/${TRUSTEE_REPO_NAME}" - - APIURL="https://quay.io/api/v1/repository/redhat-user-workloads/ose-osc-tenant/${TRUSTEE_REPO_NAME}" - TRUSTEE_CATALOG_TAG=$(get_latest_trustee_catalog_tag) - - # Extract expected Trustee version from catalog tag if it matches X.Y.Z-[0-9]+ format - extracted_trustee_version=$(get_expected_version "${TRUSTEE_CATALOG_TAG}") - if [[ -n "${extracted_trustee_version}" ]]; then - EXPECTED_TRUSTEE_VERSION="${extracted_trustee_version}" - echo "Extracted EXPECTED_TRUSTEE_VERSION from TRUSTEE_CATALOG_TAG: ${EXPECTED_TRUSTEE_VERSION}" - else - EXPECTED_TRUSTEE_VERSION="${EXPECTED_TRUSTEE_VERSION:-0.0.0}" - echo "Using default EXPECTED_TRUSTEE_VERSION: ${EXPECTED_TRUSTEE_VERSION}" + + # Catalog Source Configuration + echo "Configuring catalog sources..." + + # Set catalog source variables based on TEST_RELEASE_TYPE + if [[ "${TEST_RELEASE_TYPE}" == "Pre-GA" ]]; then + # OSC Catalog Configuration - get latest or use provided + if [[ -z "${OSC_CATALOG_TAG:-}" ]]; then + OSC_CATALOG_TAG=$(get_latest_osc_catalog_tag) + + else + echo "Using provided OSC_CATALOG_TAG: ${OSC_CATALOG_TAG}" + fi + + # Extract expected OSC version from catalog tag if it matches X.Y.Z-[0-9]+ format + extracted_version=$(get_expected_version "${OSC_CATALOG_TAG}") + if [[ -n "${extracted_version}" ]]; then + EXPECTED_OSC_VERSION="${extracted_version}" + echo "Extracted EXPECTED_OSC_VERSION from OSC_CATALOG_TAG: ${EXPECTED_OSC_VERSION}" + fi + + CATALOG_SOURCE_IMAGE="${CATALOG_SOURCE_IMAGE:-quay.io/redhat-user-workloads/ose-osc-tenant/osc-test-fbc:${OSC_CATALOG_TAG}}" + CATALOG_SOURCE_NAME="${CATALOG_SOURCE_NAME:-brew-catalog}" + + # Trustee Catalog Configuration + # Convert OCP version for Trustee catalog naming + OCP_VER=$(echo "${OCP_VERSION}" | tr '.' '-') + subfolder="" + if [[ "${OCP_VER}" == "4-16" ]]; then + subfolder="trustee-fbc/" + fi + # Get latest Trustee catalog tag with page limit safety + TRUSTEE_REPO_NAME="${subfolder}trustee-fbc-${OCP_VER}" + TRUSTEE_CATALOG_REPO="quay.io/redhat-user-workloads/ose-osc-tenant/${TRUSTEE_REPO_NAME}" + + APIURL="https://quay.io/api/v1/repository/redhat-user-workloads/ose-osc-tenant/${TRUSTEE_REPO_NAME}" + TRUSTEE_CATALOG_TAG=$(get_latest_trustee_catalog_tag) + + # Extract expected Trustee version from catalog tag if it matches X.Y.Z-[0-9]+ format + extracted_trustee_version=$(get_expected_version "${TRUSTEE_CATALOG_TAG}") + if [[ -n "${extracted_trustee_version}" ]]; then + EXPECTED_TRUSTEE_VERSION="${extracted_trustee_version}" + echo "Extracted EXPECTED_TRUSTEE_VERSION from TRUSTEE_CATALOG_TAG: ${EXPECTED_TRUSTEE_VERSION}" + else + EXPECTED_TRUSTEE_VERSION="${EXPECTED_TRUSTEE_VERSION:-0.0.0}" + echo "Using default EXPECTED_TRUSTEE_VERSION: ${EXPECTED_TRUSTEE_VERSION}" + fi + + TRUSTEE_CATALOG_SOURCE_IMAGE="${TRUSTEE_CATALOG_SOURCE_IMAGE:-${TRUSTEE_CATALOG_REPO}:${TRUSTEE_CATALOG_TAG}}" + TRUSTEE_CATALOG_SOURCE_NAME="${TRUSTEE_CATALOG_SOURCE_NAME:-trustee-catalog}" + else # GA + CATALOG_SOURCE_NAME="redhat-operators" + TRUSTEE_CATALOG_SOURCE_NAME="redhat-operators" + CATALOG_SOURCE_IMAGE="none" + TRUSTEE_CATALOG_SOURCE_IMAGE="none" fi +} - TRUSTEE_CATALOG_SOURCE_IMAGE="${TRUSTEE_CATALOG_SOURCE_IMAGE:-${TRUSTEE_CATALOG_REPO}:${TRUSTEE_CATALOG_TAG}}" - TRUSTEE_CATALOG_SOURCE_NAME="${TRUSTEE_CATALOG_SOURCE_NAME:-trustee-catalog}" -else # GA - CATALOG_SOURCE_NAME="redhat-operators" - TRUSTEE_CATALOG_SOURCE_NAME="redhat-operators" - CATALOG_SOURCE_IMAGE="none" - TRUSTEE_CATALOG_SOURCE_IMAGE="none" -fi +echo "==========================================" +echo "Sandboxed Containers Operator - Prowjob Configuration Generator" + +# Call the validation function +validate_and_set_defaults # Generate output file path OCP_PROWJOB_VERSION=$(echo "${OCP_VERSION}" | tr -d '.' ) From efc11e93f8f43eee9f11edbdd59b099fe061c8bf Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Fri, 3 Oct 2025 12:19:32 -0300 Subject: [PATCH 2/4] step-registry/sandboxed-containers-operator: Add create command to create-prowjob-commands.sh - Refactor script to support command-based interface - Add 'create' command to generate prowjob configurations - Move existing functionality into command_create() function - Add proper command validation and usage help - Maintain all existing functionality with improved structure Assisted-by: Cursor Signed-off-by: Wainer dos Santos Moschetta --- .../create-prowjob/README.md | 29 ++- ...ainers-operator-create-prowjob-commands.sh | 227 +++++++++++------- 2 files changed, 166 insertions(+), 90 deletions(-) diff --git a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/README.md b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/README.md index 876fe88ff8843..e420d01bf178a 100644 --- a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/README.md +++ b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/README.md @@ -6,11 +6,24 @@ This directory contains a robust script to generate OpenShift CI prowjob configu The `sandboxed-containers-operator-create-prowjob-commands.sh` script creates prowjob configuration files for the sandboxed containers operator CI pipeline. It supports both Pre-GA (development) and GA (production) release types with intelligent catalog source management and comprehensive parameter validation. +## Commands + +The script supports the following commands: + +- `create` - Create prowjob configuration files + +### Command Usage + +```bash +# Show help +./sandboxed-containers-operator-create-prowjob-commands.sh +``` + ## Files - `sandboxed-containers-operator-create-prowjob-commands.sh` - Main script to generate prowjob configurations - The output file is created in the current directory and named `openshift-sandboxed-containers-operator-devel__downstream-${PROW_RUN_TYPE}${OCP_VERSION}.yaml` - - `PROW_RUN_TYPE` is based on ``TEST_RELEASE_TYPE. It is `candidate` for `Pre-GA` and `release` otherwise + - `PROW_RUN_TYPE` is based on `TEST_RELEASE_TYPE`. It is `candidate` for `Pre-GA` and `release` otherwise - If the output file exists, it will be moved to a `.backup` file ## Key Features @@ -31,10 +44,10 @@ The script uses environment variables exclusively for configuration: ```bash # Generate configuration with defaults -ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh +ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh create # Generate configuration with custom OCP version -OCP_VERSION=4.17 ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh +OCP_VERSION=4.17 ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh create ``` ### Environment Variables @@ -75,7 +88,7 @@ OCP_VERSION=4.17 ci-operator/step-registry/sandboxed-containers-operator/create- TEST_RELEASE_TYPE=Pre-GA \ PROW_RUN_TYPE=candidate \ OCP_VERSION=4.18 \ -ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh +ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh create ``` #### GA Production Testing @@ -84,7 +97,7 @@ ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed TEST_RELEASE_TYPE=GA \ PROW_RUN_TYPE=release \ OCP_VERSION=4.19 \ -ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh +ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh create ``` #### Custom Regions and Timeouts @@ -94,19 +107,19 @@ AWS_REGION_OVERRIDE=us-west-2 \ CUSTOM_AZURE_REGION=westus2 \ SLEEP_DURATION=2h \ TEST_TIMEOUT=120 \ -ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh +ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh create ``` #### Kata RPM Testing ```bash # Test without Kata RPM installation INSTALL_KATA_RPM=false \ -ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh +ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh create # Test with specific Kata RPM version INSTALL_KATA_RPM=true \ KATA_RPM_VERSION=3.18.0-3.rhaos4.20.el9 \ -ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh +ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh create ``` ## Catalog Tag Discovery diff --git a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh index 4552c07e8e29c..6ecd89c71a4ca 100755 --- a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh +++ b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh @@ -1,6 +1,7 @@ #!/bin/bash # script to create prowjobs in ci-operator/config/openshift/sandboxed-containers-operator using environment variables. -# Usage: ./sandboxed-containers-operator-create-prowjob-commands.sh +# Usage: +# ./sandboxed-containers-operator-create-prowjob-commands.sh gen # Generate prowjob configuration # should be run in a branch of a fork of https://github.com/openshift/release/ # created with the assistance of Cursor AI @@ -252,26 +253,83 @@ validate_and_set_defaults() { fi } -echo "==========================================" -echo "Sandboxed Containers Operator - Prowjob Configuration Generator" +# Function to show usage +show_usage() { + echo "Usage: $0 " + echo "" + echo "Commands:" + echo " create Create prowjob configuration files" + echo "" + echo "Examples:" + echo " $0 create" + echo "" + echo "Environment variables for 'create' command:" + echo " OCP_VERSION - OpenShift version (default: 4.19)" + echo " TEST_RELEASE_TYPE - Test release type: Pre-GA or GA (default: Pre-GA)" + echo " EXPECTED_OSC_VERSION - Expected OSC version (default: 1.10.1)" + echo " INSTALL_KATA_RPM - Install Kata RPM: true or false (default: true)" + echo " KATA_RPM_VERSION - Kata RPM version (default: 3.17.0-3.rhaos4.19.el9)" + echo " SLEEP_DURATION - Sleep duration after tests (default: 0h)" + echo " TEST_SCENARIOS - Test scenarios filter (default: sig-kata.*Kata Author)" + echo " TEST_TIMEOUT - Test timeout in minutes (default: 90)" + echo " ENABLE_MUST_GATHER - Enable must-gather: true or false (default: true)" + echo " MUST_GATHER_IMAGE - Must-gather image (default: registry.redhat.io/openshift-sandboxed-containers/osc-must-gather-rhel9:latest)" + echo " MUST_GATHER_ON_FAILURE_ONLY - Must-gather on failure only: true or false (default: true)" + echo " AWS_REGION_OVERRIDE - AWS region (default: us-east-2)" + echo " CUSTOM_AZURE_REGION - Azure region (default: eastus)" + echo " OSC_CATALOG_TAG - OSC catalog tag (auto-detected if not provided)" + echo " TRUSTEE_CATALOG_TAG - Trustee catalog tag (auto-detected if not provided)" +} + +# Main function +main() { + # Parse command line arguments + if [[ $# -eq 0 ]]; then + echo "ERROR: No command specified" + echo "" + show_usage + exit 1 + fi + + COMMAND="$1" + shift + + # Validate command and dispatch + case "${COMMAND}" in + create) + command_create + ;; + *) + echo "ERROR: Unknown command '${COMMAND}'" + echo "" + show_usage + exit 1 + ;; + esac +} + +# Function to create prowjob configuration +command_create() { + echo "==========================================" + echo "Sandboxed Containers Operator - Prowjob Configuration Generator" -# Call the validation function -validate_and_set_defaults + # Call the validation function + validate_and_set_defaults -# Generate output file path -OCP_PROWJOB_VERSION=$(echo "${OCP_VERSION}" | tr -d '.' ) -OUTPUT_FILE="openshift-sandboxed-containers-operator-devel__downstream-${PROW_RUN_TYPE}${OCP_PROWJOB_VERSION}.yaml" -echo "Generating prowjob configuration..." + # Generate output file path + OCP_PROWJOB_VERSION=$(echo "${OCP_VERSION}" | tr -d '.' ) + OUTPUT_FILE="openshift-sandboxed-containers-operator-devel__downstream-${PROW_RUN_TYPE}${OCP_PROWJOB_VERSION}.yaml" + echo "Creating prowjob configuration..." -# Backup existing file if it exists -if [[ -f "${OUTPUT_FILE}" ]]; then - echo "Backing up existing file: ${OUTPUT_FILE}.backup" - cp "${OUTPUT_FILE}" "${OUTPUT_FILE}.backup" -fi + # Backup existing file if it exists + if [[ -f "${OUTPUT_FILE}" ]]; then + echo "Backing up existing file: ${OUTPUT_FILE}.backup" + cp "${OUTPUT_FILE}" "${OUTPUT_FILE}.backup" + fi -# Generate the prowjob configuration file + # Create the prowjob configuration file -cat > "${OUTPUT_FILE}" < "${OUTPUT_FILE}" < /dev/null; then - echo "Validating YAML: yq eval '.' ${OUTPUT_FILE}" - if yq eval '.' "${OUTPUT_FILE}" ; then - echo "✓ YAML syntax is valid" - else - echo "✗ YAML syntax validation failed" + # Validate the generated file + echo "Validating generated configuration..." + + if [[ ! -f "${OUTPUT_FILE}" ]]; then + echo "ERROR: Failed to create output file: ${OUTPUT_FILE}" exit 1 fi -else - echo "INFO: yq not available, skipping YAML syntax validation" -fi - -# Show configuration summary -echo "==========================================" -echo "Configuration details:" -echo " • OCP Version: ${OCP_VERSION}" -echo " • Prow Run Type: ${PROW_RUN_TYPE}" -echo " • Test Release Type: ${TEST_RELEASE_TYPE}" -echo " • Expected OSC Version: ${EXPECTED_OSC_VERSION}" -echo " • Expected Trustee Version: ${EXPECTED_TRUSTEE_VERSION:-N/A}" -echo " • AWS Region: ${AWS_REGION_OVERRIDE}" -echo " • Azure Region: ${CUSTOM_AZURE_REGION}" -echo " • Kata RPM: ${INSTALL_KATA_RPM} (${KATA_RPM_VERSION})" -echo " • Sleep Duration: ${SLEEP_DURATION}" -echo " • Test Timeout: ${TEST_TIMEOUT}" - -if [[ "${TEST_RELEASE_TYPE}" == "Pre-GA" ]]; then - echo " • Catalog Source: ${CATALOG_SOURCE_NAME} (${CATALOG_SOURCE_IMAGE})" - echo " • Trustee Catalog: ${TRUSTEE_CATALOG_SOURCE_NAME} (${TRUSTEE_CATALOG_SOURCE_IMAGE})" -else - echo " • Catalog Source: ${CATALOG_SOURCE_NAME}" - echo " • Trustee Catalog: ${TRUSTEE_CATALOG_SOURCE_NAME}" -fi - -echo "==========================================" -echo "Generated file: ${OUTPUT_FILE}" -echo "File size: ${file_size} bytes" -echo "==========================================" -echo "Next Steps:" -echo "1. Review the generated configuration file:" -echo " cat ${OUTPUT_FILE}" -echo "" -echo "2. Move it to the appropriate directory:" -echo "mv ${OUTPUT_FILE} ci-operator/config/openshift/sandboxed-containers-operator/" -echo "" -echo "3. Add to git:" -echo "git add ci-operator/config/openshift/sandboxed-containers-operator/${OUTPUT_FILE}" -echo "" -echo "4. Generate and update CI configuration before creating PR:" -echo "make ci-operator-config && make registry-metadata && make prow-config && make jobs && make update" -echo "" -echo "5. git add changes, commit and push to PR" -echo "" + + # Check file size + file_size=$(wc -c < "${OUTPUT_FILE}") + if [[ ${file_size} -lt 1000 ]]; then + echo "WARNING: Generated file seems too small (${file_size} bytes)" + fi + + # Basic YAML syntax validation if yq is available + if command -v yq &> /dev/null; then + echo "Validating YAML: yq eval '.' ${OUTPUT_FILE}" + if yq eval '.' "${OUTPUT_FILE}" ; then + echo "✓ YAML syntax is valid" + else + echo "✗ YAML syntax validation failed" + exit 1 + fi + else + echo "INFO: yq not available, skipping YAML syntax validation" + fi + + # Show configuration summary + echo "==========================================" + echo "Configuration details:" + echo " • OCP Version: ${OCP_VERSION}" + echo " • Prow Run Type: ${PROW_RUN_TYPE}" + echo " • Test Release Type: ${TEST_RELEASE_TYPE}" + echo " • Expected OSC Version: ${EXPECTED_OSC_VERSION}" + echo " • Expected Trustee Version: ${EXPECTED_TRUSTEE_VERSION:-N/A}" + echo " • AWS Region: ${AWS_REGION_OVERRIDE}" + echo " • Azure Region: ${CUSTOM_AZURE_REGION}" + echo " • Kata RPM: ${INSTALL_KATA_RPM} (${KATA_RPM_VERSION})" + echo " • Sleep Duration: ${SLEEP_DURATION}" + echo " • Test Timeout: ${TEST_TIMEOUT}" + + if [[ "${TEST_RELEASE_TYPE}" == "Pre-GA" ]]; then + echo " • Catalog Source: ${CATALOG_SOURCE_NAME} (${CATALOG_SOURCE_IMAGE})" + echo " • Trustee Catalog: ${TRUSTEE_CATALOG_SOURCE_NAME} (${TRUSTEE_CATALOG_SOURCE_IMAGE})" + else + echo " • Catalog Source: ${CATALOG_SOURCE_NAME}" + echo " • Trustee Catalog: ${TRUSTEE_CATALOG_SOURCE_NAME}" + fi + + echo "==========================================" + echo "Generated file: ${OUTPUT_FILE}" + echo "File size: ${file_size} bytes" + echo "==========================================" + echo "Next Steps:" + echo "1. Review the created configuration file:" + echo " cat ${OUTPUT_FILE}" + echo "" + echo "2. Move it to the appropriate directory:" + echo "mv ${OUTPUT_FILE} ci-operator/config/openshift/sandboxed-containers-operator/" + echo "" + echo "3. Add to git:" + echo "git add ci-operator/config/openshift/sandboxed-containers-operator/${OUTPUT_FILE}" + echo "" + echo "4. Generate and update CI configuration before creating PR:" + echo "make ci-operator-config && make registry-metadata && make prow-config && make jobs && make update" + echo "" + echo "5. git add changes, commit and push to PR" + echo "" +} + + +# Call main function with all command line arguments +main "$@" From fe996ffc12516125c19ef371f479bd4f7d64139b Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Fri, 3 Oct 2025 12:21:36 -0300 Subject: [PATCH 3/4] step-registry/sandboxed-containers-operator: Add run command to create-prowjob-commands.sh - Add 'run' command as placeholder for future prowjob execution - Update usage help to include run command - Add command_run() function with unimplemented message - Maintain backward compatibility with create command Assisted-by: Cursor Signed-off-by: Wainer dos Santos Moschetta --- .../create-prowjob/README.md | 57 ++++++ ...ainers-operator-create-prowjob-commands.sh | 171 +++++++++++++++++- 2 files changed, 227 insertions(+), 1 deletion(-) diff --git a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/README.md b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/README.md index e420d01bf178a..32da3b11656f5 100644 --- a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/README.md +++ b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/README.md @@ -11,6 +11,7 @@ The `sandboxed-containers-operator-create-prowjob-commands.sh` script creates pr The script supports the following commands: - `create` - Create prowjob configuration files +- `run` - Run prowjobs from YAML configuration ### Command Usage @@ -48,6 +49,12 @@ ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed # Generate configuration with custom OCP version OCP_VERSION=4.17 ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh create + +# Run jobs from generated YAML file +PROW_API_TOKEN=your_token_here ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh run openshift-sandboxed-containers-operator-devel__downstream-candidate419.yaml + +# Run specific job +PROW_API_TOKEN=your_token_here ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh run openshift-sandboxed-containers-operator-devel__downstream-candidate419.yaml azure-ipi-kata ``` ### Environment Variables @@ -136,6 +143,34 @@ ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed - **Method**: Quay API with pagination (max 50 pages) - **Special Case**: OCP 4.16 uses `trustee-fbc/` subfolder +## Run Command + +The `run` command allows you to trigger ProwJobs from a generated YAML configuration file. This command requires a valid Prow API token. + +### Run Command Usage + +```bash +# Run all jobs from a YAML file +./sandboxed-containers-operator-create-prowjob-commands.sh run /path/to/job_yaml.yaml + +# Run specific jobs from a YAML file +./sandboxed-containers-operator-create-prowjob-commands.sh run /path/to/job_yaml.yaml azure-ipi-kata aws-ipi-peerpods +``` + +### Run Command Features + +- **Job Name Generation**: Automatically constructs job names using the pattern `periodic-ci-{org}-{repo}-{branch}-{variant}-{job_suffix}` +- **Metadata Extraction**: Extracts organization, repository, branch, and variant from the YAML file's `zz_generated_metadata` section +- **API Integration**: Uses the Prow/Gangway API to trigger jobs +- **Job Status Monitoring**: Provides job IDs and status information +- **Flexible Job Selection**: Can run all jobs or specific jobs by name + +### Run Command Environment Variables + +| Variable | Required | Description | +|----------|----------|-------------| +| `PROW_API_TOKEN` | Yes | Prow API authentication token | + ## Generated Test Matrix The script generates configuration for 5 test scenarios: @@ -219,3 +254,25 @@ yq eval '.' openshift-sandboxed-containers-operator-devel__downstream-candidate4 - **Required**: `curl`, `jq`, `awk`, `sort`, `head` - **Optional**: `yq` (for YAML syntax validation) - **Network**: Access to `quay.io` API endpoints + +## Prow API Token + +To trigger ProwJobs via the REST API, you need an authentication token. Each SSO user is entitled to obtain a personal authentication token. + +### Obtaining a Token + +Tokens can be retrieved through the UI of the app.ci cluster at [OpenShift Console](https://console-openshift-console.apps.ci.l2s4.p1.openshiftapps.com). Alternatively, if the app.ci cluster context is already configured, you may execute: + +```bash +oc whoami -t +``` + +### Using the Token + +Once you have obtained a token, set it as an environment variable: + +```bash +export PROW_API_TOKEN=your_token_here +``` + +For complete information about triggering ProwJobs via REST, including permanent tokens for automation, see the [OpenShift CI documentation](https://docs.ci.openshift.org/docs/how-tos/triggering-prowjobs-via-rest/#obtaining-an-authentication-token). diff --git a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh index 6ecd89c71a4ca..8ad7ec8b3202f 100755 --- a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh +++ b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh @@ -2,6 +2,7 @@ # script to create prowjobs in ci-operator/config/openshift/sandboxed-containers-operator using environment variables. # Usage: # ./sandboxed-containers-operator-create-prowjob-commands.sh gen # Generate prowjob configuration +# ./sandboxed-containers-operator-create-prowjob-commands.sh run # Run prowjobs # should be run in a branch of a fork of https://github.com/openshift/release/ # created with the assistance of Cursor AI @@ -10,6 +11,10 @@ set -o nounset set -o errexit set -o pipefail +# Endpoint for the Gangway API (https://docs.prow.k8s.io/docs/components/optional/gangway/) +# used to interact with Prow via REST API +GANGWAY_API_ENDPOINT="https://gangway-ci.apps.ci.l2s4.p1.openshiftapps.com/v1/executions" + # Function to get latest OSC catalog tag get_latest_osc_catalog_tag() { local apiurl="https://quay.io/api/v1/repository/redhat-user-workloads/ose-osc-tenant/osc-test-fbc" @@ -259,9 +264,12 @@ show_usage() { echo "" echo "Commands:" echo " create Create prowjob configuration files" + echo " run Run prowjobs from YAML configuration" echo "" echo "Examples:" echo " $0 create" + echo " $0 run /path/to/job_yaml.yaml" + echo " $0 run /path/to/job_yaml.yaml azure-ipi-kata" echo "" echo "Environment variables for 'create' command:" echo " OCP_VERSION - OpenShift version (default: 4.19)" @@ -299,6 +307,9 @@ main() { create) command_create ;; + run) + command_run "$@" + ;; *) echo "ERROR: Unknown command '${COMMAND}'" echo "" @@ -539,7 +550,19 @@ EOF echo "Generated file: ${OUTPUT_FILE}" echo "File size: ${file_size} bytes" echo "==========================================" - echo "Next Steps:" + echo "Next steps you have two options:" + echo "" + echo "Option A - Run jobs immediately:" + echo "1. Set your Prow API token:" + echo " export PROW_API_TOKEN=your_token_here" + echo "" + echo "2. Run all jobs from the generated file:" + echo " ./sandboxed-containers-operator-create-prowjob-commands.sh run ${OUTPUT_FILE}" + echo "" + echo "3. Or run specific jobs:" + echo " ./sandboxed-containers-operator-create-prowjob-commands.sh run ${OUTPUT_FILE} azure-ipi-kata" + echo "" + echo "Option B - Submit configuration to CI:" echo "1. Review the created configuration file:" echo " cat ${OUTPUT_FILE}" echo "" @@ -556,6 +579,152 @@ EOF echo "" } +# Function to run prowjobs +command_run() { + echo "==========================================" + echo "Sandboxed Containers Operator - Run Prowjobs" + echo "" + + # Check if job_yaml file is provided + if [[ $# -eq 0 ]]; then + echo "ERROR: No job YAML file specified" + echo "" + echo "Usage: $0 run [job_names...]" + echo "" + echo "Examples:" + echo " $0 run /path/to/job_yaml.yaml" + echo " $0 run /path/to/job_yaml.yaml azure-ipi-kata" + echo " $0 run /path/to/job_yaml.yaml azure-ipi-kata azure-ipi-peerpods" + echo "" + exit 1 + fi + + JOB_YAML_FILE="$1" + shift + + # Check if job_yaml file exists + if [[ ! -f "${JOB_YAML_FILE}" ]]; then + echo "ERROR: Job YAML file not found: ${JOB_YAML_FILE}" + exit 1 + fi + + echo "Job YAML file: ${JOB_YAML_FILE}" + + # Extract metadata from job_yaml + ORG=$(yq eval '.zz_generated_metadata.org' "${JOB_YAML_FILE}") + REPO=$(yq eval '.zz_generated_metadata.repo' "${JOB_YAML_FILE}") + BRANCH=$(yq eval '.zz_generated_metadata.branch' "${JOB_YAML_FILE}") + VARIANT=$(yq eval '.zz_generated_metadata.variant' "${JOB_YAML_FILE}") + + if [[ -z "${ORG}" || -z "${REPO}" || -z "${BRANCH}" || -z "${VARIANT}" ]]; then + echo "ERROR: Missing required metadata in job YAML file" + echo "Required fields: org, repo, branch, variant in zz_generated_metadata section" + exit 1 + fi + + # Generate job name prefix + JOB_PREFIX="periodic-ci-${ORG}-${REPO}-${BRANCH}-${VARIANT}" + echo "Job name prefix: ${JOB_PREFIX}" + + # Determine job names to run + if [[ $# -eq 0 ]]; then + # No specific jobs provided, extract all 'as' values from tests + echo "No specific jobs provided, extracting all jobs from YAML..." + mapfile -t JOB_NAMES < <(yq eval '.tests[].as' "${JOB_YAML_FILE}") + else + # Use provided job names + echo "Using provided job names: $*" + JOB_NAMES=("$@") + fi + + if [[ ${#JOB_NAMES[@]} -eq 0 ]]; then + echo "ERROR: No jobs found to run" + exit 1 + fi + + echo "" + echo "Jobs to run:" + for job_suffix in "${JOB_NAMES[@]}"; do + full_job_name="${JOB_PREFIX}-${job_suffix}" + echo " - ${full_job_name}" + done + + echo "" + echo "Preparing job execution..." + + # Check for PROW_API_TOKEN + if [[ -z "${PROW_API_TOKEN:-}" ]]; then + echo "ERROR: PROW_API_TOKEN environment variable is not set" + echo "Please set your Prow API token:" + echo " export PROW_API_TOKEN=your_token_here" + exit 1 + fi + echo "✓ PROW_API_TOKEN is set" + + # Convert job YAML to JSON + echo "Converting job YAML to JSON..." + if ! yq -o=json "${JOB_YAML_FILE}" | jq -Rs . > config.json; then + echo "ERROR: Failed to convert YAML to JSON" + exit 1 + fi + echo "✓ Job configuration converted to JSON" + + # Trigger jobs + echo "" + echo "Triggering jobs..." + + for job_suffix in "${JOB_NAMES[@]}"; do + full_job_name="${JOB_PREFIX}-${job_suffix}" + echo "" + echo "Triggering job: ${full_job_name}" + + # Create payload + UNRESOLVED_SPEC=$(cat config.json) + payload=$(jq -n --arg job "${full_job_name}" \ + --argjson config "${UNRESOLVED_SPEC}" \ + '{ + "job_name": $job, + "job_execution_type": "1", + "pod_spec_options": { + "envs": { + "UNRESOLVED_CONFIG": $config + }, + } + }') + + # Make API call + echo "Making API call to trigger job..." + if curl -s -X POST -H "Authorization: Bearer ${PROW_API_TOKEN}" \ + -H "Content-Type: application/json" -d "${payload}" \ + "${GANGWAY_API_ENDPOINT}" > "output_${job_suffix}.json"; then + + # Extract job ID + job_id=$(jq -r '.id' "output_${job_suffix}.json") + if [[ "${job_id}" != "null" && -n "${job_id}" ]]; then + echo "✓ Job triggered successfully!" + echo " Job ID: ${job_id}" + echo " Output saved to: output_${job_suffix}.json" + + # Get job status + echo "Fetching job status..." + curl -s -X GET -H "Authorization: Bearer ${PROW_API_TOKEN}" \ + "${GANGWAY_API_ENDPOINT}/${job_id}" > "status_${job_suffix}.json" + echo " Status saved to: status_${job_suffix}.json" + else + echo "✗ Failed to get job ID from response" + echo "Response content:" + cat "output_${job_suffix}.json" + fi + else + echo "✗ Failed to trigger job" + echo "Check output_${job_suffix}.json for details" + fi + done + + echo "" + echo "Job triggering completed!" + echo "Check the output_*.json and status_*.json files for details" +} # Call main function with all command line arguments main "$@" From fc1e75f7c472e97fa3118d39554cb61ff31e8914 Mon Sep 17 00:00:00 2001 From: Wainer dos Santos Moschetta Date: Fri, 3 Oct 2025 16:50:32 -0300 Subject: [PATCH 4/4] step-registry/sandboxed-containers-operator: Remove "documentation" from generated prowjob The documentation section in the generated prowjob is not valid for the ci-operator, resulting on job run via API to fail. Signed-off-by: Wainer dos Santos Moschetta --- .../sandboxed-containers-operator-create-prowjob-commands.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh index 8ad7ec8b3202f..e88806126d568 100755 --- a/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh +++ b/ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh @@ -341,9 +341,8 @@ command_create() { # Create the prowjob configuration file cat > "${OUTPUT_FILE}" <