Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests that ensure quickstart works #167

Merged
merged 10 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
22 changes: 22 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,25 @@ jobs:

- name: Run unit tests
run: make test
e2e-quickstart:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.24.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
- name: Install helm
run: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
- name: Install skaffold
run: |
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64
chmod +x skaffold
sudo mv skaffold /usr/local/bin
- name: Run the quickstart tests
run: test/quickstart.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ go.work

# Files that might be committed from running guides
/helm-values.yaml
Chart.lock

# Ignore python virtual env
.venv
Expand Down
24 changes: 24 additions & 0 deletions skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: skaffold/v2beta21
kind: Config
metadata:
name: kubeai-project
build:
artifacts:
- image: substratusai/kubeai
local:
push: false
deploy:
helm:
releases:
- name: kubeai
chartPath: charts/kubeai
valuesFiles:
- charts/kubeai/values.yaml
setValueTemplates:
image.tag: "{{.DIGEST_HEX}}"
portForward:
- resourceType: service
resourceName: kubeai
namespace: default
port: 80
localPort: 8000
73 changes: 73 additions & 0 deletions test/quickstart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash

set -xe

KIND_CLUSTER_NAME=${KIND_CLUSTER_NAME:-kubeai-tests}

if kind get clusters | grep -q ${KIND_CLUSTER_NAME}; then
echo "Cluster ${KIND_CLUSTER_NAME} already exists.. reusing it"
else
kind create cluster --name ${KIND_CLUSTER_NAME}
fi

# Capture PID and run skaffold devin background
skaffold run --tail --port-forward &
nstogner marked this conversation as resolved.
Show resolved Hide resolved
skaffold_pid=$!

error_handler() {
local exit_status=$? # Capture the exit status of the last command
if [ $exit_status -ne 0 ]; then
echo "An error occurred. Exiting with status $exit_status. Leaving kind cluster intact for debugging"
elif [ "$TEST_CLEANUP" != "false" ]; then
echo "Exiting normally. Deleting kind cluster"
kind delete cluster --name=${KIND_CLUSTER_NAME}
fi
# Send exit signal to skaffold and wait for it to exit
kill "$skaffold_pid"
wait "$skaffold_pid"
}

trap 'error_handler' ERR EXIT

function wait_for_pod_ready() {
local label="$1"
local start_time=$SECONDS

while ! kubectl get pod -l "$label" | grep -q Running; do
sleep 5
if (( SECONDS - start_time >= 300 )); then
echo "Pods with label $label did not start in time."
exit 1
fi
done

kubectl wait --for=condition=ready pod -l "$label" --timeout=1200s
}

# wait for kubeai pod to be ready
wait_for_pod_ready app.kubernetes.io/name=kubeai

# Ensure the model count is 0
curl -s -X GET "http://localhost:8000/openai/v1/models" | jq '. | length == 0'


Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# The previous skaffold step installed KubeAI using the helm chart.
# By using the --reuse-values flag we can just append models to the previous install
# while avoiding overriding the image that skaffold originally built and set in the first
# install.

helm upgrade --reuse-values --install kubeai charts/kubeai -f - <<EOF
nstogner marked this conversation as resolved.
Show resolved Hide resolved
models:
catalog:
gemma2-2b-cpu:
enabled: true
minReplicas: 1
qwen2-500m-cpu:
enabled: true
nomic-embed-text-cpu:
enabled: true
EOF

wait_for_pod_ready model=gemma2-2b-cpu

curl -s -X GET "http://localhost:8000/openai/v1/models" | jq '. | length == 3'

curl http://localhost:8000/openai/v1/completions \
-H "Content-Type: application/json" \
-d '{"model": "gemma2-2b-cpu", "prompt": "Who was the first president of the United States?", "max_tokens": 40}'

Loading