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

K8s integration test for hotrod #6155

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions .github/workflows/ci-docker-hotrod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ jobs:
echo "BUILD_FLAGS=" >> ${GITHUB_ENV}
;;
esac
- name: Install kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'

- name: Install Kustomize
uses: imranismail/setup-kustomize@v2

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
chahatsagarmain marked this conversation as resolved.
Show resolved Hide resolved

- name: Build, test, and publish hotrod image
run: bash scripts/build-hotrod-image.sh ${{ env.BUILD_FLAGS }} -v ${{ matrix.jaeger-version }}
chahatsagarmain marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
49 changes: 42 additions & 7 deletions scripts/build-hotrod-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ print_help() {
echo "-o: overwrite image in the target remote repository even if the semver tag already exists"
echo "-p: Comma-separated list of platforms to build for (default: all supported)"
echo "-v: Jaeger version to use for hotrod image (v1 or v2, default: v1)"
echo "-r: Runtime to test with (docker|k8s, default: docker)"
exit 1
}

Expand All @@ -22,8 +23,9 @@ jaeger_version="v1"
binary="all-in-one"
FLAGS=()
success="false"
runtime="docker"

while getopts "hlop:v:" opt; do
while getopts "hlop:v:r" opt; do
chahatsagarmain marked this conversation as resolved.
Show resolved Hide resolved
case "${opt}" in
l)
# in the local-only mode the images will only be pushed to local registry
Expand All @@ -38,6 +40,12 @@ while getopts "hlop:v:" opt; do
v)
jaeger_version=${OPTARG}
;;
r)
case "${OPTARG}" in
docker|k8s) runtime="${OPTARG}" ;;
*) echo "Invalid runtime: ${OPTARG}. Use 'docker' or 'k8s'" >&2; exit 1 ;;
esac
;;
*)
print_help
;;
Expand Down Expand Up @@ -70,10 +78,20 @@ dump_logs() {

teardown() {
echo "Tearing down..."
if [[ "$success" == "false" ]]; then
dump_logs "${docker_compose_file}"
if [[ "${runtime}" == "k8s" ]]; then
if [[ -n "${HOTROD_PORT_FWD_PID:-}" ]]; then
kill "$HOTROD_PORT_FWD_PID" || true
fi
if [[ -n "${JAEGER_PORT_FWD_PID:-}" ]]; then
kill "$JAEGER_PORT_FWD_PID" || true
fi
kubectl delete namespace example-hotrod --ignore-not-found=true
chahatsagarmain marked this conversation as resolved.
Show resolved Hide resolved
else
if [[ "$success" == "false" ]]; then
dump_logs "${docker_compose_file}"
fi
docker compose -f "$docker_compose_file" down
chahatsagarmain marked this conversation as resolved.
Show resolved Hide resolved
fi
docker compose -f "$docker_compose_file" down
}
trap teardown EXIT

Expand All @@ -98,9 +116,26 @@ bash scripts/build-upload-a-docker-image.sh -l -c example-hotrod -d examples/hot
make build-${binary}
bash scripts/build-upload-a-docker-image.sh -l -b -c "${binary}" -d cmd/"${binary}" -p "${current_platform}" -t release

echo '::group:: docker compose'
JAEGER_VERSION=$GITHUB_SHA REGISTRY="localhost:5000/" docker compose -f "$docker_compose_file" up -d
echo '::endgroup::'
if [[ "${runtime}" == "k8s" ]]; then
if ! kubectl cluster-info >/dev/null 2>&1; then
echo "Error: Cannot connect to Kubernetes cluster"
exit 1
fi

kustomize build ./examples/hotrod/kubernetes | kubectl apply -n example-hotrod -f -
chahatsagarmain marked this conversation as resolved.
Show resolved Hide resolved
kubectl wait --for=condition=available --timeout=180s -n example-hotrod deployment/example-hotrod

kubectl port-forward -n example-hotrod service/example-hotrod 8080:frontend &
HOTROD_PORT_FWD_PID=$!
kubectl port-forward -n example-hotrod service/jaeger 16686:frontend &
JAEGER_PORT_FWD_PID=$!
chahatsagarmain marked this conversation as resolved.
Show resolved Hide resolved

sleep 5
chahatsagarmain marked this conversation as resolved.
Show resolved Hide resolved
else
echo '::group:: docker compose'
JAEGER_VERSION=$GITHUB_SHA REGISTRY="localhost:5000/" docker compose -f "$docker_compose_file" up -d
echo '::endgroup::'
fi

i=0
while [[ "$(curl -s -o /dev/null -w '%{http_code}' localhost:8080)" != "200" && $i -lt 30 ]]; do
Expand Down
Loading