X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Fkube_proxy_api_functions.sh;h=59b63464115840918a81a45fc9d2f438b13ab4c0;hb=84ffd4a403baee1b7aa86f9986f0c1659a5a0881;hp=374f3ec4a050f15a75ada31a262a7380c78a8582;hpb=483ee33ac3de88385c0eeb3f1ecf3a1bb760db54;p=nonrtric.git diff --git a/test/common/kube_proxy_api_functions.sh b/test/common/kube_proxy_api_functions.sh index 374f3ec4..59b63464 100644 --- a/test/common/kube_proxy_api_functions.sh +++ b/test/common/kube_proxy_api_functions.sh @@ -26,7 +26,7 @@ # arg: (selects staging, snapshot, release etc) # is present only for images with staging, snapshot,release tags __KUBEPROXY_imagesetup() { - __check_and_create_image_var KUBEPROXY "KUBE_PROXY_IMAGE" "KUBE_PROXY_IMAGE_BASE" "KUBE_PROXY_IMAGE_TAG" REMOTE_PROXY "$KUBE_PROXY_DISPLAY_NAME" + __check_and_create_image_var KUBEPROXY "KUBE_PROXY_IMAGE" "KUBE_PROXY_IMAGE_BASE" "KUBE_PROXY_IMAGE_TAG" LOCAL "$KUBE_PROXY_DISPLAY_NAME" } # Pull image from remote repo or use locally built image @@ -35,14 +35,29 @@ __KUBEPROXY_imagesetup() { # Shall be used for images that does not allow overriding # Both var may contain: 'remote', 'remote-remove' or 'local' __KUBEPROXY_imagepull() { - __check_and_pull_image $2 "$KUBE_PROXY_DISPLAY_NAME" $KUBE_PROXY_APP_NAME KUBE_PROXY_IMAGE + echo -e $RED"Image for app KUBEPROXY shall never be pulled from remote repo"$ERED } # Build image (only for simulator or interfaces stubs owned by the test environment) # arg: (selects staging, snapshot, release etc) # is present only for images with staging, snapshot,release tags __KUBEPROXY_imagebuild() { - echo -e $RED"Image for app KUBEPROXY shall never be built"$ERED + cd ../http-https-proxy + echo " Building KUBEPROXY - $KUBE_PROXY_DISPLAY_NAME - image: $KUBE_PROXY_IMAGE" + docker build --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $KUBE_PROXY_IMAGE . &> .dockererr + if [ $? -eq 0 ]; then + echo -e $GREEN" Build Ok"$EGREEN + __retag_and_push_image KUBE_PROXY_IMAGE + if [ $? -ne 0 ]; then + exit 1 + fi + else + echo -e $RED" Build Failed"$ERED + ((RES_CONF_FAIL++)) + cat .dockererr + echo -e $RED"Exiting...."$ERED + exit 1 + fi } # Generate a string for each included image using the app display name and a docker images format string @@ -65,7 +80,7 @@ __KUBEPROXY_kube_scale_zero() { # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action. # This function is called for prestarted apps not managed by the test script. __KUBEPROXY_kube_scale_zero_and_wait() { - echo -e $RED" Http proxy replicas kept as is"$ERED + echo -e $RED" KUBEPROXY app is not scaled in this state"$ERED } # Delete all kube resouces for the app @@ -83,16 +98,39 @@ __KUBEPROXY_store_docker_logs() { ####################################################### +## Access to Kube http proxy +# Direct access +KUBE_PROXY_HTTPX="http" + + +# Set http as the protocol to use for all communication to the Kube http proxy +# args: - +# (Function for test scripts) +use_kube_proxy_http() { + echo -e $BOLD"$KUBE_PROXY_DISPLAY_NAME protocol setting"$EBOLD + echo -e " Using $BOLD http $EBOLD towards Kube http proxy" + + KUBE_PROXY_HTTPX="http" + + echo -e $YELLOW" This setting cannot be changed once the kube proxy is started"$EYELLOW + echo "" +} + +# Set https as the protocol to use for all communication to the Kube http proxy +# args: - +# (Function for test scripts) +use_kube_proxy_https() { + echo -e $BOLD"$KUBE_PROXY_DISPLAY_NAME protocol setting"$EBOLD + echo -e " Using $BOLD https $EBOLD towards Kube http proxy" + + KUBE_PROXY_HTTPX="https" -## Access to Kube Http Proxy -# Host name may be changed if app started by kube -# Direct access from script -#BMXX KUBE_PROXY_HTTPX="http" -#BMXX KUBE_PROXY_HOST_NAME=$LOCALHOST_NAME -#BMXX KUBE_PROXY_PATH=$KUBE_PROXY_HTTPX"://"$KUBE_PROXY_HOST_NAME":"$KUBE_PROXY_WEB_EXTERNAL_PORT + echo -e $YELLOW" This setting cannot be changed once the kube proxy is started"$EYELLOW + echo "" +} ######################### -### Http Proxy functions +### Kube Http Proxy functions ######################### # Start the Kube Http Proxy in the simulator group @@ -133,10 +171,17 @@ start_kube_proxy() { if [ $retcode_i -eq 0 ]; then echo -e " Creating $KUBE_PROXY_APP_NAME deployment and service" export KUBE_PROXY_APP_NAME + export KUBE_PROXY_WEB_EXTERNAL_PORT export KUBE_PROXY_WEB_INTERNAL_PORT export KUBE_PROXY_EXTERNAL_PORT export KUBE_PROXY_INTERNAL_PORT + + export KUBE_PROXY_WEB_EXTERNAL_SECURE_PORT + export KUBE_PROXY_WEB_INTERNAL_SECURE_PORT + export KUBE_PROXY_EXTERNAL_SECURE_PORT + export KUBE_PROXY_INTERNAL_SECURE_PORT + export KUBE_SIM_NAMESPACE export KUBE_PROXY_IMAGE @@ -156,28 +201,60 @@ start_kube_proxy() { echo " Retrieving host and ports for service..." - CLUSTER_KUBE_PROXY="http" - CLUSTER_KUBE_PROXY_HOST=$(kubectl config view -o jsonpath={.clusters[0].cluster.server} | awk -F[/:] '{print $4}') - if [[ $CLUSTER_KUBE_PROXY_HOST == *"kubernetes"* ]]; then - echo -e $YELLOW" The cluster host is: $CLUSTER_KUBE_PROXY_HOST. The proxy (mitmproxy) used by test script requires an ip so the ip is assumed and set to 127.0.0.1" + #Finding host of the proxy + echo " Trying to find svc hostname..." + CLUSTER_KUBE_PROXY_HOST=$(__kube_cmd_with_timeout "kubectl get svc $KUBE_PROXY_APP_NAME -n $KUBE_SIM_NAMESPACE -o jsonpath={.status.loadBalancer.ingress[0].hostname}") + + + if [ "$CLUSTER_KUBE_PROXY_HOST" == "localhost" ]; then + #Local host found + echo -e $YELLOW" The test environment svc $KUBE_PROXY_APP_NAME host is: $CLUSTER_KUBE_PROXY_HOST"$EYELLOW CLUSTER_KUBE_PROXY_HOST="127.0.0.1" + else + if [ -z "$CLUSTER_KUBE_PROXY_HOST" ]; then + #Host of proxy not found, trying to find the ip.... + echo " Trying to find svc ip..." + CLUSTER_KUBE_PROXY_HOST=$(__kube_cmd_with_timeout "kubectl get svc $KUBE_PROXY_APP_NAME -n $KUBE_SIM_NAMESPACE -o jsonpath={.status.loadBalancer.ingress[0].ip}") + if [ ! -z "$CLUSTER_KUBE_PROXY_HOST" ]; then + #Host ip found + echo -e $YELLOW" The test environment svc $KUBE_PROXY_APP_NAME ip is: $CLUSTER_KUBE_PROXY_HOST."$EYELLOW + fi + else + #Host or ip of proxy found + echo -e $YELLOW" The test environment host/ip is: $CLUSTER_KUBE_PROXY_HOST."$EYELLOW + fi fi - CLUSTER_KUBE_PROXY_NODEPORT=$(__kube_get_service_nodeport $KUBE_PROXY_APP_NAME $KUBE_SIM_NAMESPACE "http") # port for proxy access - KUBE_PROXY_WEB_NODEPORT=$(__kube_get_service_nodeport $KUBE_PROXY_APP_NAME $KUBE_SIM_NAMESPACE "web") # web port, only for alive test - KUBE_PROXY_WEB_PATH=$CLUSTER_KUBE_PROXY"://"$CLUSTER_KUBE_PROXY_HOST":"$KUBE_PROXY_WEB_NODEPORT + PORT_KEY_PREFIX="" + if [ $KUBE_PROXY_HTTPX == "https" ]; then + PORT_KEY_PREFIX="s" #add suffix to port key name to get https ports + fi + if [ -z "$CLUSTER_KUBE_PROXY_HOST" ]; then + #Host/ip of proxy not found, try to use the cluster and the nodeports of the proxy + CLUSTER_KUBE_PROXY_HOST=$(kubectl config view -o jsonpath={.clusters[0].cluster.server} | awk -F[/:] '{print $4}') + echo -e $YELLOW" The test environment cluster ip is: $CLUSTER_KUBE_PROXY_HOST."$EYELLOW + CLUSTER_KUBE_PROXY_PORT=$(__kube_get_service_nodeport $KUBE_PROXY_APP_NAME $KUBE_SIM_NAMESPACE "http$PORT_KEY_PREFIX") # port for proxy access + KUBE_PROXY_WEB_NODEPORT=$(__kube_get_service_nodeport $KUBE_PROXY_APP_NAME $KUBE_SIM_NAMESPACE "web$PORT_KEY_PREFIX") # web port, only for alive test + echo " Cluster ip/host, cluster http$PORT_KEY_PREFIX nodeport, cluster web$PORT_KEY_PREFIX nodeport: $CLUSTER_KUBE_PROXY_HOST $CLUSTER_KUBE_PROXY_PORT $KUBE_PROXY_WEB_NODEPORT" + else + #Find the service ports of the proxy + CLUSTER_KUBE_PROXY_PORT=$(__kube_get_service_port $KUBE_PROXY_APP_NAME $KUBE_SIM_NAMESPACE "http$PORT_KEY_PREFIX") # port for proxy access + KUBE_PROXY_WEB_NODEPORT=$(__kube_get_service_port $KUBE_PROXY_APP_NAME $KUBE_SIM_NAMESPACE "web$PORT_KEY_PREFIX") # web port, only for alive test + echo " Proxy ip/host, proxy http$PORT_KEY_PREFIX port, proxy web$PORT_KEY_PREFIX port: $CLUSTER_KUBE_PROXY_HOST $CLUSTER_KUBE_PROXY_PORT $KUBE_PROXY_WEB_NODEPORT" + fi - echo " Cluster ip/host, cluster http nodeport cluster web nodeport: $CLUSTER_KUBE_PROXY_HOST $CLUSTER_KUBE_PROXY_NODEPORT $KUBE_PROXY_WEB_NODEPORT" + KUBE_PROXY_WEB_PATH=$KUBE_PROXY_HTTPX"://"$CLUSTER_KUBE_PROXY_HOST":"$KUBE_PROXY_WEB_NODEPORT export KUBE_PROXY_PATH= # Make sure proxy is empty when checking the proxy itself __check_service_start $KUBE_PROXY_APP_NAME $KUBE_PROXY_WEB_PATH$KUBE_PROXY_ALIVE_URL # Set proxy for all subsequent calls for all services etc - export KUBE_PROXY_PATH=$CLUSTER_KUBE_PROXY"://"$CLUSTER_KUBE_PROXY_HOST":"$CLUSTER_KUBE_PROXY_NODEPORT - + export KUBE_PROXY_PATH=$KUBE_PROXY_HTTPX"://"$CLUSTER_KUBE_PROXY_HOST":"$CLUSTER_KUBE_PROXY_PORT + export KUBE_PROXY_HTTPX else echo $YELLOW" Kube http proxy not needed in docker test. App not started" fi echo "" + }