Skip to content

Commit

Permalink
[hack] skupper script can now install the east-west demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jmazzitelli committed Mar 27, 2024
1 parent d91b83b commit fad4799
Showing 1 changed file with 81 additions and 3 deletions.
84 changes: 81 additions & 3 deletions hack/istio/skupper/install-skupper-demo.sh
Expand Up @@ -13,6 +13,10 @@
# Mongo database over that pipe. The MySQL database will be exposed externally
# using a LoadBalancer (if on minikube) and the NodePort (if on OpenShift).
#
# As an extra option, you can ask this script to install the basic Skupper
# demo that we will call the east-west demo (see: https://skupper.io/start/).
# Cluster #1 will be "west" and cluster #2 will be "east".
#
# If you are using minikube, this script will start 2 minikube clusters.
# If you are using OpenShift, you are responsible for starting the two
# clusters and telling this script how to connect to those clusters
Expand All @@ -35,6 +39,9 @@ infomsg() {
CLUSTER1_ISTIO="istio"
CLUSTER2_DB="db"

NAMESPACE_WEST="west"
NAMESPACE_EAST="east"

# Some defaults

SCRIPT_DIR="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)"
Expand All @@ -44,6 +51,7 @@ OUTPUT_DIR="${ROOT_DIR}/_output"
CLIENT_EXE="kubectl"
CLUSTER_TYPE="minikube"
HACK_SCRIPTS_DIR="${ROOT_DIR}/hack"
INSTALL_EAST_WEST_DEMO="false"
KIALI_DEV_BUILD="true"
KIALI_VERSION="dev"
MONGONS="mongons"
Expand Down Expand Up @@ -75,6 +83,7 @@ while [ $# -gt 0 ]; do
sui) _CMD="sui" ;shift ;;
-c|--client) CLIENT_EXE="$2" ;shift;shift ;;
-ct|--cluster-type) CLUSTER_TYPE="$2" ;shift;shift ;;
-ewd|--east-west-demo) INSTALL_EAST_WEST_DEMO="$2" ;shift;shift ;;
-kdb|--kiali-dev-build) KIALI_DEV_BUILD="$2" ;shift;shift ;;
-kv|--kiali-version) KIALI_VERSION="$2" ;shift;shift ;;
-os1a|--openshift1-api) OPENSHIFT1_API="$2" ;shift;shift ;;
Expand All @@ -92,6 +101,8 @@ Valid command line arguments:
If "minikube", this script creates its own clusters.
If "openshift", the clusters must be started already.
Default: "minikube"
-ewd|--east-west-demo [true|false]: If "true" the basic Skupper demo is also installed, too.
Default: "false"
-kdb|--kiali-dev-build [true|false]: If "true" and --kiali-version is "dev", a dev image will be
built. If "false" and --kiali-version is "dev", you must
have previously built a dev image prior to running this script.
Expand All @@ -115,7 +126,7 @@ Valid command line arguments:
-h|--help : This message.
Valid commands:
install: Installs the demo that consists of Istio, Kiali, Bookinfo demo, and Skupper.
install: Installs the Istio/Kiali/Bookinfo/Skupper demo (and optionally the east-west demo)
delete: Uninstalls the demo by shutting down the two minikube clusters
iprom: Open a browser window to the Istio Prometheus UI
kui: Open a browser window to the Kiali UI
Expand Down Expand Up @@ -385,6 +396,52 @@ openshift_install_skupper() {
${CLIENT_EXE} -n ${MONGOSKUPPERNS} expose svc skupper-prometheus
}

minikube_install_east_west_demo() {
infomsg "Installing East-West Demo..."

${CLIENT_EXE} --context ${CLUSTER1_ISTIO} create namespace ${NAMESPACE_WEST}
${CLIENT_EXE} --context ${CLUSTER2_DB} create namespace ${NAMESPACE_EAST}

${SKUPPER_EXE} --context ${CLUSTER1_ISTIO} -n ${NAMESPACE_WEST} init --enable-console --enable-flow-collector
${SKUPPER_EXE} --context ${CLUSTER2_DB} -n ${NAMESPACE_EAST} init

rm -r "${SKUPPER_TOKEN_FILE}"
${SKUPPER_EXE} --context ${CLUSTER1_ISTIO} -n ${NAMESPACE_WEST} token create "${SKUPPER_TOKEN_FILE}"
${SKUPPER_EXE} --context ${CLUSTER2_DB} -n ${NAMESPACE_EAST} link create "${SKUPPER_TOKEN_FILE}"

${CLIENT_EXE} --context ${CLUSTER1_ISTIO} -n ${NAMESPACE_WEST} create deployment frontend --image quay.io/skupper/hello-world-frontend
${CLIENT_EXE} --context ${CLUSTER2_DB} -n ${NAMESPACE_EAST} create deployment backend --image quay.io/skupper/hello-world-backend --replicas 3

# expose with http protocol
${SKUPPER_EXE} --context ${CLUSTER2_DB} -n ${NAMESPACE_EAST} expose deployment/backend --port 8080 --protocol http
${CLIENT_EXE} --context ${CLUSTER1_ISTIO} -n ${NAMESPACE_WEST} expose deployment frontend --port 8080 --type LoadBalancer

infomsg "East-West Demo installed."
}

