diff --git a/setupKAppNavTestEnv.sh b/setupKAppNavTestEnv.sh new file mode 100755 index 0000000..0ee1ba9 --- /dev/null +++ b/setupKAppNavTestEnv.sh @@ -0,0 +1,162 @@ +#!/bin/bash +#################################################### +# +# setupKAppNavTestEnv.sh for Kubernetes Application Navigator +# +#################################################### + +# check if user wants help +if [ "$#" -lt 5 ] || [ x$1 = 'x' ] || [ x$1 = x'?' ] || [ x$1 = x'--?' ] || [ x$1 = x'-?' ] || [ x$1 = x'--help' ] || [ x$1 = x'help' ]; then + echo "This script required 5 positional parameters" + echo "Syntax: setupTestEnv.sh " + echo + echo "Where:" + echo + echo " specifies the target URL" + echo " specifies the target username" + echo " specifies the target password" + echo " specifies one of: okd, ocp, minishift or minikube. Default is okd" + echo " specifies your docker username" + echo + exit 0 +fi + +# get positional parms +platformURL=$1 +platformUsername=$2 +platformPassword=$3 +platform=$4 +dockerID=$5 + +if [ x$platform = 'xminikube' ] ; then + kubectl=$(kubectl) + if [ $? -ne 0 ]; then + echo "Error: kubectl not found. Make sure minikube is running." + echo "" + exit 1 + fi +else + # make sure to logout first, in case it already login to different platform + oc logout + # login to target platform + echo "oc login -u $platformUsername -p $platformPassword $platformURL" + oc login -u $platformUsername -p $platformPassword $platformURL + if [ $? -eq 0 ]; then + echo "########## OC login successfully. ##########" + else + echo "########## OC login failed, exiting. ##########" + exit 1 + fi +fi + +# At least check if previous KAppNav already install on user namespace +# If there is then uninstall first as having 2 instances install on same platform won't work well + +# check if KAppNav has been installed using docker id namespace +./test/isDeployed.sh $dockerID +if [ $? -eq 0 ]; then + echo "KAppNav already installed on namespace $dockerID" + echo "Uninstalling KAppNav from $dockerID namespace" + kubectl delete -f ../operator/kappnav-delete-CR.yaml -n $dockerID --now + kubectl delete -f ../operator/kappnav-delete.yaml -n $dockerID + kubectl delete namespace $dockerID + if [ $? -eq 0 ]; then + echo "########## Uninstall successfully. ##########" + else + echo "########## Uninstall failed, exiting ##########" + exit 1 + fi +fi + +# check if KAppNav has been installed on kappnav namespace +# because if either AppNav or KAppNav already install on the platform you are using then thing won't work well +./test/isDeployed.sh kappnav +if [ $? -eq 0 ]; then + echo "KAppNav already installed on namespace kappnav" + echo "Uninstalling KAppNav from kappnav namespace" + ./uninstall.sh + if [ $? -eq 0 ]; then + echo "########## Uninstall successfully. ##########" + else + echo "########## Uninstall failed, exiting ##########" + exit 1 + fi +fi + +# build kappnav +echo "########## Building KAppNav ########## " +./build.sh +if [ $? -eq 0 ]; then + echo "########## Build successfully. ##########" +else + echo "########## Build failed, exiting. ##########" + exit 1 +fi + +# push all images to docker hub +echo "########## Pushing all KAppNav images to docker hub of $dockerID ########## " +./pushimages.sh $dockerID +if [ $? -eq 0 ]; then + echo "########## Pushed KAppNav images successfully. ##########" +else + echo "########## Pushed KAppNav images failed, exiting. ##########" + exit 1 +fi + +# installing to target platform +./install.sh $dockerID $platform +if [ $? -eq 0 ]; then + echo "########## Install successfully. ##########" +else + echo "########## Install failed, exiting. ##########" + exit 1 +fi + +# check to make sure KAppNav healthy +./test/isKAppNavHealthy.sh kappnav 3 +if [ $? -ne 0 ]; then + echo "########## isKAppNavHealthy failed, exiting ##########" + exit 1 +fi + +# check to hit kappnavui url +./test/isKappnavUIOK.sh kappnav $platform +if [ $? -ne 0 ]; then + echo "########## isKappnavUIOK failed, exiting ##########" + exit 1 +fi + +# install sample stocktrader application +./test/installStocktrader.sh ../samples/stocktrader +if [ $? -ne 0 ]; then + echo "########## installStocktrader failed, exiting ##########" + exit 1 +fi + +# install sample bookinfo application +./test/installBookinfo.sh ../samples/bookinfo +if [ $? -ne 0 ]; then + echo "########## installBookinfo failed, exiting ##########" + exit 1 +fi + +# test to make sure adminCenter url OK +# If do not want to launch the adminCenter, do not pass in true +./test/isAdminCenterUIOK.sh kappnav $platform + +# launch kappnav ui to do UI manual test with the test env setup +# If do not want to launch the KAppNavUI, do not pass in true +./test/isKappnavUIOK.sh kappnav $platform true + +exit 0 + + + + + + + + + + + diff --git a/test/installBookinfo.sh b/test/installBookinfo.sh new file mode 100755 index 0000000..48bcc6d --- /dev/null +++ b/test/installBookinfo.sh @@ -0,0 +1,28 @@ +#!/bin/bash +#################################################### +# +# installBookinfo.sh +# +#################################################### + +if [ "$#" -lt 1 ] || [ x$1 = 'x' ] || [ x$1 = x'?' ] || [ x$1 = x'--?' ] || [ x$1 = x'-?' ] || [ x$1 = x'--help' ] || [ x$1 = x'help' ]; then + echo Syntax: installBookinfo.sh \ + echo "Where:" + echo " specifies the path where bookinfo sample located" + exit 1 +fi + +bookinfoPath=$1 + +echo "kubectl create namespace bookinfo" +kubectl create namespace bookinfo + +echo "kubectl apply -f $bookinfoPath -n bookinfo" +kubectl apply -f $bookinfoPath -n bookinfo + +if [ $? -eq 0 ]; then + echo "########## Bookinfo sample application installed successfully ##########" +else + echo "########## Failed to install bookinfo sample application ##########" + exit 1 +fi diff --git a/test/installStocktrader.sh b/test/installStocktrader.sh new file mode 100755 index 0000000..17ef9c0 --- /dev/null +++ b/test/installStocktrader.sh @@ -0,0 +1,31 @@ +#!/bin/bash +#################################################### +# +# installStocktrader.sh +# +#################################################### + +if [ "$#" -lt 1 ] || [ x$1 = 'x' ] || [ x$1 = x'?' ] || [ x$1 = x'--?' ] || [ x$1 = x'-?' ] || [ x$1 = x'--help' ] || [ x$1 = x'help' ]; then + echo Syntax: installStocktrader.sh \ + echo "Where:" + echo " specifies the path where stocktrader sample located" + exit 1 +fi + +stocktraderPath=$1 + +echo "kubectl create namespace stocktrader" +kubectl create namespace stocktrader + +echo "kubectl apply -f $stocktraderPath -n stocktrader" +kubectl apply -f $stocktraderPath -n stocktrader + +if [ $? -eq 0 ]; then + # update stocktrader namespace to include all other application namespace that should show up under stock trader component view + echo "kubectl annotate Application stock-trader kappnav.component.namespaces=twas,liberty,localliberty -n stocktrader --overwrite" + kubectl annotate Application stock-trader kappnav.component.namespaces=twas,liberty,localliberty -n stocktrader --overwrite + echo "########## Stocktrader sample application installed successfully ##########" +else + echo "########## Failed to install stocktrader sample application ##########" + exit 1 +fi \ No newline at end of file diff --git a/test/isAdminCenterUIOK.sh b/test/isAdminCenterUIOK.sh new file mode 100755 index 0000000..66097b8 --- /dev/null +++ b/test/isAdminCenterUIOK.sh @@ -0,0 +1,39 @@ +if [ "$#" -lt 2 ] || [ x$1 = 'x' ] || [ x$1 = x'?' ] || [ x$1 = x'--?' ] || [ x$1 = x'-?' ] || [ x$1 = x'--help' ] || [ x$1 = x'help' ]; then + echo "Syntax: isAdminCenterUIOK.sh [true|false]" + echo "Where:" + echo " specifies the namespace where AppNav is installed." + echo " specifies one of: okd, ocp or minishift. Default is okd." + echo " optional: [true|false] true will launch the kappnavui page." + exit 1 +fi + +namespace=$1 +platform=$2 +launch=$3 + +# test to hit Liberty adminCenter ui +if [ x$platform != 'xminikube' ] ; then + echo "kubectl get route -n $namespace -o=jsonpath={@.items[0].spec.host}" + host=$(kubectl get route -n $namespace -o=jsonpath={@.items[0].spec.host}) + if [ -z host ]; then + echo "Could not retrieve kappnavui host from route. Confirm install is correct." + exit 1 + fi + url="https://$host/adminCenter/" + + curl=$(curl $url --insecure >/dev/null 2>/dev/null) + if [ $? -ne 0 ]; then + echo "Error: $url not responding. Check that initialization is complete and successful." + echo "" + exit 1 + fi +fi + +echo "########## Liberty AdminCenter UI is OK ##########" + +if [ "$launch" = "true" ]; then + open $url + echo "########## Liberty AdminCenter UI is launched at url $url ##########" +fi + + diff --git a/test/isDeployed.sh b/test/isDeployed.sh new file mode 100755 index 0000000..8c2de90 --- /dev/null +++ b/test/isDeployed.sh @@ -0,0 +1,19 @@ +if [ "$#" -lt 1 ] || [ x$1 = 'x' ] || [ x$1 = x'?' ] || [ x$1 = x'--?' ] || [ x$1 = x'-?' ] || [ x$1 = x'--help' ] || [ x$1 = x'help' ]; then + echo Syntax: isDeployed.sh \ + echo "Where:" + echo " specifies the namespace where KAppNav is installed." + exit 1 +fi + +namespace=$1 + +echo "kubectl get Deployment -n $namespace --no-headers" +deployments=$(kubectl get Deployment -n $namespace --no-headers) +depLen=${#deployments} +if [ $depLen -ne 0 ]; then + echo "Already installed" + exit 0 +else + echo "Not installed yet" + exit 1 +fi diff --git a/test/isKAppNavHealthy.sh b/test/isKAppNavHealthy.sh new file mode 100755 index 0000000..31d2a82 --- /dev/null +++ b/test/isKAppNavHealthy.sh @@ -0,0 +1,72 @@ +#!/bin/bash +#################################################### +# +# isKAppNavHealthy.sh +# +#################################################### + +if [ "$#" -lt 1 ] || [ x$1 = 'x' ] || [ x$1 = x'?' ] || [ x$1 = x'--?' ] || [ x$1 = x'-?' ] || [ x$1 = x'--help' ] || [ x$1 = x'help' ]; then + echo Syntax: isKAppNavHealthy.sh \ + echo "Where:" + echo " specifies the namespace where AppNav is installed." + exit 1 +fi + +namespace=$1 +numPods=$2 + +# get all KAppNav pods +echo "kubectl get pods -n $namespace --no-headers -o custom-columns=NAME:.metadata.name" +kappnavPods=$(kubectl get pods -n $namespace --no-headers -o custom-columns=NAME:.metadata.name) +echo $kappnavPods +kappnavPodsArray=( $kappnavPods ) +kappnavPodsLen="${#kappnavPodsArray[@]}" + +# check to make sure all KAppNav pods created +count=0 +while [ $kappnavPodsLen -ne $numPods ] +do + if [ $count -eq 12 ]; then + exit 1 + else + echo "kubectl get pods -n $namespace --no-headers -o custom-columns=NAME:.metadata.name" + kappnavPods=$(kubectl get pods -n $namespace --no-headers -o custom-columns=NAME:.metadata.name) + kappnavPodsArray=( $kappnavPods ) + kappnavPodsLen="${#kappnavPodsArray[@]}" + if [ $kappnavPodsLen -ne $numPods ]; then + # check to make sure all kappnav pods created for 1 minutes at the most with 5s delay in between checking + sleep 5 + fi + count=$((count+1)) + fi +done + +echo $kappnavPods +# check all KAppNav pods until all pods status true +for kappnavPod in $kappnavPods +do + status="false" + count=0 + while [ "$status" = "false" ] + do + # check to make sure the apps created for 10 minutes at the most with 5s delay in between checking + if [ $count -eq 120 ]; then + exit 1 + else + echo "kubectl get pods $kappnavPod -n $namespace --no-headers -o custom-columns=Ready:status.containerStatuses[0].ready" + status=$(kubectl get pods $kappnavPod -n $namespace --no-headers -o custom-columns=Ready:status.containerStatuses[0].ready) + if [ "$status" = "false" ]; then + sleep 5 + fi + count=$((count+1)) + fi + echo "Status : $status" + done +done + +echo "########## KAppNav pods are healthy ##########" + + + + + diff --git a/test/isKappnavUIOK.sh b/test/isKappnavUIOK.sh new file mode 100755 index 0000000..209143b --- /dev/null +++ b/test/isKappnavUIOK.sh @@ -0,0 +1,39 @@ +if [ "$#" -lt 2 ] || [ x$1 = 'x' ] || [ x$1 = x'?' ] || [ x$1 = x'--?' ] || [ x$1 = x'-?' ] || [ x$1 = x'--help' ] || [ x$1 = x'help' ]; then + echo "Syntax: isKappnavUIOK.sh [true|false]" + echo "Where:" + echo " specifies the namespace where KAppNav is installed." + echo " specifies one of: okd, ocp or minishift. Default is okd." + echo " optional: [true|false] true will launch the kappnavui page." + exit 1 +fi + +namespace=$1 +platform=$2 +launch=$3 + +# test to hit KAppNav ui +if [ x$platform != 'xminikube' ] ; then + echo "kubectl get route -n $namespace -o=jsonpath={@.items[0].spec.host}" + host=$(kubectl get route -n $namespace -o=jsonpath={@.items[0].spec.host}) + if [ -z host ]; then + echo "Could not retrieve kappnavui host from route. Confirm install is correct." + exit 1 + fi + url="https://$host/kappnav-ui/" + + curl=$(curl $url --insecure >/dev/null 2>/dev/null) + if [ $? -ne 0 ]; then + echo "Error: $url not responding. Check that initialization is complete and successful." + echo "" + exit 1 + fi +fi + +echo "########## KAppNav UI is OK ##########" + +if [ "$launch" = "true" ]; then + open $url + echo "########## KAppNav UI is launched at url $url ##########" +fi + +