mirror of
https://github.com/clearlinux/cloud-native-setup.git
synced 2026-08-26 18:36:03 +00:00
metrics: api: move some api code out to a common file
We are very likely to re-use the k8s api code in many/all of the tests, so move common code out to a common libray file. Signed-off-by: Graham Whaley <graham.whaley@intel.com>
This commit is contained in:
committed by
David Lyle
parent
293a2b32d2
commit
fa94c2ce90
@@ -10,6 +10,7 @@ RESULT_DIR="${LIB_DIR}/../results"
|
||||
|
||||
source ${LIB_DIR}/kata-common.bash
|
||||
source ${LIB_DIR}/json.bash
|
||||
source ${LIB_DIR}/k8s-api.bash
|
||||
source /etc/os-release || source /usr/lib/os-release
|
||||
|
||||
# Set variables to reasonable defaults if unset or empty
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) 2019 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Helper routines for talking to k8s over its API, via http/curl
|
||||
|
||||
API_ADDRESS="http://127.0.0.1"
|
||||
API_PORT="8090"
|
||||
PROXY_CMD="kubectl proxy --port=${API_PORT}"
|
||||
clean_up_proxy=false
|
||||
|
||||
k8s_api_init() {
|
||||
# check if kubectl proxy is already running. If it is use the port,
|
||||
# specified, otherwise start kubectl proxy command.
|
||||
if [ $use_api != "no" ]; then
|
||||
# assuming command was called "kubectl proxy --port=####"
|
||||
# FIXME make this more flexible for --port parameter being in a different order
|
||||
local port
|
||||
port=$(ps -ef | awk '$8 == "kubectl" && $9 == "proxy" {print $10}' | cut -b1-7 --complement)
|
||||
if [ -z $port ]; then
|
||||
echo "starting kubectl proxy"
|
||||
clean_up_proxy=true
|
||||
${PROXY_CMD} &
|
||||
else
|
||||
echo "found proxy port: ${port}"
|
||||
API_PORT=$port
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
k8s_api_shutdown() {
|
||||
# if this script launched the proxy, clean it up to prevent hang on exit
|
||||
if [ "$clean_up_proxy" = "true" ]; then
|
||||
echo "cleaning up kubectl proxy"
|
||||
kill $(pgrep -f "${PROXY_CMD}")
|
||||
fi
|
||||
}
|
||||
|
||||
# get the number of nodes in the "Ready" state
|
||||
get_num_nodes() {
|
||||
n=$(kubectl get nodes --no-headers=true | awk '$2 == "Ready" {print $1}' | wc -l)
|
||||
echo "$n"
|
||||
}
|
||||
|
||||
@@ -34,17 +34,6 @@ use_api=${use_api:-yes}
|
||||
TEST_ARGS="runtime=${RUNTIME}"
|
||||
TEST_NAME="k8s scaling"
|
||||
|
||||
API_ADDRESS="http://127.0.0.1"
|
||||
API_PORT="8090"
|
||||
PROXY_CMD="kubectl proxy --port=${API_PORT}"
|
||||
clean_up_proxy=false
|
||||
|
||||
# get the number of nodes in the "Ready" state
|
||||
get_num_nodes() {
|
||||
n=$(kubectl get nodes --no-headers=true | awk '$2 == "Ready" {print $1}' | wc -l)
|
||||
echo "$n"
|
||||
}
|
||||
|
||||
# $1 is the launch time in seconds this pod/container took to start up.
|
||||
# $2 is the number of pod/containers under test
|
||||
grab_stats() {
|
||||
@@ -104,22 +93,7 @@ init() {
|
||||
# FIXME - check the node(s) can run enough pods - check 'max-pods' in the
|
||||
# kubelet config - from 'kubectl describe node -o json' ?
|
||||
|
||||
# check if kubectl proxy is already running. If it is use the port,
|
||||
# specified, otherwise start kubectl proxy command.
|
||||
if [ $use_api != "no" ]; then
|
||||
# assuming command was called "kubectl proxy --port=####"
|
||||
# FIXME make this more flexible for --port parameter being in a different order
|
||||
local port
|
||||
port=$(ps -ef | awk '$8 == "kubectl" && $9 == "proxy" {print $10}' | cut -b1-7 --complement)
|
||||
if [ -z $port ]; then
|
||||
echo "starting kubectl proxy"
|
||||
clean_up_proxy=true
|
||||
${PROXY_CMD} &
|
||||
else
|
||||
echo "found proxy port: ${port}"
|
||||
API_PORT=$port
|
||||
fi
|
||||
fi
|
||||
k8s_api_init
|
||||
|
||||
# Launch our stats gathering pod
|
||||
kubectl apply -f ${SCRIPT_PATH}/${stats_pod}.yaml
|
||||
@@ -245,11 +219,7 @@ EOF
|
||||
metrics_json_add_fragment "$json"
|
||||
metrics_json_save
|
||||
|
||||
# if this script launched the proxy, clean it up to prevent hang on exit
|
||||
if [ "$clean_up_proxy" = "true" ]; then
|
||||
echo "cleaning up kubectl proxy"
|
||||
kill $(pgrep -f "${PROXY_CMD}")
|
||||
fi
|
||||
k8s_api_shutdown
|
||||
}
|
||||
|
||||
show_vars()
|
||||
|
||||
Reference in New Issue
Block a user