openshift_install_east_west_demo() {
infomsg "Installing East-West Demo..."

openshift_login ${CLUSTER1_ISTIO} && ${CLIENT_EXE} create namespace ${NAMESPACE_WEST}
openshift_login ${CLUSTER2_DB} && ${CLIENT_EXE} create namespace ${NAMESPACE_EAST}

openshift_login ${CLUSTER1_ISTIO} && ${SKUPPER_EXE} -n ${NAMESPACE_WEST} init --enable-console --enable-flow-collector
openshift_login ${CLUSTER2_DB} && ${SKUPPER_EXE} -n ${NAMESPACE_EAST} init

rm -r "${SKUPPER_TOKEN_FILE}"
openshift_login ${CLUSTER1_ISTIO} && ${SKUPPER_EXE} -n ${NAMESPACE_WEST} token create "${SKUPPER_TOKEN_FILE}"
openshift_login ${CLUSTER2_DB} && ${SKUPPER_EXE} -n ${NAMESPACE_EAST} link create "${SKUPPER_TOKEN_FILE}"

openshift_login ${CLUSTER1_ISTIO} && ${CLIENT_EXE} -n ${NAMESPACE_WEST} create deployment frontend --image quay.io/skupper/hello-world-frontend
openshift_login ${CLUSTER2_DB} && ${CLIENT_EXE} -n ${NAMESPACE_EAST} create deployment backend --image quay.io/skupper/hello-world-backend --replicas 3

# expose with http protocol - still logged into cluster 2
${SKUPPER_EXE} -n ${NAMESPACE_EAST} expose deployment/backend --port 8080 --protocol http
openshift_login ${CLUSTER1_ISTIO} && ${CLIENT_EXE} -n ${NAMESPACE_WEST} expose deployment frontend --port 8080 --type LoadBalancer

infomsg "East-West Demo installed."
}

confirm_cluster_is_up() {
local cluster_name="${1}"

Expand Down Expand Up @@ -493,15 +550,21 @@ if [ "$_CMD" == "install" ]; then

case ${CLUSTER_TYPE} in
minikube)
infomsg "Installing demo on minikube"
infomsg "Installing Istio/Kiali/Bookinfo demo on minikube"
minikube_install_basic_demo
minikube_install_skupper
if [ "${INSTALL_EAST_WEST_DEMO}" == "true" ]; then
minikube_install_east_west_demo
fi
;;

openshift)
infomsg "Installing demo on OpenShift"
infomsg "Installing Istio/Kiali/Bookinfo demo on OpenShift"
openshift_install_basic_demo
openshift_install_skupper
if [ "${INSTALL_EAST_WEST_DEMO}" == "true" ]; then
openshift_install_east_west_demo
fi
;;

*) errormsg "Invalid cluster type" && exit 1 ;;
Expand Down Expand Up @@ -533,12 +596,18 @@ elif [ "$_CMD" == "delete" ]; then
infomsg "Uninstalling Skupper pipe ..."
${CLIENT_EXE} get namespace ${MONGOSKUPPERNS} && ${CLIENT_EXE} delete namespace ${MONGOSKUPPERNS}

infomsg "Uninstalling ${NAMESPACE_WEST} namespace ..."
${CLIENT_EXE} get namespace ${NAMESPACE_WEST} && ${CLIENT_EXE} delete namespace ${NAMESPACE_WEST}

# LOGIN TO CLUSTER 2
openshift_login ${CLUSTER2_DB}

infomsg "Uninstalling the databases ..."
${CLIENT_EXE} get namespace ${MYSQLNS} && ${CLIENT_EXE} delete namespace ${MYSQLNS}
${CLIENT_EXE} get namespace ${MONGONS} && ${CLIENT_EXE} delete namespace ${MONGONS}

infomsg "Uninstalling ${NAMESPACE_EAST} namespace ..."
${CLIENT_EXE} get namespace ${NAMESPACE_EAST} && ${CLIENT_EXE} delete namespace ${NAMESPACE_EAST}
;;

*) errormsg "Invalid cluster type" && exit 1 ;;
Expand Down Expand Up @@ -610,6 +679,15 @@ elif [ "$_CMD" == "sstatus" ]; then
*) errormsg "Invalid cluster type" && exit 1 ;;
esac

if ${CLIENT_EXE} --context ${CLUSTER1_ISTIO} -n ${NAMESPACE_WEST} get service/frontend &>/dev/null; then
case ${CLUSTER_TYPE} in
minikube) east_west_demo_url="http://$(${CLIENT_EXE} --context ${CLUSTER1_ISTIO} -n ${NAMESPACE_WEST} get service/frontend -o jsonpath={.status.loadBalancer.ingress[0].ip}):8080" ;;
openshift) east_west_demo_url="http://$(${CLIENT_EXE} -n ${NAMESPACE_WEST} get service/frontend -o jsonpath={.status.loadBalancer.ingress[0].ip}):8080" ;;
*) errormsg "Invalid cluster type" && exit 1 ;;
esac
infomsg "East-West Demo Frontend App: ${east_west_demo_url}"
fi

elif [ "$_CMD" == "sui" ]; then

confirm_cluster_is_up "${CLUSTER1_ISTIO}"
Expand Down

0 comments on commit fad4799

Please sign in to comment.