Skip to content

Commit

Permalink
K8s integration test for HotROD (#6155)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- Resolves #6086 

## Description of the changes
- 

## How was this change tested?
- 

## Checklist
- [ ] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [ ] I have signed all commits
- [ ] I have added unit tests for the new functionality
- [ ] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: chahatsagarmain <[email protected]>
Signed-off-by: chahat sagar <[email protected]>
Co-authored-by: Yuri Shkuro <[email protected]>
  • Loading branch information
chahatsagarmain and yurishkuro authored Nov 17, 2024
1 parent f88262c commit 5475a36
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 14 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/ci-docker-hotrod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
runtime: [docker, k8s]
jaeger-version: [v1, v2]

steps:
Expand Down Expand Up @@ -56,9 +57,22 @@ jobs:
echo "BUILD_FLAGS=" >> ${GITHUB_ENV}
;;
esac
- name: Install kubectl
if: matrix.runtime == 'k8s'
uses: azure/setup-kubectl@v3
with:
version: 'latest'

- name: Install Kustomize
if: matrix.runtime == 'k8s'
uses: imranismail/setup-kustomize@v2

- name: Create k8s Kind Cluster
if: matrix.runtime == 'k8s'
uses: helm/kind-action@v1

- name: Build, test, and publish hotrod image
run: bash scripts/build-hotrod-image.sh ${{ env.BUILD_FLAGS }} -v ${{ matrix.jaeger-version }}
run: bash scripts/build-hotrod-image.sh ${{ env.BUILD_FLAGS }} -v ${{ matrix.jaeger-version }} -r ${{ matrix.runtime }}
env:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
68 changes: 55 additions & 13 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
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 All @@ -62,18 +70,37 @@ esac
set -x

dump_logs() {
local compose_file=$1
echo "::group:: Hotrod logs"
docker compose -f "${compose_file}" logs
local runtime=$1
local compose_file=$2

echo "::group:: Logs"
if [ "$runtime" == "k8s" ]; then
kubectl logs -n example-hotrod -l app=example-hotrod
kubectl logs -n example-hotrod -l app=jaeger
else
docker compose -f "$compose_file" logs
fi
echo "::endgroup::"
}

teardown() {
echo "Tearing down..."
echo "::group::Tearing down..."
if [[ "$success" == "false" ]]; then
dump_logs "${docker_compose_file}"
dump_logs "${runtime}" "${docker_compose_file}"
fi
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
else
docker compose -f "$docker_compose_file" down
fi
docker compose -f "$docker_compose_file" down

echo "::endgroup::"
}
trap teardown EXIT

Expand All @@ -98,12 +125,27 @@ 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 \
HOTROD_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

echo '::group:: run on Kubernetes'
kustomize build ./examples/hotrod/kubernetes | kubectl apply -n example-hotrod -f -
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=$!
echo '::endgroup::'

else
echo '::group:: docker compose'
JAEGER_VERSION=$GITHUB_SHA HOTROD_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

0 comments on commit 5475a36

Please sign in to comment.