Skip to content

Commit

Permalink
Add system tests (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
nstogner committed Aug 22, 2023
1 parent 876a0cf commit fcdd6f9
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main
tags:
- "v*.*.*"
pull_request:
merge_group:
jobs:
controller:
runs-on: ubuntu-latest
Expand All @@ -18,7 +18,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
if: github.event_name != 'merge_group'
uses: docker/login-action@v2
with:
username: "${{ secrets.DOCKERHUB_USERNAME }}"
Expand All @@ -34,7 +34,7 @@ jobs:
with:
context: .
platforms: "linux/amd64,linux/arm64"
push: ${{ github.event_name != 'pull_request' }}
push: ${{ github.event_name != 'merge_group' }}
tags: ${{ steps.meta-controller-manager.outputs.tags }}
labels: ${{ steps.meta-controller-manager.outputs.labels }}
installer:
Expand All @@ -47,7 +47,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
if: github.event_name != 'merge_group'
uses: docker/login-action@v2
with:
username: "${{ secrets.DOCKERHUB_USERNAME }}"
Expand All @@ -63,7 +63,7 @@ jobs:
with:
context: install/
platforms: "linux/amd64,linux/arm64"
push: ${{ github.event_name != 'pull_request' }}
push: ${{ github.event_name != 'merge_group' }}
tags: ${{ steps.meta-installer.outputs.tags }}
labels: ${{ steps.meta-installer.outputs.labels }}
sci-gcp:
Expand All @@ -76,7 +76,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
if: github.event_name != 'merge_group'
uses: docker/login-action@v2
with:
username: "${{ secrets.DOCKERHUB_USERNAME }}"
Expand All @@ -93,7 +93,7 @@ jobs:
context: .
file: Dockerfile.sci-gcp
platforms: "linux/amd64,linux/arm64"
push: ${{ github.event_name != 'pull_request' }}
push: ${{ github.event_name != 'merge_group' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
sci-kind:
Expand All @@ -106,7 +106,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
if: github.event_name != 'merge_group'
uses: docker/login-action@v2
with:
username: "${{ secrets.DOCKERHUB_USERNAME }}"
Expand All @@ -123,6 +123,6 @@ jobs:
context: .
file: Dockerfile.sci-kind
platforms: "linux/amd64,linux/arm64"
push: ${{ github.event_name != 'pull_request' }}
push: ${{ github.event_name != 'merge_group' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: Integration tests
run-name: ${{ github.actor }} triggered integration tests 🚀
on: [pull_request]
on:
pull_request:
merge_group:
jobs:
unit-tests:
integration-tests:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- run: make test
- run: make test-integration
20 changes: 20 additions & 0 deletions .github/workflows/system-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: System tests
run-name: ${{ github.actor }} triggered integration tests 🚀
on:
push:
branches:
# Must run after docker images are built and pushed.
# Should run before a release.
- main
workflow_run:
workflows: [Run Tests]
types:
- completed
jobs:
system-tests:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Check out repository code
uses: actions/checkout@v3
- run: make test-system
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

.PHONY: test
test: manifests generate protogen fmt vet envtest ## Run tests.
.PHONY: test-system
test-system:
./test/system.sh kind

.PHONY: test-integration
test-integration: manifests generate protogen fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -v -coverprofile cover.out

.PHONY: test-kubectl
Expand Down Expand Up @@ -286,7 +290,7 @@ installation-scripts:
installation-manifests: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/sci-kind && $(KUSTOMIZE) edit set image sci=${IMG_SCI_KIND}
$(KUSTOMIZE) build config/install-kind > install/kind/manifests/system.yaml
$(KUSTOMIZE) build config/install-kind > install/kind/manifests.yaml
cd config/sci-gcp && $(KUSTOMIZE) edit set image sci=${IMG_SCI_GCP}
$(KUSTOMIZE) build config/install-gcp > install/kubernetes/gcp/system.yaml

Expand Down
File renamed without changes.
16 changes: 12 additions & 4 deletions internal/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@ package resources
import (
"fmt"

apiv1 "github.com/substratusai/substratus/api/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

apiv1 "github.com/substratusai/substratus/api/v1"
)

func Apply(podMetadata *metav1.ObjectMeta, podSpec *corev1.PodSpec, containerName string, cloudName string, res *apiv1.Resources) error {
// TODO: Auto-determine resources if nil.
if res == nil {
res = &apiv1.Resources{
CPU: 2,
Memory: 4,
// TODO(nstogner): Cloud-specific conditional should go away...
// Most likely this stuff will all go into a ConfigMap that contains cloud-specific
// information.
if cloudName == "kind" {
res = &apiv1.Resources{}
} else {
res = &apiv1.Resources{
CPU: 2,
Memory: 4,
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# System Tests

System tests create a cluster, install Substratus (using pushed container images), and runs kubectl commands to test the system as a whole from the outside.

7 changes: 7 additions & 0 deletions test/install/kind/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resources:
- ../../../config/install-kind/
images:
- name: docker.io/substratusai/sci-kind
newTag: main
- name: docker.io/substratusai/controller-manager
newTag: main
73 changes: 73 additions & 0 deletions test/system.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

set -e
set -x

cloud=$1
repo=$(git rev-parse --show-toplevel)
example="facebook-opt-125m"

if [[ -z "$cloud" ]]; then
echo "Must provide <cloud> arg"
exit 1
fi

echo "Running test for cloud: $cloud"

function down {
if [ "${DOWN}" == "no" ]; then
echo "Skipping DOWN..."
else
echo "Running DOWN..."
./install/${cloud}/down.sh
fi
}
trap down EXIT

if [ "${UP}" == "no" ]; then
echo "Skipping UP..."
else
./install/${cloud}/up.sh
fi

kubectl get events -A -w &

# Install Substratus
kubectl apply -k ${repo}/test/install/${cloud}

# Import a Model
kubectl apply -f ${repo}/examples/${example}/base-model.yaml

# Serve the Model
kubectl apply -f ${repo}/examples/${example}/base-server.yaml

# Wait until both are ready
# TODO: Consider adding common "Ready" condition to make this check easier.
kubectl wait --for=condition=modelled models --all --timeout 720s
kubectl wait --for=condition=deployed servers --all --timeout 720s

# Forward ports to localhost
kubectl port-forward service/$example-server 8080:8080 &
port_forward_pid=$!

function stop_port_forward {
kill $port_forward_pid
# Allow for the port-forward to stop
sleep 1
# Trap will only call 1 function, so we must call the previous trap function
down
}
trap stop_port_forward EXIT

# Wait for port-forward to be ready (client-side)
sleep 3

# Send example request
curl http://localhost:8080/v1/completions \
-H "Content-Type: application/json" \
-d '{ \
"prompt": "What is your favorite color? ", \
"max_tokens": 3\
}'

kill $port_forward_pid

0 comments on commit fcdd6f9

Please sign in to comment.