Adaptation of test env to helm chart
[nonrtric.git] / test / common / kube_proxy_api_functions.sh
index c352ff1..dcaaf80 100644 (file)
@@ -93,15 +93,84 @@ __KUBEPROXY_kube_delete_all() {
 # This function is called for apps managed by the test script.
 # args: <log-dir> <file-prexix>
 __KUBEPROXY_store_docker_logs() {
-       docker logs $KUBE_PROXY_APP_NAME > $1$2_kubeproxy.log 2>&1
+       if [ $RUNMODE == "KUBE" ]; then
+               kubectl  logs -l "autotest=KUBEPROXY" -n $KUBE_SIM_NAMESPACE --tail=-1 > $1$2_kubeproxy.log 2>&1
+       else
+               docker logs $KUBE_PROXY_APP_NAME > $1$2_kubeproxy.log 2>&1
+       fi
+}
+
+# Initial setup of protocol, host and ports
+# This function is called for apps managed by the test script.
+# args: -
+__KUBEPROXY_initial_setup() {
+       use_kube_proxy_http
 }
 
 #######################################################
 
+## 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"
+
+       echo -e $YELLOW" This setting cannot be changed once the kube proxy is started"$EYELLOW
+       echo ""
+}
+
 #########################
-### Http Proxy functions
+### Kube Http Proxy functions
 #########################
 
+# Export env vars for config files, docker compose and kube resources
+# args: -
+__kube_proxy_vars() {
+
+       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
+
+       export KUBE_PROXY_APP_NAME
+       export KUBE_PROXY_DOCKER_EXTERNAL_PORT
+       export KUBE_PROXY_DOCKER_EXTERNAL_SECURE_PORT
+       export KUBE_PROXY_WEB_DOCKER_EXTERNAL_PORT
+       export KUBE_PROXY_WEB_DOCKER_EXTERNAL_SECURE_PORT
+       export DOCKER_SIM_NWNAME
+
+       export KUBE_PROXY_DISPLAY_NAME
+}
+
 # Start the Kube Http Proxy in the simulator group
 # args: -
 # (Function for test scripts)
@@ -139,13 +208,10 @@ start_kube_proxy() {
 
                if [ $retcode_i -eq 0 ]; then
                        echo -e " Creating $KUBE_PROXY_APP_NAME deployment and service"
+
+                       __kube_proxy_vars
+
                        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_SIM_NAMESPACE
-                       export KUBE_PROXY_IMAGE
 
                        __kube_create_namespace $KUBE_SIM_NAMESPACE
 
@@ -163,8 +229,6 @@ start_kube_proxy() {
 
                echo " Retrieving host and ports for service..."
 
-               CLUSTER_KUBE_PROXY="http"
-
                #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}")
@@ -188,30 +252,70 @@ start_kube_proxy() {
                                echo -e $YELLOW" The test environment host/ip is: $CLUSTER_KUBE_PROXY_HOST."$EYELLOW
                        fi
                fi
+
+               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 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
-                       echo " Cluster ip/host, cluster http nodeport, cluster web nodeport: $CLUSTER_KUBE_PROXY_HOST $CLUSTER_KUBE_PROXY_PORT $KUBE_PROXY_WEB_NODEPORT"
+                       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 for proxy access
-                       KUBE_PROXY_WEB_NODEPORT=$(__kube_get_service_port $KUBE_PROXY_APP_NAME $KUBE_SIM_NAMESPACE "web")  # web port, only for alive test
-                       echo " Proxy ip/host, proxy http port, proxy web port: $CLUSTER_KUBE_PROXY_HOST $CLUSTER_KUBE_PROXY_PORT $KUBE_PROXY_WEB_NODEPORT"
+                       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
 
-               KUBE_PROXY_WEB_PATH=$CLUSTER_KUBE_PROXY"://"$CLUSTER_KUBE_PROXY_HOST":"$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_PORT
+               export KUBE_PROXY_PATH=$KUBE_PROXY_HTTPX"://"$CLUSTER_KUBE_PROXY_HOST":"$CLUSTER_KUBE_PROXY_PORT
+               export KUBE_PROXY_HTTPX
+
+               KP_PORT1=$(__kube_get_service_nodeport $KUBE_PROXY_APP_NAME $KUBE_SIM_NAMESPACE "http")
+               KP_PORT2=$(__kube_get_service_nodeport $KUBE_PROXY_APP_NAME $KUBE_SIM_NAMESPACE "https")
+
+               echo " $KUBE_PROXY_DISPLAY_NAME node ports (http/https): $KP_PORT1 $KP_PORT2"
 
        else
-               echo $YELLOW" Kube http proxy not needed in docker test. App not started"
+               # Check if docker app shall be fully managed by the test script
+               __check_included_image 'KUBEPROXY'
+               if [ $? -eq 1 ]; then
+                       echo -e $RED"The Kube Proxy app is not included in this test script"$ERED
+                       echo -e $RED"The Kube Proxy will not be started"$ERED
+                       exit
+               fi
+
+               __kube_proxy_vars
+
+               __start_container $KUBE_PROXY_COMPOSE_DIR "" NODOCKERARGS 1 $KUBE_PROXY_APP_NAME
+
+               if [ $KUBE_PROXY_HTTPX == "http" ]; then
+                       export KUBE_PROXY_WEB_PATH=$KUBE_PROXY_HTTPX"://"$LOCALHOST_NAME":"$KUBE_PROXY_WEB_DOCKER_EXTERNAL_PORT
+               else
+                       export KUBE_PROXY_WEB_PATH=$KUBE_PROXY_HTTPX"://"$LOCALHOST_NAME":"$KUBE_PROXY_WEB_DOCKER_EXTERNAL_SECURE_PORT
+               fi
+
+               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
+
+               if [ $KUBE_PROXY_HTTPX == "http" ]; then
+                       export KUBE_PROXY_PATH=$KUBE_PROXY_HTTPX"://"$LOCALHOST_NAME":"$KUBE_PROXY_DOCKER_EXTERNAL_PORT
+               else
+                       export KUBE_PROXY_PATH=$KUBE_PROXY_HTTPX"://"$LOCALHOST_NAME":"$KUBE_PROXY_DOCKER_EXTERNAL_SECURE_PORT
+               fi
+
+               echo " $KUBE_PROXY_DISPLAY_NAME localhost ports (http/https): $KUBE_PROXY_DOCKER_EXTERNAL_PORT $KUBE_PROXY_DOCKER_EXTERNAL_SECURE_PORT"
+
+
        fi
        echo ""