Skip to content

Commit

Permalink
Add functional tests for lightweight informer (#60)
Browse files Browse the repository at this point in the history
* Functional tests

* Update .travis.yml

* Pass image tag

* Update resourceBudgetTest.sh

* Delete kind-hub.config.yaml

* Update resourceBudgetTest.sh

* Update resourceBudgetTest.sh

* Test failure path

* Fix test

* Update .travis.yml

* Fix in travis

* Try different path

* try to resolve permission denied

* Update resourceBudgetTest.sh

* Update resourceBudgetTest.sh

* Update resourceBudgetTest.sh

* Update resourceBudgetTest.sh

* Update resourceBudgetTest.sh

* Update resourceBudgetTest.sh

* cleanup

* Test fail path

* Update resourceBudgetTest.sh

* finalize

* Update resourceBudgetTest.sh

* Update resourceBudgetTest.sh

Co-authored-by: Disaiah Bennett <lavontae.bennett@gmail.com>
  • Loading branch information
jlpadilla and dislbenn authored Sep 10, 2020
1 parent 60aab55 commit b4da2ad
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 6 deletions.
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ jobs:
- make sonar/go
- make security/scans

# - stage: test-e2e
# name: "Run e2e tests"
# if: type = pull_request
# script:
# # Run e2e tests.
# - make component/test/e2e
- stage: test-e2e
name: "Run e2e tests"
if: type = pull_request
script:
# Run e2e tests.
- make component/pull
- make component/test/e2e

- stage: release-ff
name: "Push commits to current release branch"
Expand Down
3 changes: 3 additions & 0 deletions build/run-e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

echo " > Running run-e2e-test.sh"
set -e
sh tests/e2e/runTests.sh $1

exit 0
14 changes: 14 additions & 0 deletions tests/e2e/kind/kind-collector-test.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 80
listenAddress: "0.0.0.0"
- containerPort: 443
hostPort: 443
listenAddress: "0.0.0.0"
- containerPort: 6443
hostPort: 32806
listenAddress: "0.0.0.0"
92 changes: 92 additions & 0 deletions tests/e2e/resourceBudgetTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

# Copyright (c) 2020 Red Hat, Inc.

echo "=== TEST: Memory and CPU budget ===\n"

CPU_BUDGET=1.00
MEM_BUDGET=15.00
if [ $1 ]; then
SEARCH_COLLECTOR_IMAGE=$1
else
SEARCH_COLLECTOR_IMAGE="search-collector"
fi
KUBECONFIG_PATH=${PWD}/.kubeconfig-kind


create_kind_cluster() {
WORKDIR=`pwd`
if [ ! -f /usr/local/bin/kind ]; then
echo "Installing kind from (https://kind.sigs.k8s.io/)."

# uname returns your operating system name
# uname -- Print operating system name
# -L location, lowercase -o specify output name, uppercase -O Write output to a local file named like the remote file we get
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.7.0/kind-$(uname)-amd64"
chmod +x ./kind
sudo cp ./kind /usr/local/bin/kind
fi
# Delete kind cluster collector-test if it exists
kind delete cluster --name collector-test --quiet || true

echo "Starting kind cluster: collector-test"
rm -rf $KUBECONFIG_PATH
kind create cluster \
--kubeconfig $KUBECONFIG_PATH \
--name collector-test \
--config ${WORKDIR}/tests/e2e/kind/kind-collector-test.config.yaml \
--quiet
chmod +r $KUBECONFIG_PATH
}

run_container() {
docker run \
-e CLUSTER_NAME="local-cluster" \
-e DEPLOYED_IN_HUB="true" \
-e KUBECONFIG=".kubeconfig" \
-e KUBERNETES_SERVICE_HOST="https://127.0.0.1" \
-e KUBERNETES_SERVICE_PORT="63481" \
-v $PWD/sslcert:/sslcert \
-v $KUBECONFIG_PATH:/.kubeconfig \
--network="host" \
--name search-collector \
${SEARCH_COLLECTOR_IMAGE} &

echo "Waiting 90s for search-collector container to start."
sleep 90
OUTPUT=$(docker stats --no-stream --format "{{.MemUsage}} : {{.CPUPerc}}" search-collector)
MEM=$(echo $OUTPUT | awk '{print $1}' | sed 's/[^0-9\.]*//g')
CPU=$(echo $OUTPUT | awk '{print $5}' | sed 's/[^0-9\.]*//g')

echo "Stopping and removing search-collector container."
docker stop search-collector
docker rm search-collector
rm -rf $KUBECONFIG_PATH
kind delete cluster --name collector-test --quiet
}

verify_mem_cpu() {
MEM_TEST=$(awk 'BEGIN {print ('$MEM' >= '$MEM_BUDGET')}')
CPU_TEST=$(awk 'BEGIN {print ('$CPU' >= '$CPU_BUDGET')}')

if [ "$MEM_TEST" -eq 1 ]; then
echo "MEMORY budget exceeded."
echo "\tUsed: $MEM"
echo "\tBudget: $MEM_BUDGET"
fi
if [ "$CPU_TEST" -eq 1 ]; then
echo "CPU budget exceeded."
echo "\tUsed: $CPU"
echo "\tBudget: $CPU_BUDGET"
fi
if [ "$MEM_TEST" -eq 1 ] || [ "$CPU_TEST" -eq 1 ]; then
echo "TEST FAILED."
exit 1
fi
}

create_kind_cluster
run_container
verify_mem_cpu

echo "\nTEST PASSED."
5 changes: 5 additions & 0 deletions tests/e2e/runTests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# Copyright (c) 2020 Red Hat, Inc.

sh tests/e2e/resourceBudgetTest.sh $1

0 comments on commit b4da2ad

Please sign in to comment.