mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
metrics: stops kata components and k8s deployment when test finishes
This PR adds a trap whenever the scrip exits, it deletes the iperf k8s deployment and k8s services, and deletes the kata components. This way, when the script finishes, it verifies that there are indeed no kata components still running. Fixes: #8126 Signed-off-by: David Esparza <david.esparza.borquez@intel.com>
This commit is contained in:
parent
1280f85343
commit
bba34910df
@ -26,6 +26,8 @@ source "${SCRIPT_PATH}/../../lib/common.bash"
|
|||||||
iperf_file=$(mktemp iperfresults.XXXXXXXXXX)
|
iperf_file=$(mktemp iperfresults.XXXXXXXXXX)
|
||||||
TEST_NAME="${TEST_NAME:-network-iperf3}"
|
TEST_NAME="${TEST_NAME:-network-iperf3}"
|
||||||
COLLECT_ALL="${COLLECT_ALL:-false}"
|
COLLECT_ALL="${COLLECT_ALL:-false}"
|
||||||
|
IPERF_DEPLOYMENT="${SCRIPT_PATH}/runtimeclass_workloads/iperf3-deployment.yaml"
|
||||||
|
IPERF_DAEMONSET="${SCRIPT_PATH}/runtimeclass_workloads/iperf3-daemonset.yaml"
|
||||||
|
|
||||||
function remove_tmp_file() {
|
function remove_tmp_file() {
|
||||||
rm -rf "${iperf_file}"
|
rm -rf "${iperf_file}"
|
||||||
@ -177,56 +179,55 @@ function iperf3_start_deployment() {
|
|||||||
cmds=("bc" "jq")
|
cmds=("bc" "jq")
|
||||||
check_cmds "${cmds[@]}"
|
check_cmds "${cmds[@]}"
|
||||||
|
|
||||||
init_env
|
|
||||||
|
|
||||||
# Check no processes are left behind
|
# Check no processes are left behind
|
||||||
check_processes
|
check_processes
|
||||||
|
|
||||||
export service="iperf3-server"
|
|
||||||
export deployment="iperf3-server-deployment"
|
|
||||||
|
|
||||||
wait_time=20
|
wait_time=20
|
||||||
sleep_time=2
|
sleep_time=2
|
||||||
|
|
||||||
# Create deployment
|
# Create deployment
|
||||||
kubectl create -f "${SCRIPT_PATH}/runtimeclass_workloads/iperf3-deployment.yaml"
|
kubectl create -f "${IPERF_DEPLOYMENT}"
|
||||||
|
|
||||||
# Check deployment creation
|
# Check deployment creation
|
||||||
local cmd="kubectl wait --for=condition=Available deployment/${deployment}"
|
local cmd="kubectl wait --for=condition=Available deployment/iperf3-server-deployment"
|
||||||
waitForProcess "$wait_time" "$sleep_time" "$cmd"
|
waitForProcess "${wait_time}" "${sleep_time}" "${cmd}"
|
||||||
|
|
||||||
# Create DaemonSet
|
# Create DaemonSet
|
||||||
kubectl create -f "${SCRIPT_PATH}/runtimeclass_workloads/iperf3-daemonset.yaml"
|
kubectl create -f "${IPERF_DAEMONSET}"
|
||||||
|
|
||||||
# Expose deployment
|
|
||||||
kubectl expose deployment/"${deployment}"
|
|
||||||
|
|
||||||
# Get the names of the server pod
|
# Get the names of the server pod
|
||||||
export server_pod_name=$(kubectl get pods -o name | grep server | cut -d '/' -f2)
|
export server_pod_name=$(kubectl get pods -o name | grep server | cut -d '/' -f2)
|
||||||
|
|
||||||
# Verify the server pod is working
|
# Verify the server pod is working
|
||||||
local cmd="kubectl get pod $server_pod_name -o yaml | grep 'phase: Running'"
|
local cmd="kubectl get pod ${server_pod_name} -o yaml | grep 'phase: Running'"
|
||||||
waitForProcess "$wait_time" "$sleep_time" "$cmd"
|
waitForProcess "${wait_time}" "${sleep_time}" "${cmd}"
|
||||||
|
|
||||||
# Get the names of client pod
|
# Get the names of client pod
|
||||||
export client_pod_name=$(kubectl get pods -o name | grep client | cut -d '/' -f2)
|
export client_pod_name=$(kubectl get pods -o name | grep client | cut -d '/' -f2)
|
||||||
|
|
||||||
# Verify the client pod is working
|
# Verify the client pod is working
|
||||||
local cmd="kubectl get pod $client_pod_name -o yaml | grep 'phase: Running'"
|
local cmd="kubectl get pod ${client_pod_name} -o yaml | grep 'phase: Running'"
|
||||||
waitForProcess "$wait_time" "$sleep_time" "$cmd"
|
waitForProcess "${wait_time}" "${sleep_time}" "${cmd}"
|
||||||
|
|
||||||
# Get the ip address of the server pod
|
# Get the ip address of the server pod
|
||||||
export server_ip_add=$(kubectl get pod "$server_pod_name" -o jsonpath='{.status.podIP}')
|
export server_ip_add=$(kubectl get pod "${server_pod_name}" -o jsonpath='{.status.podIP}')
|
||||||
}
|
}
|
||||||
|
|
||||||
function iperf3_deployment_cleanup() {
|
function iperf3_deployment_cleanup() {
|
||||||
kubectl delete pod "$server_pod_name" "$client_pod_name"
|
info "iperf: deleting deployments and services"
|
||||||
kubectl delete ds iperf3-clients
|
kubectl delete pod "${server_pod_name}" "${client_pod_name}"
|
||||||
kubectl delete deployment "$deployment"
|
kubectl delete -f "${IPERF_DAEMONSET}"
|
||||||
kubectl delete service "$deployment"
|
kubectl delete -f "${IPERF_DEPLOYMENT}"
|
||||||
|
kill_kata_components && sleep 1
|
||||||
|
kill_kata_components
|
||||||
check_processes
|
check_processes
|
||||||
|
info "End of iperf3 test"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The deployment must be removed in
|
||||||
|
# any case the script terminates.
|
||||||
|
trap iperf3_deployment_cleanup EXIT
|
||||||
|
|
||||||
function help() {
|
function help() {
|
||||||
echo "$(cat << EOF
|
echo "$(cat << EOF
|
||||||
Usage: $0 "[options]"
|
Usage: $0 "[options]"
|
||||||
@ -309,8 +310,8 @@ function main() {
|
|||||||
export COLLECT_ALL=true && iperf3_bandwidth && iperf3_jitter && iperf3_cpu && iperf3_parallel
|
export COLLECT_ALL=true && iperf3_bandwidth && iperf3_jitter && iperf3_cpu && iperf3_parallel
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
info "iperf3: saving test results"
|
||||||
metrics_json_save
|
metrics_json_save
|
||||||
iperf3_deployment_cleanup
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
Loading…
Reference in New Issue
Block a user