Skip to content

Commit fe996ff

Browse files
committed
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 <[email protected]>
1 parent efc11e9 commit fe996ff

File tree

2 files changed

+227
-1
lines changed

2 files changed

+227
-1
lines changed

ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The `sandboxed-containers-operator-create-prowjob-commands.sh` script creates pr
1111
The script supports the following commands:
1212

1313
- `create` - Create prowjob configuration files
14+
- `run` - Run prowjobs from YAML configuration
1415

1516
### Command Usage
1617

@@ -48,6 +49,12 @@ ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed
4849

4950
# Generate configuration with custom OCP version
5051
OCP_VERSION=4.17 ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh create
52+
53+
# Run jobs from generated YAML file
54+
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
55+
56+
# Run specific job
57+
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
5158
```
5259

5360
### Environment Variables
@@ -136,6 +143,34 @@ ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed
136143
- **Method**: Quay API with pagination (max 50 pages)
137144
- **Special Case**: OCP 4.16 uses `trustee-fbc/` subfolder
138145

146+
## Run Command
147+
148+
The `run` command allows you to trigger ProwJobs from a generated YAML configuration file. This command requires a valid Prow API token.
149+
150+
### Run Command Usage
151+
152+
```bash
153+
# Run all jobs from a YAML file
154+
./sandboxed-containers-operator-create-prowjob-commands.sh run /path/to/job_yaml.yaml
155+
156+
# Run specific jobs from a YAML file
157+
./sandboxed-containers-operator-create-prowjob-commands.sh run /path/to/job_yaml.yaml azure-ipi-kata aws-ipi-peerpods
158+
```
159+
160+
### Run Command Features
161+
162+
- **Job Name Generation**: Automatically constructs job names using the pattern `periodic-ci-{org}-{repo}-{branch}-{variant}-{job_suffix}`
163+
- **Metadata Extraction**: Extracts organization, repository, branch, and variant from the YAML file's `zz_generated_metadata` section
164+
- **API Integration**: Uses the Prow/Gangway API to trigger jobs
165+
- **Job Status Monitoring**: Provides job IDs and status information
166+
- **Flexible Job Selection**: Can run all jobs or specific jobs by name
167+
168+
### Run Command Environment Variables
169+
170+
| Variable | Required | Description |
171+
|----------|----------|-------------|
172+
| `PROW_API_TOKEN` | Yes | Prow API authentication token |
173+
139174
## Generated Test Matrix
140175

141176
The script generates configuration for 5 test scenarios:
@@ -219,3 +254,25 @@ yq eval '.' openshift-sandboxed-containers-operator-devel__downstream-candidate4
219254
- **Required**: `curl`, `jq`, `awk`, `sort`, `head`
220255
- **Optional**: `yq` (for YAML syntax validation)
221256
- **Network**: Access to `quay.io` API endpoints
257+
258+
## Prow API Token
259+
260+
To trigger ProwJobs via the REST API, you need an authentication token. Each SSO user is entitled to obtain a personal authentication token.
261+
262+
### Obtaining a Token
263+
264+
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:
265+
266+
```bash
267+
oc whoami -t
268+
```
269+
270+
### Using the Token
271+
272+
Once you have obtained a token, set it as an environment variable:
273+
274+
```bash
275+
export PROW_API_TOKEN=your_token_here
276+
```
277+
278+
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).

ci-operator/step-registry/sandboxed-containers-operator/create-prowjob/sandboxed-containers-operator-create-prowjob-commands.sh

Lines changed: 170 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# script to create prowjobs in ci-operator/config/openshift/sandboxed-containers-operator using environment variables.
33
# Usage:
44
# ./sandboxed-containers-operator-create-prowjob-commands.sh gen # Generate prowjob configuration
5+
# ./sandboxed-containers-operator-create-prowjob-commands.sh run # Run prowjobs
56
# should be run in a branch of a fork of https://github.com/openshift/release/
67

78
# created with the assistance of Cursor AI
@@ -10,6 +11,10 @@ set -o nounset
1011
set -o errexit
1112
set -o pipefail
1213

14+
# Endpoint for the Gangway API (https://docs.prow.k8s.io/docs/components/optional/gangway/)
15+
# used to interact with Prow via REST API
16+
GANGWAY_API_ENDPOINT="https://gangway-ci.apps.ci.l2s4.p1.openshiftapps.com/v1/executions"
17+
1318
# Function to get latest OSC catalog tag
1419
get_latest_osc_catalog_tag() {
1520
local apiurl="https://quay.io/api/v1/repository/redhat-user-workloads/ose-osc-tenant/osc-test-fbc"
@@ -259,9 +264,12 @@ show_usage() {
259264
echo ""
260265
echo "Commands:"
261266
echo " create Create prowjob configuration files"
267+
echo " run Run prowjobs from YAML configuration"
262268
echo ""
263269
echo "Examples:"
264270
echo " $0 create"
271+
echo " $0 run /path/to/job_yaml.yaml"
272+
echo " $0 run /path/to/job_yaml.yaml azure-ipi-kata"
265273
echo ""
266274
echo "Environment variables for 'create' command:"
267275
echo " OCP_VERSION - OpenShift version (default: 4.19)"
@@ -299,6 +307,9 @@ main() {
299307
create)
300308
command_create
301309
;;
310+
run)
311+
command_run "$@"
312+
;;
302313
*)
303314
echo "ERROR: Unknown command '${COMMAND}'"
304315
echo ""
@@ -539,7 +550,19 @@ EOF
539550
echo "Generated file: ${OUTPUT_FILE}"
540551
echo "File size: ${file_size} bytes"
541552
echo "=========================================="
542-
echo "Next Steps:"
553+
echo "Next steps you have two options:"
554+
echo ""
555+
echo "Option A - Run jobs immediately:"
556+
echo "1. Set your Prow API token:"
557+
echo " export PROW_API_TOKEN=your_token_here"
558+
echo ""
559+
echo "2. Run all jobs from the generated file:"
560+
echo " ./sandboxed-containers-operator-create-prowjob-commands.sh run ${OUTPUT_FILE}"
561+
echo ""
562+
echo "3. Or run specific jobs:"
563+
echo " ./sandboxed-containers-operator-create-prowjob-commands.sh run ${OUTPUT_FILE} azure-ipi-kata"
564+
echo ""
565+
echo "Option B - Submit configuration to CI:"
543566
echo "1. Review the created configuration file:"
544567
echo " cat ${OUTPUT_FILE}"
545568
echo ""
@@ -556,6 +579,152 @@ EOF
556579
echo ""
557580
}
558581

582+
# Function to run prowjobs
583+
command_run() {
584+
echo "=========================================="
585+
echo "Sandboxed Containers Operator - Run Prowjobs"
586+
echo ""
587+
588+
# Check if job_yaml file is provided
589+
if [[ $# -eq 0 ]]; then
590+
echo "ERROR: No job YAML file specified"
591+
echo ""
592+
echo "Usage: $0 run <job_yaml_file> [job_names...]"
593+
echo ""
594+
echo "Examples:"
595+
echo " $0 run /path/to/job_yaml.yaml"
596+
echo " $0 run /path/to/job_yaml.yaml azure-ipi-kata"
597+
echo " $0 run /path/to/job_yaml.yaml azure-ipi-kata azure-ipi-peerpods"
598+
echo ""
599+
exit 1
600+
fi
601+
602+
JOB_YAML_FILE="$1"
603+
shift
604+
605+
# Check if job_yaml file exists
606+
if [[ ! -f "${JOB_YAML_FILE}" ]]; then
607+
echo "ERROR: Job YAML file not found: ${JOB_YAML_FILE}"
608+
exit 1
609+
fi
610+
611+
echo "Job YAML file: ${JOB_YAML_FILE}"
612+
613+
# Extract metadata from job_yaml
614+
ORG=$(yq eval '.zz_generated_metadata.org' "${JOB_YAML_FILE}")
615+
REPO=$(yq eval '.zz_generated_metadata.repo' "${JOB_YAML_FILE}")
616+
BRANCH=$(yq eval '.zz_generated_metadata.branch' "${JOB_YAML_FILE}")
617+
VARIANT=$(yq eval '.zz_generated_metadata.variant' "${JOB_YAML_FILE}")
618+
619+
if [[ -z "${ORG}" || -z "${REPO}" || -z "${BRANCH}" || -z "${VARIANT}" ]]; then
620+
echo "ERROR: Missing required metadata in job YAML file"
621+
echo "Required fields: org, repo, branch, variant in zz_generated_metadata section"
622+
exit 1
623+
fi
624+
625+
# Generate job name prefix
626+
JOB_PREFIX="periodic-ci-${ORG}-${REPO}-${BRANCH}-${VARIANT}"
627+
echo "Job name prefix: ${JOB_PREFIX}"
628+
629+
# Determine job names to run
630+
if [[ $# -eq 0 ]]; then
631+
# No specific jobs provided, extract all 'as' values from tests
632+
echo "No specific jobs provided, extracting all jobs from YAML..."
633+
mapfile -t JOB_NAMES < <(yq eval '.tests[].as' "${JOB_YAML_FILE}")
634+
else
635+
# Use provided job names
636+
echo "Using provided job names: $*"
637+
JOB_NAMES=("$@")
638+
fi
639+
640+
if [[ ${#JOB_NAMES[@]} -eq 0 ]]; then
641+
echo "ERROR: No jobs found to run"
642+
exit 1
643+
fi
644+
645+
echo ""
646+
echo "Jobs to run:"
647+
for job_suffix in "${JOB_NAMES[@]}"; do
648+
full_job_name="${JOB_PREFIX}-${job_suffix}"
649+
echo " - ${full_job_name}"
650+
done
651+
652+
echo ""
653+
echo "Preparing job execution..."
654+
655+
# Check for PROW_API_TOKEN
656+
if [[ -z "${PROW_API_TOKEN:-}" ]]; then
657+
echo "ERROR: PROW_API_TOKEN environment variable is not set"
658+
echo "Please set your Prow API token:"
659+
echo " export PROW_API_TOKEN=your_token_here"
660+
exit 1
661+
fi
662+
echo "✓ PROW_API_TOKEN is set"
663+
664+
# Convert job YAML to JSON
665+
echo "Converting job YAML to JSON..."
666+
if ! yq -o=json "${JOB_YAML_FILE}" | jq -Rs . > config.json; then
667+
echo "ERROR: Failed to convert YAML to JSON"
668+
exit 1
669+
fi
670+
echo "✓ Job configuration converted to JSON"
671+
672+
# Trigger jobs
673+
echo ""
674+
echo "Triggering jobs..."
675+
676+
for job_suffix in "${JOB_NAMES[@]}"; do
677+
full_job_name="${JOB_PREFIX}-${job_suffix}"
678+
echo ""
679+
echo "Triggering job: ${full_job_name}"
680+
681+
# Create payload
682+
UNRESOLVED_SPEC=$(cat config.json)
683+
payload=$(jq -n --arg job "${full_job_name}" \
684+
--argjson config "${UNRESOLVED_SPEC}" \
685+
'{
686+
"job_name": $job,
687+
"job_execution_type": "1",
688+
"pod_spec_options": {
689+
"envs": {
690+
"UNRESOLVED_CONFIG": $config
691+
},
692+
}
693+
}')
694+
695+
# Make API call
696+
echo "Making API call to trigger job..."
697+
if curl -s -X POST -H "Authorization: Bearer ${PROW_API_TOKEN}" \
698+
-H "Content-Type: application/json" -d "${payload}" \
699+
"${GANGWAY_API_ENDPOINT}" > "output_${job_suffix}.json"; then
700+
701+
# Extract job ID
702+
job_id=$(jq -r '.id' "output_${job_suffix}.json")
703+
if [[ "${job_id}" != "null" && -n "${job_id}" ]]; then
704+
echo "✓ Job triggered successfully!"
705+
echo " Job ID: ${job_id}"
706+
echo " Output saved to: output_${job_suffix}.json"
707+
708+
# Get job status
709+
echo "Fetching job status..."
710+
curl -s -X GET -H "Authorization: Bearer ${PROW_API_TOKEN}" \
711+
"${GANGWAY_API_ENDPOINT}/${job_id}" > "status_${job_suffix}.json"
712+
echo " Status saved to: status_${job_suffix}.json"
713+
else
714+
echo "✗ Failed to get job ID from response"
715+
echo "Response content:"
716+
cat "output_${job_suffix}.json"
717+
fi
718+
else
719+
echo "✗ Failed to trigger job"
720+
echo "Check output_${job_suffix}.json for details"
721+
fi
722+
done
723+
724+
echo ""
725+
echo "Job triggering completed!"
726+
echo "Check the output_*.json and status_*.json files for details"
727+
}
559728

560729
# Call main function with all command line arguments
561730
main "$@"

0 commit comments

Comments
 (0)