Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/e2e-cluster-lifecycle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
206 changes: 206 additions & 0 deletions src/roles/kserve/tests/create-devflag/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
#!/usr/bin/env bash
## INIT START ##
if [[ $DEBUG == "0" ]]; then
set -x
fi
Comment on lines +3 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

DEBUG flag logic looks inverted and unquoted – trace will be enabled when DEBUG is “0”
set -x is usually activated when a truthy / non-zero DEBUG is supplied. As written, the script goes verbose for the “off” value and is silent otherwise. Additionally the variable is unquoted.

-if [[ $DEBUG == "0" ]]; then
-  set -x
-fi
+if [[ "${DEBUG}" == "1" ]]; then   # enable tracing only when explicitly requested
+  set -x
+fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ $DEBUG == "0" ]]; then
set -x
fi
if [[ "${DEBUG}" == "1" ]]; then # enable tracing only when explicitly requested
set -x
fi
🤖 Prompt for AI Agents
In src/roles/kserve/tests/create-devflag/build.sh around lines 3 to 5, the DEBUG
flag logic is inverted and the variable is unquoted. To fix this, change the
condition to enable set -x when DEBUG is not "0" (i.e., when DEBUG is truthy),
and quote the variable in the test to prevent word splitting or errors. This
means using a condition like 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 ##
Comment on lines +17 to +23
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Script continues after root-repo discovery failure – will dereference an uninitialised variable
If the .git folder isn’t found, root_directory stays unset, yet the script still executes source $root_directory/..., leading to “No such file or directory”. Bail out early and quote the variable when sourcing:

-else
-  echo "Error: Unable to find .github folder."
-fi
-source $root_directory/src/commons/scripts/utils.sh
+else
+  echo "Error: Unable to find .git folder. Aborting."
+  exit 1
+fi
+source "${root_directory}/src/commons/scripts/utils.sh"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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 ##
if [ -d "$github_dir/.git" ]; then
root_directory="$github_dir"
else
echo "Error: Unable to find .git folder. Aborting."
exit 1
fi
source "${root_directory}/src/commons/scripts/utils.sh"
## INIT END ##
🤖 Prompt for AI Agents
In src/roles/kserve/tests/create-devflag/build.sh around lines 17 to 23, the
script continues after failing to find the .git folder, causing root_directory
to be unset and leading to an error when sourcing utils.sh. Fix this by adding
an exit command immediately after the error message to stop the script, and
quote the root_directory variable in the source command to handle any spaces
safely.


# 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
Comment on lines +72 to +76
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

cd commands are unchecked – script may operate in an unexpected directory
ShellCheck SC2164 flags these instances. Add || exit 1 (or || return 1 inside functions) to fail fast when the target directory is missing:

-cd "$target_parent_directory"
+cd "$target_parent_directory" || return 1
...
-cd ${COMPONENT_NAME}
+cd "${COMPONENT_NAME}" || return 1
...
-cd "$target_parent_directory/${COMPONENT_NAME}"
+cd "$target_parent_directory/${COMPONENT_NAME}" || return 1

Also applies to: 86-87, 183-184

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 73-73: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

🤖 Prompt for AI Agents
In src/roles/kserve/tests/create-devflag/build.sh around lines 72 to 76, the cd
commands lack error checking, which can cause the script to continue running in
the wrong directory if the cd fails. To fix this, append || exit 1 to each cd
command outside functions to ensure the script exits immediately if changing
directories fails. Apply the same fix to the cd commands at lines 86-87 and
183-184.

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"
}
101 changes: 101 additions & 0 deletions src/roles/kserve/tests/create-devflag/config.yaml
Original file line number Diff line number Diff line change
@@ -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")
Loading
Loading