Skip to content
Open
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
3 changes: 3 additions & 0 deletions tools/deployment/spider-helm/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
.idea/
.project
.vscode/
# Test set-up scripts
set-up-test.sh
.set-up-common.sh
123 changes: 123 additions & 0 deletions tools/deployment/spider-helm/.set-up-common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env bash

# Common utilities for Helm chart set-up scripts
# Source this file from set-up-*.sh scripts

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

# Cleans up existing cluster and prepares environment
#
# @param {string} cluster_name Name of the kind cluster
prepare_environment() {
local cluster_name=$1

echo "Deleting existing cluster if present..."
kind delete cluster --name "${cluster_name}" 2>/dev/null || true
}

# Loads a local Docker image into the kind cluster and returns the helm --set
# flags for using it. If image is not specified, returns empty string.
#
# @param {string} cluster_name Name of the kind cluster
# @param {string} component Image component name (e.g., "storage", "scheduler", "worker")
# @param {string} [image] Docker image (e.g., "spider-worker:dev")
# @return Prints helm --set flags to stdout
get_image_helm_args() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The function name should describe that it loads the images into kind cluster.

local cluster_name=$1
local component=$2
local image="${3:-}"

if [[ -z "${image}" ]]; then
return
fi

echo "Loading local image '${image}' into kind cluster..." >&2
kind load docker-image "${image}" --name "${cluster_name}" >&2

# Split "repo:tag" on the last colon whose right-hand side contains no '/'
# (so registry ports like localhost:5000/repo are not mistaken for tags).
if [[ "${image}" =~ ^(.+):([^:/]+)$ ]]; then
local repo="${BASH_REMATCH[1]}"
local tag="${BASH_REMATCH[2]}"
else
echo "Error: '${image}' is not a valid image reference (expected repo:tag)." >&2
return 1
fi
echo "--set" "image.${component}.repository=${repo}" \
"--set" "image.${component}.tag=${tag}" \
"--set" "image.${component}.pullPolicy=Never"
}

# Parses common arguments shared across set-up scripts.
# Sets STORAGE_IMAGE, SCHEDULER_IMAGE, and WORKER_IMAGE global variables.
#
# @param {string[]} args Script arguments
parse_common_args() {
STORAGE_IMAGE=""
SCHEDULER_IMAGE=""
WORKER_IMAGE=""
while [[ $# -gt 0 ]]; do
case "$1" in
--storage-image | --scheduler-image | --worker-image)
if [[ $# -lt 2 || "$2" == --* ]]; then
echo "Error: '$1' requires a value." >&2
exit 1
fi
case "$1" in
--storage-image) STORAGE_IMAGE="$2" ;;
--scheduler-image) SCHEDULER_IMAGE="$2" ;;
--worker-image) WORKER_IMAGE="$2" ;;
esac
shift 2
;;
*)
echo "Unknown argument: $1" >&2
exit 1
;;
esac
done
}

# Waits for all pods to be ready.
#
# NOTE: The Spider services fail fast when their dependencies (e.g., the database) are unreachable,
# so pods may go through a few restarts before the whole deployment converges.
#
# @param {int} timeout_seconds Overall timeout in seconds
# @param {int} poll_interval_seconds Interval between status checks
# @param {int} wait_timeout_seconds Timeout for each kubectl wait call
# @return {int} 0 on success, 1 on timeout
wait_for_pods() {
local timeout_seconds=$1
local poll_interval_seconds=$2
local wait_timeout_seconds=$3

echo "Waiting for all pods to be ready" \
"(timeout=${timeout_seconds}s, poll=${poll_interval_seconds}s," \
"wait=${wait_timeout_seconds}s)..."

# Reset bash built-in SECONDS counter
SECONDS=0

while true; do
sleep "${poll_interval_seconds}"
kubectl get pods

if kubectl wait pods \
--all \
--for=condition=Ready \
--timeout="${wait_timeout_seconds}s" 2>/dev/null; then
echo "All pods are ready."
return 0
fi

if [[ ${SECONDS} -ge ${timeout_seconds} ]]; then
echo "ERROR: Timed out waiting for pods to be ready"
return 1
fi

echo "---"
done
}
2 changes: 1 addition & 1 deletion tools/deployment/spider-helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: "v2"
name: "spider"
description: "A Helm chart for the Spider Huntsman deployment"
type: "application"
version: "0.1.5"
version: "0.1.6"
appVersion: "0.1.0"
home: "https://github.com/y-scope/spider"
sources: ["https://github.com/y-scope/spider"]
Expand Down
33 changes: 33 additions & 0 deletions tools/deployment/spider-helm/set-up-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

