Skip to content

Merge pull request #24742 from red-hat-data-services/konflux/componen… #21258

Merge pull request #24742 from red-hat-data-services/konflux/componen…

Merge pull request #24742 from red-hat-data-services/konflux/componen… #21258

name: Operator Processor
on:
workflow_dispatch:
push:
branches:
- 'rhoai-[23].[0-9]' # e.g. rhoai-2.1, rhoai-3.1, rhoai-3.4
- 'rhoai-[23].[0-9][0-9]' # e.g. rhoai-2.10, rhoai-3.10, rhoai-3.22
- 'rhoai-[23].[0-9]-ea.[0-9]' # e.g. rhoai-2.4-ea.1, rhoai-3.4-ea.1, rhoai-3.5-ea.2
- 'rhoai-[23].[0-9][0-9]-ea.[0-9]' # e.g. rhoai-2.10-ea.1, rhoai-3.10-ea.3
paths:
- build/operator-nudging.yaml
env:
GITHUB_ORG: red-hat-data-services
LOG_FILE_DIR: ${{ github.workspace }}
LOG_FILE_NAME: operator-processor.log
permissions:
contents: write
jobs:
operator-processor:
if: ${{ github.ref_name != 'main' && (github.event_name == 'workflow_dispatch' || ( github.event_name == 'push' && (github.event.commits[0].author.name == 'konflux-internal-p02[bot]' || github.event.commits[0].author.name == 'Openshift-AI DevOps') )) }}
runs-on: ubuntu-latest
steps:
- name: Checkout RBC repo
uses: actions/checkout@v4
with:
repository: ${{ env.GITHUB_ORG }}/RHOAI-Build-Config
ref: ${{ github.ref_name }}
path: RBC
sparse-checkout: |
bundle/bundle-patch.yaml
sparse-checkout-cone-mode: false
- name: Git checkout utils
uses: actions/checkout@v4
with:
repository: ${{ env.GITHUB_ORG }}/RHOAI-Konflux-Automation
ref: main
path: utils
sparse-checkout: |
utils/processors
sparse-checkout-cone-mode: false
- name: Git checkout operator repo
uses: actions/checkout@v4
with:
repository: ${{ env.GITHUB_ORG }}/rhods-operator
ref: ${{ github.ref_name }}
path: rhods-operator
sparse-checkout: |
build
prefetched-manifests
prefetched-charts
.tekton
sparse-checkout-cone-mode: false
- name: Install dependencies
run: |
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m | sed 's/x86_64/amd64/')"
yq_version="v4.44.3"
yq_filename="yq-$yq_version"
echo "-> Downloading yq" >&2
curl -sSfLo "$yq_filename" "https://github.com/mikefarah/yq/releases/download/$yq_version/yq_${os}_${arch}"
chmod +x $yq_filename
ln -s $yq_filename yq
cp $yq_filename /usr/local/bin/yq
pip install --default-timeout=100 -r utils/utils/processors/requirements.txt
- name: Execute Operator Processor
env:
BRANCH: ${{ github.ref_name }}
RHOAI_QUAY_API_TOKEN: ${{ secrets.RHOAI_QUAY_API_TOKEN }}
run: |
RHOAI_VERSION=v${BRANCH/rhoai-/}
COMPONENT_SUFFIX=${RHOAI_VERSION//./-}
ODH_OPERATOR_COMPONENT_NAME=odh-operator-${COMPONENT_SUFFIX}
PUSH_PIPELINE_PATH=rhods-operator/.tekton/${ODH_OPERATOR_COMPONENT_NAME}-push.yaml
PATCH_YAML_PATH=RBC/bundle/bundle-patch.yaml
OPERANDS_MAP_PATH=rhods-operator/build/operands-map.yaml
NUDGING_YAML_PATH=rhods-operator/build/operator-nudging.yaml
MANIFEST_CONFIG_PATH=rhods-operator/build/manifests-config.yaml
python3 utils/utils/processors/operator-processor.py -op process-operator-yamls --patch-yaml-path ${PATCH_YAML_PATH} --operands-map-path ${OPERANDS_MAP_PATH} --nudging-yaml-path ${NUDGING_YAML_PATH} --manifest-config-path ${MANIFEST_CONFIG_PATH} --rhoai-version ${BRANCH} --push-pipeline-yaml-path ${PUSH_PIPELINE_PATH} --push-pipeline-operation enable
- name: Print debug logs
if: always()
run: |
LOG_FILE="${{ env.LOG_FILE_DIR }}/${{ env.LOG_FILE_NAME }}"
if [ -f "$LOG_FILE" ]; then
cat "$LOG_FILE"
else
echo "Log file not found at $LOG_FILE"
fi
- name: Fetch all manifests
env:
BRANCH: ${{ github.ref_name }}
run: |
#!/bin/bash
set -e
echo "current dir = $(pwd)"
MANIFEST_CONFIG_PATH=${{ github.workspace }}/rhods-operator/build/manifests-config.yaml
PREFETCHED_MANIFEST_DIR_PATH="rhods-operator/prefetched-manifests"
# Clean up old prefetched manifests
if [ -d "$PREFETCHED_MANIFEST_DIR_PATH" ]; then
echo "Cleaning up old prefetched manifests..."
rm -rf "$PREFETCHED_MANIFEST_DIR_PATH"
fi
# Create fresh directories
mkdir -p "$PREFETCHED_MANIFEST_DIR_PATH"
mkdir -p manifests
cd manifests
while IFS= read -r value;
do
value=${value/- /}
component=$value
# Skip empty keys
[[ -z "$component" ]] && continue
echo "=============================================================="
echo "Fetching Manifest for component: $component"
echo "=============================================================="
if [[ -n $component ]]
then
git_url=$(value="$value" yq '.map[strenv(value)]["git.url"]' ${MANIFEST_CONFIG_PATH})
git_commit=$(value="$value" yq '.map[strenv(value)]["git.commit"]' ${MANIFEST_CONFIG_PATH})
ref_type=$(value="$value" yq '.map[strenv(value)]["ref_type"]' ${MANIFEST_CONFIG_PATH})
# If ref_type is branch, resolve the actual commit SHA
if [[ "$ref_type" == "branch" ]]; then
# Fetch latest commit SHA for the branch from remote
git_commit=$(git ls-remote "$git_url" "refs/heads/$BRANCH" | awk '{print $1}')
echo "Resolved git.commit for branch '$BRANCH' to commit SHA $git_commit"
# Update the git.commit field in manifests-config.yaml for the current component.
# Using strenv() to safely reference both the component key ($value) and the new commit SHA ($git_commit).
# This avoids issues with --arg, which is not supported in this yq version, and prevents creating an empty "" key.
value="$value" git_commit="$git_commit" yq -i eval '.map[strenv(value)]["git.commit"] = strenv(git_commit)' ${MANIFEST_CONFIG_PATH}
fi
src=$(value="$value" yq '.map[strenv(value)]["src"]' ${MANIFEST_CONFIG_PATH})
dest=$(value="$value" yq '.map[strenv(value)]["dest"]' ${MANIFEST_CONFIG_PATH})
echo "component = $component"
echo "git_url = $git_url"
echo "git_commit = $git_commit"
echo "src = $src"
echo "dest = $dest"
mkdir -p $component
cd $component
git config --global init.defaultBranch ${BRANCH}
git init
git remote add origin $git_url
git config core.sparseCheckout true
git config core.sparseCheckoutCone false
echo "$src" >> .git/info/sparse-checkout
git fetch --depth=1 origin $git_commit
git checkout $git_commit
cd ../
echo "current dir = $(pwd)"
dest_dir_path=${{ github.workspace }}/${PREFETCHED_MANIFEST_DIR_PATH}/$dest
mkdir -p ${dest_dir_path}
cp -r $component/$src/* ${dest_dir_path}
echo ""
fi
done < <(yq e '.map | keys' ${MANIFEST_CONFIG_PATH} )
cd ${{ github.workspace }}/${PREFETCHED_MANIFEST_DIR_PATH}
tree
- name: Fetch all charts
env:
BRANCH: ${{ github.ref_name }}
run: |
#!/bin/bash
set -e
echo "current dir = $(pwd)"
CHARTS_CONFIG_PATH=${{ github.workspace }}/rhods-operator/build/charts-config.yaml
PREFETCHED_CHARTS_DIR_PATH="rhods-operator/prefetched-charts"
# Clean up old prefetched charts
if [ -d "$PREFETCHED_CHARTS_DIR_PATH" ]; then
echo "Cleaning up old prefetched charts..."
rm -rf "$PREFETCHED_CHARTS_DIR_PATH"
fi
# Create fresh directories
mkdir -p "$PREFETCHED_CHARTS_DIR_PATH"
mkdir -p charts
cd charts
while IFS= read -r value;
do
value=${value/- /}
component=$value
# Skip empty keys
[[ -z "$component" ]] && continue
echo "=============================================================="
echo "Fetching Chart for component: $component"
echo "=============================================================="
if [[ -n $component ]]
then
git_url=$(value="$value" yq '.map[strenv(value)]["git.url"]' ${CHARTS_CONFIG_PATH})
git_commit=$(value="$value" yq '.map[strenv(value)]["git.commit"]' ${CHARTS_CONFIG_PATH})
ref_type=$(value="$value" yq '.map[strenv(value)]["ref_type"]' ${CHARTS_CONFIG_PATH})
if [[ "$ref_type" == "branch" ]]; then
git_commit=$(git ls-remote "$git_url" "refs/heads/$BRANCH" | awk '{print $1}')
echo "Resolved git.commit for branch '$BRANCH' to commit SHA $git_commit"
value="$value" git_commit="$git_commit" yq -i eval '.map[strenv(value)]["git.commit"] = strenv(git_commit)' ${CHARTS_CONFIG_PATH}
fi
src=$(value="$value" yq '.map[strenv(value)]["src"]' ${CHARTS_CONFIG_PATH})
dest=$(value="$value" yq '.map[strenv(value)]["dest"]' ${CHARTS_CONFIG_PATH})
echo "component = $component"
echo "git_url = $git_url"
echo "git_commit = $git_commit"
echo "src = $src"
echo "dest = $dest"
mkdir -p $component
cd $component
git config --global init.defaultBranch ${BRANCH}
git init
git remote add origin $git_url
git config core.sparseCheckout true
git config core.sparseCheckoutCone false
echo "$src" >> .git/info/sparse-checkout
git fetch --depth=1 origin $git_commit
git checkout $git_commit
cd ../
echo "current dir = $(pwd)"
dest_dir_path=${{ github.workspace }}/${PREFETCHED_CHARTS_DIR_PATH}/$dest
mkdir -p ${dest_dir_path}
cp -r $component/$src/* ${dest_dir_path}
echo ""
fi
done < <(yq e '.map | keys' ${CHARTS_CONFIG_PATH} )
cd ${{ github.workspace }}/${PREFETCHED_CHARTS_DIR_PATH}
tree
- name: Commit and push the changes to release branch
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref_name }}
message: "Updating the operator repo with latest images and manifests"
repository: ${{ env.GITHUB_ORG }}/rhods-operator
directory: rhods-operator
author_name: Openshift-AI DevOps
author_email: openshift-ai-devops@redhat.com
- name: Upload debug logs
if: always()
uses: actions/upload-artifact@v4
with:
name: operator-processor-output
path: ${{ env.LOG_FILE_DIR }}/${{ env.LOG_FILE_NAME }}
if-no-files-found: warn
retention-days: 30