Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 47 additions & 14 deletions config/forge/resolve_job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,75 @@ spec:
command: ["/bin/bash", "-c"]
args:
- |
#!/usr/bin/env bash

set -o pipefail
set -o errexit
set -o nounset
set -o errtrace

export ARTIFACT_DIR=/tmp/artifacts
export ARTIFACT_BASE_DIR="$(workspaces.artifacts.path)"
export ARTIFACT_DIR="${ARTIFACT_BASE_DIR}/${FOURNOS_STEP_NAME}"
Comment thread
kpouget marked this conversation as resolved.
mkdir -p "${ARTIFACT_DIR}"

exec &> >(tee -a "$ARTIFACT_DIR/run.log")

# Fetch FournosJob from the hub cluster (in-cluster SA) before
# switching KUBECONFIG to the target cluster.
oc get "fjob/$FJOB_NAME" -n "$FOURNOS_WORKLOAD_NAMESPACE" -oyaml > $ARTIFACT_DIR/fournos_fjob.yaml

PULL_BASE_SHA=$(cat "$ARTIFACT_DIR/fournos_fjob.yaml" | yq -r .spec.env.PULL_BASE_SHA)
if [[ "$PULL_BASE_SHA" != null ]]; then
export PULL_BASE_SHA
else
unset PULL_BASE_SHA
fi
# Check if we have a kubeconfig for target cluster
if [[ "$KUBECONFIG_SECRET_PARAM" != "fournos-clusterless-placeholder" && -f "$TARGET_KUBECONFIG" ]]; then
echo "Setting up target cluster kubeconfig..."
export KUBECONFIG=$TARGET_KUBECONFIG
export CLUSTERLESS_MODE="false"

PULL_PULL_SHA=$(cat "$ARTIFACT_DIR/fournos_fjob.yaml" | yq -r .spec.env.PULL_PULL_SHA)
if [[ "$PULL_PULL_SHA" != null ]]; then
export PULL_PULL_SHA
else
unset PULL_PULL_SHA
if [[ "$KUBECONFIG_SECRET_PARAM" == "fournos-clusterless-placeholder" ]]; then
echo "Running in clusterless mode - no target cluster kubeconfig"
else
echo "WARNING: Expected kubeconfig not found at: $TARGET_KUBECONFIG"
echo "Running in clusterless mode as fallback"
fi
export CLUSTERLESS_MODE="true"
fi

# Function to conditionally export environment variables from FournosJob spec
export_env_var_from_fjob() {
local var_name="$1"
local value=$(cat "$ARTIFACT_DIR/fournos_fjob.yaml" | yq -r ".spec.env.${var_name}")
if [[ "$value" != null ]]; then
export "$var_name=$value"
echo "Exported $var_name=$value"
else
unset "$var_name" 2>/dev/null || true
echo "Unset $var_name (was null in FournosJob spec)"
fi
}
Comment thread
kpouget marked this conversation as resolved.

# Export environment variables from FournosJob spec
export_env_var_from_fjob PULL_BASE_SHA
export_env_var_from_fjob PULL_PULL_SHA
export_env_var_from_fjob PULL_NUMBER

if [[ "${PULL_PULL_SHA:-}" ]]; then
echo
echo "Updating to PULL_PULL_SHA=$PULL_PULL_SHA ..."

git -C "$FORGE_HOME" fetch --quiet origin "$PULL_PULL_SHA"
git -C "$FORGE_HOME" reset --hard FETCH_HEAD

elif [[ "${PULL_NUMBER:-}" ]]; then
echo
echo "Updating to the HEAD commit of PR $PULL_NUMBER ..."
commit="refs/pull/$PULL_NUMBER/head"

git -C "$FORGE_HOME" fetch --quiet origin "$commit"
git -C "$FORGE_HOME" reset --hard FETCH_HEAD
export PULL_PULL_SHA="$(git rev-parse HEAD)"
echo "Setting PULL_PULL_SHA to '$PULL_PULL_SHA'"
Comment thread
kpouget marked this conversation as resolved.
else
echo "No PULL_PULL_SHA, using the image commit"
echo "No PULL_PULL_SHA nor PULL_NUMBER, using the image commit"
fi
git show --quiet

Expand All @@ -71,6 +106,4 @@ spec:
exit 1
fi

export FOURNOS_CI=true

exec bin/run_ci "$FORGE_PROJECT" ci "$FOURNOS_STEP"
Loading