# Single-node kind cluster set-up for testing the Helm chart
# TODO: Submit a job through the deployed stack once an end-to-end test scenario is available.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we start the client submitting the job in the bash script? More generally, how much of work should we put in bash script, and how much should we put in taskfiles?


script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

CLUSTER_NAME="${CLUSTER_NAME:-spider-test}"
RELEASE_NAME="${RELEASE_NAME:-test}"

# shellcheck source=.set-up-common.sh
source "${script_dir}/.set-up-common.sh"

parse_common_args "$@"

echo "=== Single-node setup ==="
echo "Cluster: ${CLUSTER_NAME}"
echo ""

prepare_environment "${CLUSTER_NAME}"

echo "Creating kind cluster..."
kind create cluster --name "${CLUSTER_NAME}"

echo "Installing Helm chart..."
# Word splitting is intentional: get_image_helm_args returns multiple --set flags.
# shellcheck disable=SC2046
helm install "${RELEASE_NAME}" "${script_dir}" \
$(get_image_helm_args "${CLUSTER_NAME}" "storage" "${STORAGE_IMAGE}") \
$(get_image_helm_args "${CLUSTER_NAME}" "scheduler" "${SCHEDULER_IMAGE}") \
$(get_image_helm_args "${CLUSTER_NAME}" "worker" "${WORKER_IMAGE}")
Comment on lines +28 to +31

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
fd -a '(\.set-up-common\.sh|set-up-test\.sh)$' . | sed 's#^\./##'

echo "== target files line counts =="
wc -l tools/deployment/spider-helm/.set-up-common.sh tools/deployment/spider-helm/set-up-test.sh

echo "== relevant target files =="
cat -n tools/deployment/spider-helm/.set-up-common.sh
printf '\n--- set-up-test.sh ---\n'
cat -n tools/deployment/spider-helm/set-up-test.sh

echo "== helpers references =="
rg -n "get_image_helm_args|load docker-image|kind load|helm install|set -|set -e|get_image" tools/deployment/spider-helm/.set-up-common.sh tools/deployment/spider-helm/set-up-test.sh

Repository: y-scope/spider

Length of output: 7540


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== bash command-substitution exit-status probe =="
bash -c 'set -o errexit; set -o pipefail; f() { echo x >/dev/null; false >&2; echo y; }; echo "start"; x=$(f); echo "x=$x"; echo "outdone" || echo "cmd exited non-zero; final status=$?"'

echo "== check bash availability and version =="
command -v bash
bash --version | head -n1

Repository: y-scope/spider

Length of output: 338


Separate checked image loading from Helm argument generation. A failed kind load docker-image inside command substitution is not a script error and will not stop the surrounding helm install from running.

  • Move the image-load step into a checked preflight before helm install.
  • Keep get_image_helm_args() limited to emitting the Helm --set flags.
📍 Affects 2 files
  • tools/deployment/spider-helm/set-up-test.sh#L28-L31 (this comment)
  • tools/deployment/spider-helm/.set-up-common.sh#L36-L37
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tools/deployment/spider-helm/set-up-test.sh` around lines 28 - 31, The image
loading currently occurs inside get_image_helm_args command substitutions,
allowing failures to be ignored before helm install. In
tools/deployment/spider-helm/.set-up-common.sh lines 36-37, keep
get_image_helm_args limited to emitting Helm --set flags; in
tools/deployment/spider-helm/set-up-test.sh lines 28-31, add a checked
image-loading preflight before helm install and abort if any kind load
docker-image operation fails.


wait_for_pods 300 5 5
Loading