diff --git a/.github/workflows/e2e-cluster-lifecycle.yml b/.github/workflows/e2e-cluster-lifecycle.yml index fb0f8cb..1fbae98 100644 --- a/.github/workflows/e2e-cluster-lifecycle.yml +++ b/.github/workflows/e2e-cluster-lifecycle.yml @@ -21,7 +21,7 @@ jobs: git fetch origin main CHANGED_FILES=$(git diff --name-only origin/main...HEAD) - if ! echo "$CHANGED_FILES" | grep -qE '^(src/roles/clusters/kind/|tests/e2e/cluster-life-cycle/kind_install_delete/|default_provided_services/|hacks/|.github/|commons/)'; then + if ! echo "$CHANGED_FILES" | grep -qE '^(src/roles/clusters/kind/|tests/e2e/cluster-life-cycle/kind_install_delete/|hacks/|.github/|commons/)'; then echo "No relevant files changed for KIND cluster-lifecycle-test. Skipping tests but marking success." exit 0 fi diff --git a/src/roles/kserve/tests/create-devflag/build.sh b/src/roles/kserve/tests/create-devflag/build.sh new file mode 100644 index 0000000..7b24386 --- /dev/null +++ b/src/roles/kserve/tests/create-devflag/build.sh @@ -0,0 +1,206 @@ +#!/usr/bin/env bash +## INIT START ## +if [[ $DEBUG == "0" ]]; then + set -x +fi + +# Get the directory where this script is located +current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# Traverse up the directory tree to find the .github folder +github_dir="$current_dir" +while [ ! -d "$github_dir/.git" ] && [ "$github_dir" != "/" ]; do + github_dir="$(dirname "$github_dir")" +done + +# If the .github folder is found, set root_directory +if [ -d "$github_dir/.git" ]; then + root_directory="$github_dir" +else + echo "Error: Unable to find .github folder." +fi +source $root_directory/src/commons/scripts/utils.sh +## INIT END ## + +# Function to check if branch exists +check_and_create_branch() { + local branch_name=$1 + if git show-ref --verify --quiet refs/heads/$branch_name; then + echo "Branch $branch_name already exists, skipping branch creation" + return 0 + else + git checkout -b $branch_name + return $? + fi +} + +# Function to check if image already exists with same SHA +check_image_exists() { + local image_url=$1 + + if ${CONTAINER_CLI} manifest inspect $image_url >/dev/null 2>&1; then + echo "Image $image_url already exists" + return 0 + else + echo "Image $image_url does not exist" + return 1 + fi +} + +# Function to build and push image +build_and_push_image() { + local component=$1 + local registry=$2 + local tag=$3 + local skip_build=$4 + + if [[ "$skip_build" == "true" ]]; then + info "Skipping build and pushing ${component}-controller image..." + else + info "Building and pushing ${component}-controller image..." + ENGINE=${CONTAINER_CLI} make docker-build + fi + ${CONTAINER_CLI} tag docker.io/library/${component}-controller:latest ${registry}/${component}-controller:${tag} + ${CONTAINER_CLI} push ${registry}/${component}-controller:${tag} +} + +# Function to setup git repository and branch +setup_git_repo() { + local use_case=$1 + local target_parent_directory=$2 + + if [[ "${use_case}" != "LOCAL_SOURCE" ]]; then + cd $target_parent_directory + + # Clone repository + if [[ -d ${COMPONENT_NAME} ]]; then + info "Repository ${COMPONENT_NAME} already exists, skipping clone" + else + info "Cloning ${COMPONENT_NAME} repository(git clone git@github.com:${USER_NAME}/${COMPONENT_NAME}.git)..." + git clone git@github.com:${USER_NAME}/${COMPONENT_NAME}.git + if [[ $? != 0 ]]; then + error "Failed to clone ${COMPONENT_NAME}." + return 1 + fi + fi + cd ${COMPONENT_NAME} + else + if [[ $(basename "$ORIGINAL_DIR") != ${COMPONENT_NAME} ]]; then + error "This is not the ${COMPONENT_NAME} repository" + return 1 + fi + fi + + + if [[ ${COMPONENT_NAME} == "kserve" ]]; then + if [[ ! -d /tmp/kserve/config/overlays/odh ]]; then + error "This is upstream kserve that does not support devflag" + return 1 + fi + fi + # Set environment variables + export REPO_URL=https://github.com/${USER_NAME}/${COMPONENT_NAME}.git + export KO_DOCKER_REPO=${REGISTRY_URL} + + # Handle different source types + case $use_case in + "PR_SOURCE") + info "Setting up PR source from: ${PR_URL}" + export PR_REPO_URL=https://github.com/${PR_USER_NAME}/${COMPONENT_NAME}.git + + # Setup git remotes and fetch + if ! git remote | grep -q "^${PR_USER_NAME}$"; then + git remote add ${PR_USER_NAME} ${PR_REPO_URL} + git fetch --all + fi + + # Checkout PR branch for build + git checkout -b ${PR_BRANCH_NAME}-for-devflag ${PR_USER_NAME}/${PR_BRANCH_NAME} 2>/dev/null || git checkout ${PR_BRANCH_NAME}-for-devflag + ;; + + "REMOTE_SOURCE") + info "Setting up remote source from: ${TARGET_USER_NAME}/${TARGET_BRANCH_NAME}" + export TARGET_REPO_URL=https://github.com/${TARGET_USER_NAME}/${COMPONENT_NAME}.git + + # Setup git remotes and fetch + git remote add ${TARGET_USER_NAME} ${TARGET_REPO_URL} + git fetch --all + + # Checkout target branch for build + git checkout -b ${TARGET_BRANCH_NAME}-for-devflag ${TARGET_USER_NAME}/${TARGET_BRANCH_NAME} 2>/dev/null || git checkout ${TARGET_BRANCH_NAME}-for-devflag + ;; + + "LOCAL_SOURCE") + info "Use local source for build" + ;; + + "CUSTOM_IMAGE") + info "Use custom image without build: ${CUSTOM_IMAGE}" + ;; + esac +} + +# Function to update manifest files +update_manifests() { + local target_image=$1 + + kserve_params_file="config/overlays/odh/params.env" + odh_model_controller_params_file="config/base/params.env" + + # Checkout a new branch "${TEST_MANIFEST_BRANCH}" for updating manifests + # git checkout -b ${TEST_MANIFEST_BRANCH} 2>/dev/null || git checkout ${TEST_MANIFEST_BRANCH} + check_and_create_branch ${TEST_MANIFEST_BRANCH} + # Check and update controller image in params.env + if [[ ${COMPONENT_NAME} == "kserve" ]]; then + if grep -q "$target_image" ${kserve_params_file}; then + info "Controller image is already updated in params.env, skipping update" + else + # Update the controller image in params.env + sed -i "s|^${COMPONENT_NAME}-controller=.*|kserve-controller=${target_image}|g" ${kserve_params_file} + info "Updated ${COMPONENT_NAME}-controller image in params.env" + fi + else + if grep -q "$target_image" ${odh_model_controller_params_file}; then + info "Controller image is already updated in params.env, skipping update" + else + # Update the controller image in params.env + sed -i "s|^${COMPONENT_NAME}=.*|odh-model-controller=${target_image}|g" ${odh_model_controller_params_file} + info "Updated ${COMPONENT_NAME} image in params.env" + fi + fi + + # Commit and push changes + git add . + git commit -m "Update ${target_image} in params.env" + git push -u origin ${TEST_MANIFEST_BRANCH} -f +} + +# Function to handle image building and pushing +handle_image_build() { + local target_image="${KO_DOCKER_REPO}/${COMPONENT_NAME}-controller:${TAG}" + local target_parent_directory=$1 + + cd $target_parent_directory/${COMPONENT_NAME} + if check_image_exists "$target_image"; then + info "Controller image $target_image already exists, checking SHA..." + + # Get the SHA of the existing image + existing_sha=$(${CONTAINER_CLI} manifest inspect $target_image | jq -r '.config.digest' 2>/dev/null || echo "") + + # Build locally to get the new SHA + make docker-build + local_sha=$(${CONTAINER_CLI} inspect docker.io/library/${COMPONENT_NAME}-controller:latest | jq -r '.[0].Id' 2>/dev/null || echo "") + + if [[ "$existing_sha" == "$local_sha" ]]; then + info "Controller image with same SHA already exists, skipping push" + else + info "Controller image exists but with different SHA, pushing new image..." + build_and_push_image "$COMPONENT_NAME" "$KO_DOCKER_REPO" "$TAG" "true" + fi + else + info "Controller image does not exist, building and pushing..." + build_and_push_image "$COMPONENT_NAME" "$KO_DOCKER_REPO" "$TAG" "false" + fi + + echo "$target_image" +} \ No newline at end of file diff --git a/src/roles/kserve/tests/create-devflag/config.yaml b/src/roles/kserve/tests/create-devflag/config.yaml new file mode 100644 index 0000000..cb4fac9 --- /dev/null +++ b/src/roles/kserve/tests/create-devflag/config.yaml @@ -0,0 +1,101 @@ +role: + created_date: "20250620" + name: create-devflag + description: | + This role helps to create devflag branch and update kserve-controller/odh-model-controller image. + It supports 4 different use cases with different environment variable requirements. + + pre-requirements: + - docker or podman + - You have to setup SSH key to github before running this role. + - You have to login to registry like dockerhub or quay.io before running this role. + - curl and jq are required for PR source mode + + Use Cases: + 1. Remote Source: Build controller image from remote source and push to registry, then create devflag branch + Required: USER_NAME, TARGET_USER_NAME, COMPONENT_NAME, TARGET_BRANCH_NAME, CTRL_IMG_TAG, REGISTRY_URL + + 2. PR Source: Build controller image from PR source and push to registry, then create devflag branch + Required: USER_NAME, PR_URL, CTRL_IMG_TAG, REGISTRY_URL + + 3. Local Source: Build controller image from local source and push to registry, then create devflag branch + Required: USER_NAME, CTRL_IMG_TAG, REGISTRY_URL + + 4. Custom Image: Create devflag branch and update manifests with custom image (no building) + Required: USER_NAME, COMPONENT_NAME, CUSTOM_IMAGE, CTRL_IMG_TAG, REGISTRY_URL + + Usage Examples: + + 1. Remote source: + ./loopy roles run create-devflag \ + -p USER_NAME=jooho \ + -p TARGET_USER_NAME=test \ + -p COMPONENT_NAME=kserve \ + -p TARGET_BRANCH_NAME=pr_branch \ + -p CTRL_IMG_TAG=loopy \ + -p REGISTRY_URL=quay.io/jooholee + + 2. PR source: + ./loopy roles run create-devflag \ + -p USER_NAME=jooho \ + -p PR_URL=https://github.com/opendatahub-io/kserve/pulls/684 \ + -p CTRL_IMG_TAG=loopy \ + -p REGISTRY_URL=quay.io/jooholee + + 3. Local source: + ./loopy roles run create-devflag \ + -p USER_NAME=jooho \ + -p CTRL_IMG_TAG=loopy \ + -p REGISTRY_URL=quay.io/jooholee + + 4. Custom image: + ./loopy roles run create-devflag \ + -p USER_NAME=jooho \ + -p COMPONENT_NAME=kserve \ + -p CUSTOM_IMAGE=quay.io/jooholee/kserve-controller:loopy \ + -p CTRL_IMG_TAG=loopy \ + -p REGISTRY_URL=quay.io/jooholee + + input_env: + - name: CONTAINER_CLI + description: container runtime cli (docker or podman) + default: "docker" + + - name: USER_NAME + description: Set your github user name + required: true + + - name: REGISTRY_URL + description: DockerHub/Quay repo url (e.g. quay.io/jooholee) + required: true + + - name: COMPONENT_NAME + description: Set target github repo name (kserve or odh-model-controller) + default: "kserve" + + - name: TARGET_USER_NAME + description: github user name for remote source (Case 1) + + - name: TARGET_BRANCH_NAME + description: github branch name for remote source (Case 1) + + - name: PR_URL + description: github PR url for PR source (Case 2). Format https://github.com/user/repo/pull/number + + - name: CUSTOM_IMAGE + description: custom controller image URL for custom image mode (Case 4) + + - name: CTRL_IMG_TAG + description: docker tag for built images + default: "loopy" + + - name: TEST_MANIFEST_BRANCH + description: github branch name for updating manifests + default: "loopy-test-devflag" + +output_env: +- name: CUSTOM_KSERVE_MANIFESTS + description: custom kserve manifests url (e.g. "https://github.com/jooho/kserve/tarball/loopy-test-devflag") + +- name: CUSTOM_ODH_MODEL_CONTROLLER_MANIFESTS + description: custom odh-model-controller manifests url (e.g. "https://github.com/jooho/odh-model-controller/tarball/loopy-test-devflag") diff --git a/src/roles/kserve/tests/create-devflag/main.sh b/src/roles/kserve/tests/create-devflag/main.sh new file mode 100644 index 0000000..69c3deb --- /dev/null +++ b/src/roles/kserve/tests/create-devflag/main.sh @@ -0,0 +1,116 @@ +#!/usr/bin/env bash +## INIT START ## +if [[ $DEBUG == "0" ]]; then + set -x +fi + +# Get the directory where this script is located +current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# Traverse up the directory tree to find the .github folder +github_dir="$current_dir" +while [ ! -d "$github_dir/.git" ] && [ "$github_dir" != "/" ]; do + github_dir="$(dirname "$github_dir")" +done + +# If the .github folder is found, set root_directory +if [ -d "$github_dir/.git" ]; then + root_directory="$github_dir" + echo "The root directory is: $root_directory" +else + echo "Error: Unable to find .github folder." +fi +source $root_directory/src/commons/scripts/utils.sh +## INIT END ## + +################################################################# +# Source additional function files +source "${current_dir}/validation.sh" +source "${current_dir}/build.sh" +source "${current_dir}/verify.sh" + +index_role_name=$(basename $ROLE_DIR) +role_name=$(yq e '.role.name' ${current_dir}/config.yaml) + +################### +result=0 +# cd $ROLE_DIR + +# Validate pre-requisites +export CONTAINER_CLI=${CONTAINER_CLI:-podman} +if [[ ! $(command -v ${CONTAINER_CLI}) ]]; then + error "${CONTAINER_CLI} is not installed." + exit 1 +fi + +# Validate environment variables first +info "Validating environment variables" +if ! validate_env_vars ${root_directory}; then + error "Validation failed" + exit 1 +fi + + +# Determine use case +use_case="" +if [[ -n "${PR_URL}" ]]; then + use_case="PR_SOURCE" +elif [[ -n "${CUSTOM_IMAGE}" ]]; then + use_case="CUSTOM_IMAGE" +elif [[ -n "${TARGET_USER_NAME}" && -n "${TARGET_BRANCH_NAME}" ]]; then + use_case="REMOTE_SOURCE" +else + use_case="LOCAL_SOURCE" +fi + +# Setup git repository +GIT_PARENT_REPO_DIR="${ROLE_DIR}" +if [[ "$use_case" == "LOCAL_SOURCE" ]]; then + GIT_PARENT_REPO_DIR="$(dirname ${ORIGINAL_DIR})" +fi +debug "ORIGINAL_DIR: ${ORIGINAL_DIR}" +debug "ROLE_DIR: ${ROLE_DIR}" +debug "GIT_PARENT_REPO_DIR: ${GIT_PARENT_REPO_DIR}" +setup_git_repo "$use_case" "$GIT_PARENT_REPO_DIR" +if [[ $? -ne 0 ]]; then + error "Failed to setup git repository" + exit 1 + result=1 +fi + +# Execute based on use case +TARGET_IMAGE="" +if [[ "$use_case" == "CUSTOM_IMAGE" ]]; then + # Case 4: Custom image - only update manifests, no image building + TARGET_IMAGE="${CUSTOM_IMAGE}" +else + # Cases 1, 2, 3: Need to build and push image + # Handle container image building and pushing + info "Building image: ${REGISTRY_URL}/${COMPONENT_NAME}-controller:${CTRL_IMG_TAG}" + handle_image_build "$GIT_PARENT_REPO_DIR" + if [[ $? -ne 0 ]]; then + error "Failed to build image" + exit 1 + fi + TARGET_IMAGE=${REGISTRY_URL}/${COMPONENT_NAME}-controller:${CTRL_IMG_TAG} +fi + +cd $GIT_PARENT_REPO_DIR/${COMPONENT_NAME} +# Check and update controller image in params.env +update_manifests "$TARGET_IMAGE" +############# VERIFY ############# +run_all_verifications "$TARGET_IMAGE" "$GIT_PARENT_REPO_DIR/${COMPONENT_NAME}" +result=$? + +############# OUTPUT ############# +# Generate output based on component type +TARBALL_URL="https://github.com/${USER_NAME}/${COMPONENT_NAME}/tarball/${TEST_MANIFEST_BRANCH}" + +if [[ ${COMPONENT_NAME} == "kserve" ]]; then + echo "CUSTOM_KSERVE_MANIFESTS=${TARBALL_URL}" >${OUTPUT_ENV_FILE} +else + echo "CUSTOM_ODH_MODEL_CONTROLLER_MANIFESTS=${TARBALL_URL}" >${OUTPUT_ENV_FILE} +fi + +############# REPORT ############# +echo "${index_role_name}::${result}" >>${REPORT_FILE} diff --git a/src/roles/kserve/tests/create-devflag/validation.sh b/src/roles/kserve/tests/create-devflag/validation.sh new file mode 100755 index 0000000..4bac0c6 --- /dev/null +++ b/src/roles/kserve/tests/create-devflag/validation.sh @@ -0,0 +1,182 @@ +#!/usr/bin/env bash + + +# Function to validate environment variables for different use cases +validate_env_vars() { + root_directory=$1 + source $root_directory/src/commons/scripts/utils.sh + local use_case="" + local missing_vars=() + local conflicting_vars=() + + # First, validate that only one use case is specified (mutually exclusive) + local use_case_count=0 + + # Check PR_SOURCE indicators + if [[ -n "${PR_URL}" ]]; then + use_case_count=$((use_case_count + 1)) + conflicting_vars+=("PR_URL") + fi + + # Check CUSTOM_IMAGE indicators + if [[ -n "${CUSTOM_IMAGE}" ]]; then + use_case_count=$((use_case_count + 1)) + conflicting_vars+=("CUSTOM_IMAGE") + fi + + # Check REMOTE_SOURCE indicators + if [[ -n "${TARGET_USER_NAME}" && -n "${TARGET_BRANCH_NAME}" ]]; then + use_case_count=$((use_case_count + 1)) + conflicting_vars+=("TARGET_USER_NAME + TARGET_BRANCH_NAME") + fi + + # Validate mutual exclusivity + if [[ $use_case_count -gt 1 ]]; then + error "Multiple use cases detected. Only one use case can be specified at a time." + error "Conflicting variables found: ${conflicting_vars[*]}" + echo "" + echo "Use case definitions:" + echo "- PR_SOURCE: PR_URL is set" + echo "- CUSTOM_IMAGE: CUSTOM_IMAGE is set" + echo "- REMOTE_SOURCE: Both TARGET_USER_NAME and TARGET_BRANCH_NAME are set" + echo "- LOCAL_SOURCE: None of the above are set" + echo "" + return 1 + fi + + # Determine use case based on provided variables + if [[ -n "${PR_URL}" ]]; then + use_case="PR_SOURCE" + elif [[ -n "${CUSTOM_IMAGE}" ]]; then + use_case="CUSTOM_IMAGE" + elif [[ -n "${TARGET_USER_NAME}" && -n "${TARGET_BRANCH_NAME}" ]]; then + use_case="REMOTE_SOURCE" + else + use_case="LOCAL_SOURCE" + fi + + info "Detected use case: $use_case" + + case $use_case in + "REMOTE_SOURCE") + # Case 1: Remote source + local required_vars=("USER_NAME" "TARGET_USER_NAME" "COMPONENT_NAME" "TARGET_BRANCH_NAME" "CTRL_IMG_TAG" "REGISTRY_URL") + ;; + "PR_SOURCE") + # Case 2: PR source + local required_vars=("USER_NAME" "PR_URL" "CTRL_IMG_TAG" "REGISTRY_URL") + ;; + "LOCAL_SOURCE") + # Case 3: Local source + local required_vars=("USER_NAME" "CTRL_IMG_TAG" "REGISTRY_URL") + ;; + "CUSTOM_IMAGE") + # Case 4: Custom image + local required_vars=("USER_NAME" "COMPONENT_NAME" "CUSTOM_IMAGE" "CTRL_IMG_TAG" "REGISTRY_URL") + ;; + esac + + # Check if all required variables are set + for var in "${required_vars[@]}"; do + if [[ -z "${!var}" ]]; then + missing_vars+=("$var") + fi + done + + if [[ ${#missing_vars[@]} -gt 0 ]]; then + error "Missing required environment variables for use case '$use_case':" + for var in "${missing_vars[@]}"; do + error " - $var" + done + + # Print usage examples + echo "" + echo "Usage examples:" + echo "" + echo "1. Remote source:" + echo " ./loopy roles run create-devflag \\" + echo " -p USER_NAME=jooho \\" + echo " -p TARGET_USER_NAME=test \\" + echo " -p COMPONENT_NAME=kserve \\" + echo " -p TARGET_BRANCH_NAME=pr_branch \\" + echo " -p CTRL_IMG_TAG=loopy \\" + echo " -p REGISTRY_URL=quay.io/jooholee" + echo "" + echo "2. PR source:" + echo " ./loopy roles run create-devflag \\" + echo " -p USER_NAME=jooho \\" + echo " -p PR_URL=https://github.com/opendatahub-io/kserve/pulls/684 \\" + echo " -p CTRL_IMG_TAG=loopy \\" + echo " -p REGISTRY_URL=quay.io/jooholee" + echo "" + echo "3. Local source:" + echo " ./loopy roles run create-devflag \\" + echo " -p USER_NAME=jooho \\" + echo " -p CTRL_IMG_TAG=loopy \\" + echo " -p REGISTRY_URL=quay.io/jooholee" + echo "" + echo "4. Custom image:" + echo " ./loopy roles run create-devflag \\" + echo " -p USER_NAME=jooho \\" + echo " -p COMPONENT_NAME=kserve \\" + echo " -p CUSTOM_IMAGE=quay.io/jooholee/kserve-controller:loopy \\" + echo " -p CTRL_IMG_TAG=loopy \\" + echo " -p REGISTRY_URL=quay.io/jooholee" + echo "" + + error "Exiting due to missing required environment variables." + return 1 + fi + + success "All required environment variables are set for use case '$use_case'" + + # Set derived variables based on use case + case $use_case in + "PR_SOURCE") + # Extract component name and PR details from PR_URL + if [[ $PR_URL =~ github\.com/([^/]+)/([^/]+)/pull/([0-9]+) ]]; then + PR_OWNER="${BASH_REMATCH[1]}" + COMPONENT_NAME="${BASH_REMATCH[2]}" + PR_NUMBER="${BASH_REMATCH[3]}" + info "Extracted from PR_URL: PR_OWNER=$PR_OWNER, COMPONENT_NAME=$COMPONENT_NAME, PR_NUMBER=$PR_NUMBER" + + # Get PR details using GitHub API + if command -v curl >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then + PR_INFO=$(curl -s "https://api.github.com/repos/${PR_OWNER}/${COMPONENT_NAME}/pulls/${PR_NUMBER}") + PR_USER_NAME=$(echo "$PR_INFO" | jq -r '.head.repo.owner.login') + PR_BRANCH_NAME=$(echo "$PR_INFO" | jq -r '.head.ref') + info "PR details: PR_USER_NAME=$PR_USER_NAME, PR_BRANCH_NAME=$PR_BRANCH_NAME" + else + error "curl and jq are required for PR source mode" + return 1 + fi + else + error "Invalid PR_URL format. Expected format: https://github.com/user/repo/pull/number" + return 1 + fi + ;; + "LOCAL_SOURCE") + # For local source, try to determine component name from current directory or default to kserve + if [[ -z "$COMPONENT_NAME" ]]; then + if [[ -f "Makefile" ]] && grep -q "kserve" Makefile; then + COMPONENT_NAME="kserve" + elif [[ -f "Makefile" ]] && grep -q "odh-model-controller" Makefile; then + COMPONENT_NAME="odh-model-controller" + else + error "COMPONENT_NAME not specified for local source. Please provide -p COMPONENT_NAME=kserve or -p COMPONENT_NAME=odh-model-controller" + return 1 + fi + fi + info "Using COMPONENT_NAME=$COMPONENT_NAME for local source" + ;; + "REMOTE_SOURCE") + info "Using remote source: TARGET_USER_NAME=$TARGET_USER_NAME, TARGET_BRANCH_NAME=$TARGET_BRANCH_NAME" + ;; + esac + + # Set common derived variables + export TAG=${CTRL_IMG_TAG} + export CONTAINER_CLI=${CONTAINER_CLI:-podman} + + return 0 +} \ No newline at end of file diff --git a/src/roles/kserve/tests/create-devflag/verify.sh b/src/roles/kserve/tests/create-devflag/verify.sh new file mode 100644 index 0000000..d7042c7 --- /dev/null +++ b/src/roles/kserve/tests/create-devflag/verify.sh @@ -0,0 +1,156 @@ +#!/usr/bin/env bash + +# Verification functions +verify_image_exists() { + local image_url=$1 + info "Verifying if image exists: $image_url" + + if ${CONTAINER_CLI} manifest inspect $image_url >/dev/null 2>&1; then + success "Image exists in registry: $image_url" + return 0 + else + error "Image does not exist in registry: $image_url" + return 1 + fi +} + +verify_image_sha_match() { + local image_url=$1 + info "Verifying image SHA match between local and remote" + + # Get remote image SHA + remote_sha=$(${CONTAINER_CLI} manifest inspect $image_url | jq -r '.config.digest' 2>/dev/null) + if [[ -z "$remote_sha" || "$remote_sha" == "null" ]]; then + error "Failed to get remote image SHA" + return 1 + fi + + # Get local image SHA + local_sha=$(${CONTAINER_CLI} inspect docker.io/library/${COMPONENT_NAME}-controller:latest | jq -r '.[0].Id' 2>/dev/null) + if [[ -z "$local_sha" || "$local_sha" == "null" ]]; then + error "Failed to get local image SHA" + return 1 + fi + + if [[ "$remote_sha" == "$local_sha" ]]; then + success "Image SHA matches between local and remote" + return 0 + else + error "Image SHA mismatch - Local: $local_sha, Remote: $remote_sha" + return 1 + fi +} + +verify_branch_pushed() { + local branch_name="${TEST_MANIFEST_BRANCH}" + local repo_dir=$1 + local user_name=$2 + local repo_name=$3 + + cd $repo_dir + + if git remote show ${user_name} >/dev/null 2>&1; then + info "Username remote found: ${user_name}" + else + info "Username remote not found, using origin" + user_name="origin" + fi + + info "Verifying if branch is pushed to remote: $branch_name" + + # Check if branch exists on remote + if git ls-remote --heads ${user_name} $branch_name | grep -q $branch_name; then + success "Branch $branch_name exists on remote repository" + git fetch --all + # Check if local and remote commits match + local_commit=$(git rev-parse HEAD) + remote_commit=$(git rev-parse ${user_name}/$branch_name) + + if [[ "$local_commit" == "$remote_commit" ]]; then + success "Local and remote commits match for branch $branch_name" + return 0 + else + error "Local and remote commits don't match for branch $branch_name" + return 1 + fi + else + error "Branch $branch_name not found on remote repository" + return 1 + fi +} + +verify_image_url_updated() { + local config_file="config/overlays/odh/params.env" + local expected_line="kserve-controller=${REGISTRY_URL}/kserve-controller:${CTRL_IMG_TAG}" + if [[ ${COMPONENT_NAME} == "kserve" ]]; then + if [[ -n "${CUSTOM_IMAGE}" ]]; then + expected_line="kserve-controller=${CUSTOM_IMAGE}" + fi + else + config_file="config/base/params.env" + expected_line="odh-model-controller=${REGISTRY_URL}/odh-model-controller:${CTRL_IMG_TAG}" + if [[ -n "${CUSTOM_IMAGE}" ]]; then + expected_line="odh-model-controller=${CUSTOM_IMAGE}" + fi + fi + pwd + info "Verifying if image URL is correctly updated in $config_file" + + if [[ -f "$config_file" ]]; then + if grep -q "$expected_line" "$config_file"; then + success "Image URL correctly updated in $config_file" + info " Expected: $expected_line" + return 0 + else + error "Image URL not found or incorrect in $config_file" + error " Expected: $expected_line" + error " Current content:" + grep "${COMPONENT_NAME}-controller=" "$config_file" || error " No controller line found" + return 1 + fi + else + error "Configuration file not found: $config_file" + return 1 + fi +} + +# Function to run all verifications +run_all_verifications() { + local target_image=$1 + local repo_dir=$2 + local result=0 + + info "Starting verification process..." + + # 1. Verify image exists in registry + if ! verify_image_exists "$target_image"; then + result=1 + fi + + # 2. Verify image SHA match (only if image exists and not using custom image) + if [[ $result -eq 0 && -z "${CUSTOM_IMAGE}" ]]; then + if ! verify_image_sha_match "$target_image"; then + result=1 + fi + fi + + # 3. Verify branch is pushed + if ! verify_branch_pushed "$repo_dir" "$USER_NAME" "$COMPONENT_NAME"; then + result=1 + exit 1 + fi + + # 4. Verify image URL is updated in config + if ! verify_image_url_updated; then + result=1 + fi + + # Final verification result + if [[ $result -eq 0 ]]; then + success "All verifications passed successfully!" + else + error "One or more verifications failed!" + fi + + return $result +} \ No newline at end of file diff --git a/src/roles/kserve-tests/e2e-test/config.yaml b/src/roles/kserve/tests/e2e-test/config.yaml similarity index 100% rename from src/roles/kserve-tests/e2e-test/config.yaml rename to src/roles/kserve/tests/e2e-test/config.yaml diff --git a/src/roles/kserve-tests/e2e-test/main.sh b/src/roles/kserve/tests/e2e-test/main.sh similarity index 99% rename from src/roles/kserve-tests/e2e-test/main.sh rename to src/roles/kserve/tests/e2e-test/main.sh index 712fa2d..6d58c4e 100644 --- a/src/roles/kserve-tests/e2e-test/main.sh +++ b/src/roles/kserve/tests/e2e-test/main.sh @@ -73,7 +73,6 @@ if [[ ${CLUSTER_ADMIN_ID} != "user" ]]; then fi # Run pytest -info "${PYTEST_MARKER}" if [[ ${PYTEST_MARKER} != "" ]]; then echo "uv run pytest --setup-show --tc=distribution:upstream $ROLE_DIR/opendatahub-tests/${PYTEST_PATH} -m \"${PYTEST_MARKER}\" -s" uv run pytest --setup-show --tc=distribution:upstream $ROLE_DIR/opendatahub-tests/${PYTEST_PATH} -m "${PYTEST_MARKER}" -s diff --git a/unofficial_components/playbooks/odh-test/kserve-e2e-test-with-existing-cluster/config.yaml b/unofficial_components/playbooks/odh-test/kserve-e2e-test-with-existing-cluster/config.yaml index 6328d31..412ff65 100644 --- a/unofficial_components/playbooks/odh-test/kserve-e2e-test-with-existing-cluster/config.yaml +++ b/unofficial_components/playbooks/odh-test/kserve-e2e-test-with-existing-cluster/config.yaml @@ -67,9 +67,9 @@ playbook: ./loopy playbook run kserve-e2e-test-with-existing-cluster ~~~ steps: - - role: - name: openshift-rosa-install - description: Install ROSA Openshift Cluster + # - role: + # name: openshift-rosa-install + # description: Install ROSA Openshift Cluster - unit: name: install-odh-stable-operator