echo " [--repo-policy local|remote] [--cluster-timeout <timeout-in seconds>] [--print-stats]"
echo " [--override <override-environment-filename>] [--pre-clean] [--gen-stats] [--delete-namespaces]"
echo " [--delete-containers] [--endpoint-stats] [--kubeconfig <config-file>] [--host-path-dir <local-host-dir>]"
- echo " [--kubecontext <context-name>]"
+ echo " [--kubecontext <context-name>] [--docker-host <docker-host-url>] [--docker-proxy <host-or-ip>]"
}
if [ $# -eq 1 ] && [ "$1" == "help" ]; then
echo "--kubeconfig - Configure kubectl to use cluster specific cluster config file"
echo "--host-path-dir - (Base-)path on local-hostmounted to all VMs (nodes), for hostpath volumes in kube"
echo "--kubecontext - Configure kubectl to use a certain context, e.g 'minikube'"
+ echo "--docker-host - Configure docker to use docker in e.g. a VM"
+ echo "--docker-proxy - Configure ip/host to docker when docker is running in a VM"
echo ""
echo "List of app short names supported: "$APP_SHORT_NAMES
exit 0
#Var to indicate docker-compose version, V1 or V2
#V1 names replicated containers <proj-name>_<service-name>_<index>
#V2 names replicated containers <proj-name>-<service-name>-<index>
-DOCKER_COMPOSE_VERION="V1"
+DOCKER_COMPOSE_VERSION="V1"
# Function to indent cmd output with one space
indent1() { sed 's/^/ /'; }
#Var to configure kubectl from a config file or context
KUBECONF=""
+#Localhost, may be set to another host/ip by cmd parameter
+LOCALHOST_NAME="localhost"
+
+#Reseting vars related to token/keys used by kubeproxy when istio is enabled
+#The vars are populated if istio is used in the testcase
+KUBE_PROXY_CURL_JWT=""
+KUBE_PROXY_ISTIO_JWKS_KEYS=""
+
#Var pointing to dir mounted to each kubernetes node (master and workers)
#Persistent volumes using "hostpath" are allocated beneath the point.
#Typically it is a dir on local host mounted to each VM running the master and worker.
fi
else
HOST_PATH_BASE_DIR=$1
+ echo "Option set - Host path for kube set to: "$1
+ shift
+ foundparm=0
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--docker-host" ]; then
+ shift;
+ if [ -z "$1" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No url found for : '--docker-host'"
+ fi
+ else
+ export DOCKER_HOST="$1"
+ echo "Option set - DOCKER_HOST set to: "$1
+ shift
+ foundparm=0
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--docker-host" ]; then
+ shift;
+ if [ -z "$1" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No url found for : '--docker-host'"
+ fi
+ else
+ export DOCKER_HOST="$1"
+ echo "Option set - DOCKER_HOST set to: "$1
+ shift
+ foundparm=0
+ fi
+ fi
+ fi
+ if [ $paramerror -eq 0 ]; then
+ if [ "$1" == "--docker-proxy" ]; then
+ shift;
+ if [ -z "$1" ]; then
+ paramerror=1
+ if [ -z "$paramerror_str" ]; then
+ paramerror_str="No ip/host found for : '--docker-proxy'"
+ fi
+ else
+ export LOCALHOST_NAME=$1
+ echo "Option set - docker proxy set to: "$1
shift
foundparm=0
fi
exit 1
fi
-#Localhost constants
-LOCALHOST_NAME="localhost"
-# if [ ! -z "$DOCKER_HOST" ]; then
-# LOCALHOST_NAME=$(echo $DOCKER_HOST | awk -F[/:] '{print $4}' )
-# fi
LOCALHOST_HTTP="http://$LOCALHOST_NAME"
LOCALHOST_HTTPS="https://$LOCALHOST_NAME"
echo -e $RED"docker-compose is required to run the test environment, pls install"$ERED
exit 1
else
- tmp=$(docker-compose version --short)
+ tmp=$(docker-compose version)
echo " docker-compose installed and using version $tmp"
if [[ "$tmp" == *'v2'* ]]; then
- DOCKER_COMPOSE_VERION="V2"
+ DOCKER_COMPOSE_VERSION="V2"
fi
fi
fi
namespace=$1
labelname=$2
labelid=$3
- resources="deployments replicaset statefulset services pods configmaps persistentvolumeclaims persistentvolumes serviceaccounts clusterrolebindings secrets"
+ resources="deployments replicaset statefulset services pods configmaps persistentvolumeclaims persistentvolumes serviceaccounts clusterrolebindings secrets authorizationpolicies requestauthentications"
deleted_resourcetypes=""
for restype in $resources; do
ns_flag="-n $namespace"
ns_flag=""
ns_text=""
fi
- result=$(kubectl $KUBECONF get $restype $ns_flag -o jsonpath='{.items[?(@.metadata.labels.'$labelname'=="'$labelid'")].metadata.name}')
+ result=$(kubectl $KUBECONF get $restype $ns_flag -o jsonpath='{.items[?(@.metadata.labels.'$labelname'=="'$labelid'")].metadata.name}' 2> /dev/null)
if [ $? -eq 0 ] && [ ! -z "$result" ]; then
deleted_resourcetypes=$deleted_resourcetypes" "$restype
for resid in $result; do
return 0
}
-# Removes a namespace
+# Removes and re-create a namespace
# args: <namespace>
# (Not for test scripts)
clean_and_create_namespace() {
if [ $? -ne 0 ]; then
return 1
fi
+}
+# Add/remove label on non-namespaced kube object
+# args: <api> <instance> <label>
+# (Not for test scripts)
+__kube_label_non_ns_instance() {
+ kubectl $KUBECONF label $1 $2 "$3" 1> /dev/null 2> ./tmp/kubeerr
+ return $?
+}
+
+# Add/remove label on namespaced kube object
+# args: <api> <instance> <namespace> <label>
+# (Not for test scripts)
+__kube_label_ns_instance() {
+ kubectl $KUBECONF label $1 $2 -n $3 "$4" 1> /dev/null 2> ./tmp/kubeerr
+ return $?
}
# Find the host ip of an app (using the service resource)
fi
done
+ # Remove istio label on namespaces
+ test_env_namespaces=$(kubectl $KUBECONF get ns --no-headers -o custom-columns=":metadata.name" -l autotest=engine -l istio-injection=enabled) #Get list of ns created by the test env
+ if [ $? -ne 0 ]; then
+ echo " Cannot get list of namespaces...continues.."
+ else
+ for test_env_ns in $test_env_namespaces; do
+ echo " Removing istio label on ns: "$test_env_ns
+ __kube_label_non_ns_instance ns $test_env_ns "istio-injection-"
+ done
+ fi
+
echo ""
}
envsubst < $compose_file > "gen_"$compose_file
compose_file="gen_"$compose_file
- if [ $DOCKER_COMPOSE_VERION == "V1" ]; then
+ if [ $DOCKER_COMPOSE_VERSION == "V1" ]; then
docker_compose_cmd="docker-compose"
else
docker_compose_cmd="docker compose"
## Generic curl
###############
# Generic curl function, assumes all 200-codes are ok
+# Used proxy, set
# args: <valid-curl-args-including full url>
# returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
# returns: The return code is 0 for ok and 1 for not ok
proxyflag=" --proxy-insecure --proxy $KUBE_PROXY_PATH"
fi
fi
- curlString="curl -skw %{http_code} $proxyflag $@"
+
+ if [ ! -z "$KUBE_PROXY_CURL_JWT" ]; then
+ jwt="-H "\""Authorization: Bearer $KUBE_PROXY_CURL_JWT"\"
+ curlString="curl -skw %{http_code} $proxyflag $@"
+ echo " CMD: $curlString $jwt" >> $HTTPLOG
+ res=$($curlString -H "Authorization: Bearer $KUBE_PROXY_CURL_JWT")
+ retcode=$?
+ else
+ curlString="curl -skw %{http_code} $proxyflag $@"
+ echo " CMD: $curlString" >> $HTTPLOG
+ res=$($curlString)
+ retcode=$?
+ fi
+ echo " RESP: $res" >> $HTTPLOG
+ echo " RETCODE: $retcode" >> $HTTPLOG
+ if [ $retcode -ne 0 ]; then
+ echo "<no-response-from-server>"
+ return 1
+ fi
+ http_code="${res:${#res}-3}"
+ if [ ${#res} -eq 3 ]; then
+ if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
+ echo "<no-response-from-server>"
+ return 1
+ else
+ return 0
+ fi
+ else
+ if [ $http_code -lt 200 ] || [ $http_code -gt 299 ]; then
+ echo "<not found, resp:${http_code}>"
+ return 1
+ fi
+ if [ $# -eq 2 ]; then
+ echo "${res:0:${#res}-3}" | xargs
+ else
+ echo "${res:0:${#res}-3}"
+ fi
+
+ return 0
+ fi
+
+}
+
+# Generic curl function, assumes all 200-codes are ok
+# Uses no proxy, even if it is set
+# args: <valid-curl-args-including full url>
+# returns: <returned response (without respose code)> or "<no-response-from-server>" or "<not found, <http-code>>""
+# returns: The return code is 0 for ok and 1 for not ok
+__do_curl_no_proxy() {
+ echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG
+ curlString="curl -skw %{http_code} $@"
echo " CMD: $curlString" >> $HTTPLOG
res=$($curlString)
retcode=$?
return 1
fi
if [ $# -eq 2 ]; then
- echo "${res:0:${#res}-3}" | xargs
+ echo "${res:0:${#res}-3}" | xargs
else
- echo "${res:0:${#res}-3}"
+ echo "${res:0:${#res}-3}"
fi
return 0