Skip to content

Commit

Permalink
Merge pull request openservicemesh#2431 from snehachhabria/updateRout…
Browse files Browse the repository at this point in the history
…esv2Demo

ref(*): Update demo scripts for routes v2
  • Loading branch information
snehachhabria authored Feb 1, 2021
2 parents 85e16b2 + aa87ede commit f18569e
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 39 deletions.
6 changes: 6 additions & 0 deletions demo/deploy-bookbuyer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ CI_MAX_ITERATIONS_THRESHOLD="${CI_MAX_ITERATIONS_THRESHOLD:-0}"
CI_CLIENT_CONCURRENT_CONNECTIONS="${CI_CLIENT_CONCURRENT_CONNECTIONS:-1}"
ENABLE_EGRESS="${ENABLE_EGRESS:-false}"
CI_SLEEP_BETWEEN_REQUESTS_SECONDS="${CI_SLEEP_BETWEEN_REQUESTS_SECONDS:-1}"
ROUTES_V2="${ROUTES_V2:-false}"

if [ "$ROUTES_V2" = "true" ]; then
BOOKSTORE_SVC=bookstore-v1
fi

kubectl delete deployment bookbuyer -n "$BOOKBUYER_NAMESPACE" --ignore-not-found

Expand Down Expand Up @@ -52,6 +57,7 @@ spec:
selector:
matchLabels:
app: bookbuyer
version: v1
template:
metadata:
labels:
Expand Down
3 changes: 3 additions & 0 deletions demo/deploy-bookstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ set -aueo pipefail
source .env
VERSION=${1:-v1}
SVC="bookstore-$VERSION"
ROUTES_V2="${ROUTES_V2:-false}"

kubectl delete deployment "$SVC" -n "$BOOKSTORE_NAMESPACE" --ignore-not-found

# Create a top level service just for the bookstore domain
if [ "$ROUTES_V2" = "false" ]; then
echo -e "Deploy bookstore Service"
kubectl apply -f - <<EOF
apiVersion: v1
Expand All @@ -26,6 +28,7 @@ spec:
selector:
app: bookstore
EOF
fi

echo -e "Deploy $SVC Service Account"
kubectl apply -f - <<EOF
Expand Down
File renamed without changes.
33 changes: 33 additions & 0 deletions demo/ingress/deploy-ingress-nginx-with-host.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash



# This script deploys a Kubernetes Ingress resource for Nginx.
# This is a helper script used to ease the demonstration of OSM.



set -aueo pipefail

# shellcheck disable=SC1091
source .env

echo "Create Bookstore Ingress Resource"
kubectl apply -f - <<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: bookstore-v1
namespace: $BOOKSTORE_NAMESPACE
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: bookstore-v1.$BOOKSTORE_NAMESPACE.svc.cluster.local
http:
paths:
- path: /books-bought
backend:
serviceName: bookstore-v1
servicePort: 80
EOF
33 changes: 33 additions & 0 deletions demo/ingress/deploy-ingress-nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash



# This script deploys a Kubernetes Ingress resource for Nginx.
# This is a helper script used to ease the demonstration of OSM.



set -aueo pipefail

# shellcheck disable=SC1091
source .env


echo "Create Bookstore Ingress Resource"
kubectl apply -f - <<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: bookstore-v1
namespace: $BOOKSTORE_NAMESPACE
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- http:
paths:
- path: /books-bought
backend:
serviceName: bookstore-v1
servicePort: 80
EOF
39 changes: 8 additions & 31 deletions experimental/routes_refactor/demo/manifests/traffic-access.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ spec:
pathRegex: ".*a-book.*new"
methods:
- GET
- name: update-books-bought
pathRegex: /update-books-bought
methods:
- POST
---
kind: TrafficTarget
apiVersion: access.smi-spec.io/v1alpha3
Expand All @@ -58,34 +62,7 @@ spec:
- kind: ServiceAccount
name: bookbuyer
namespace: bookbuyer
---
apiVersion: specs.smi-spec.io/v1alpha4
kind: HTTPRouteGroup
metadata:
name: bookstore-service-routes
namespace: bookstore
spec:
matches:
- name: books-bought
pathRegex: /books-bought
methods:
- GET
- name: buy-a-book
pathRegex: ".*a-book.*new"
methods:
- GET
- name: update-books-bought
pathRegex: /update-books-bought
methods:
- POST
---
apiVersion: specs.smi-spec.io/v1alpha4
kind: HTTPRouteGroup
metadata:
name: bookwarehouse-service-routes
namespace: bookwarehouse
spec:
matches:
- name: restock-books
methods:
- POST
#- kind: ServiceAccount
#name: bookthief
#namespace: bookthief
---
158 changes: 158 additions & 0 deletions experimental/routes_refactor/demo/run-osm-demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#!/bin/bash

set -aueo pipefail

if [ ! -f .env ]; then
echo -e "\nThere is no .env file in the root of this repository."
echo -e "Copy the values from .env.example into .env."
echo -e "Modify the values in .env to match your setup.\n"
echo -e " cat .env.example > .env\n\n"
exit 1
fi

# shellcheck disable=SC1091
source .env

# Set meaningful defaults for env vars we expect from .env
CI="${CI:-false}" # This is set to true by Github Actions
MESH_NAME="${MESH_NAME:-osm}"
K8S_NAMESPACE="${K8S_NAMESPACE:-osm-system}"
BOOKBUYER_NAMESPACE="${BOOKBUYER_NAMESPACE:-bookbuyer}"
BOOKSTORE_NAMESPACE="${BOOKSTORE_NAMESPACE:-bookstore}"
BOOKTHIEF_NAMESPACE="${BOOKTHIEF_NAMESPACE:-bookthief}"
BOOKWAREHOUSE_NAMESPACE="${BOOKWAREHOUSE_NAMESPACE:-bookwarehouse}"
CERT_MANAGER="${CERT_MANAGER:-tresor}"
CTR_REGISTRY="${CTR_REGISTRY:-localhost:5000}"
CTR_REGISTRY_CREDS_NAME="${CTR_REGISTRY_CREDS_NAME:-acr-creds}"
DEPLOY_TRAFFIC_SPLIT="${DEPLOY_TRAFFIC_SPLIT:-true}"
CTR_TAG="${CTR_TAG:-$(git rev-parse HEAD)}"
IMAGE_PULL_POLICY="${IMAGE_PULL_POLICY:-Always}"
ENABLE_DEBUG_SERVER="${ENABLE_DEBUG_SERVER:-true}"
ENABLE_EGRESS="${ENABLE_EGRESS:-false}"
DEPLOY_GRAFANA="${DEPLOY_GRAFANA:-true}"
DEPLOY_JAEGER="${DEPLOY_JAEGER:-true}"
ENABLE_FLUENTBIT="${ENABLE_FLUENTBIT:-false}"
DEPLOY_PROMETHEUS="${DEPLOY_PROMETHEUS:-true}"
ENABLE_PROMETHEUS_SCRAPING="${ENABLE_PROMETHEUS_SCRAPING:-true}"
DEPLOY_WITH_SAME_SA="${DEPLOY_WITH_SAME_SA:-false}"
ENVOY_LOG_LEVEL="${ENVOY_LOG_LEVEL:-debug}"
ROUTES_V2="${ROUTES_V2:-false}"

# For any additional installation arguments. Used heavily in CI.
optionalInstallArgs=$*

exit_error() {
error="$1"
echo "$error"
exit 1
}

# Check if Docker daemon is running
docker info > /dev/null || { echo "Docker daemon is not running"; exit 1; }

make build-osm

# cleanup stale resources from previous runs
./demo/clean-kubernetes.sh

# The demo uses osm's namespace as defined by environment variables, K8S_NAMESPACE
# to house the control plane components.
#
# Note: `osm install` creates the namespace via Helm only if such a namespace already
# doesn't exist. We explicitly create the namespace below because of the need to
# create container registry credentials in this namespace for the purpose of testing.
# The side effect of creating the namespace here instead of letting Helm create it is
# that Helm no longer manages namespace creation, and as a result labels that it
# otherwise adds for using as a namespace selector are no longer available.
kubectl create namespace "$K8S_NAMESPACE"
# Mimic Helm namespace label behavior: https://github.com/helm/helm/blob/release-3.2/pkg/action/install.go#L292
kubectl label namespace "$K8S_NAMESPACE" name="$K8S_NAMESPACE"

echo "Certificate Manager in use: $CERT_MANAGER"
if [ "$CERT_MANAGER" = "vault" ]; then
echo "Installing Hashi Vault"
./demo/deploy-vault.sh
fi

if [ "$CERT_MANAGER" = "cert-manager" ]; then
echo "Installing cert-manager"
./demo/deploy-cert-manager.sh
fi

make docker-push
./scripts/create-container-registry-creds.sh "$K8S_NAMESPACE"

# Deploys Xds and Prometheus
echo "Certificate Manager in use: $CERT_MANAGER"
if [ "$CERT_MANAGER" = "vault" ]; then
# shellcheck disable=SC2086
bin/osm install \
--osm-namespace "$K8S_NAMESPACE" \
--mesh-name "$MESH_NAME" \
--certificate-manager="$CERT_MANAGER" \
--vault-host="$VAULT_HOST" \
--vault-token="$VAULT_TOKEN" \
--vault-protocol="$VAULT_PROTOCOL" \
--container-registry "$CTR_REGISTRY" \
--container-registry-secret "$CTR_REGISTRY_CREDS_NAME" \
--osm-image-tag "$CTR_TAG" \
--osm-image-pull-policy "$IMAGE_PULL_POLICY" \
--enable-debug-server="$ENABLE_DEBUG_SERVER" \
--enable-egress="$ENABLE_EGRESS" \
--deploy-grafana="$DEPLOY_GRAFANA" \
--deploy-jaeger="$DEPLOY_JAEGER" \
--enable-fluentbit="$ENABLE_FLUENTBIT" \
--deploy-prometheus="$DEPLOY_PROMETHEUS" \
--enable-prometheus-scraping="$ENABLE_PROMETHEUS_SCRAPING" \
--envoy-log-level "$ENVOY_LOG_LEVEL" \
--timeout=90s \
--enable-routes-v2-experimental="$ROUTES_V2"
$optionalInstallArgs
else
# shellcheck disable=SC2086
bin/osm install \
--osm-namespace "$K8S_NAMESPACE" \
--mesh-name "$MESH_NAME" \
--certificate-manager="$CERT_MANAGER" \
--container-registry "$CTR_REGISTRY" \
--container-registry-secret "$CTR_REGISTRY_CREDS_NAME" \
--osm-image-tag "$CTR_TAG" \
--osm-image-pull-policy "$IMAGE_PULL_POLICY" \
--enable-debug-server="$ENABLE_DEBUG_SERVER"\
--enable-egress="$ENABLE_EGRESS" \
--deploy-grafana="$DEPLOY_GRAFANA" \
--deploy-jaeger="$DEPLOY_JAEGER" \
--enable-fluentbit="$ENABLE_FLUENTBIT" \
--deploy-prometheus="$DEPLOY_PROMETHEUS" \
--enable-prometheus-scraping="$ENABLE_PROMETHEUS_SCRAPING" \
--envoy-log-level "$ENVOY_LOG_LEVEL" \
--timeout=90s \
--enable-routes-v2-experimental="$ROUTES_V2"
$optionalInstallArgs
fi

if [ "$ROUTES_V2" = "true" ]; then
./demo/configure-app-namespaces.sh
./demo/deploy-apps.sh
kubectl apply -f ./experimental/routes_refactor/demo/manifests/traffic-access.yaml
else
./demo/configure-app-namespaces.sh

./demo/deploy-apps.sh
# Apply SMI policies
if [ "$DEPLOY_TRAFFIC_SPLIT" = "true" ]; then
./demo/deploy-traffic-split.sh
fi

./demo/deploy-traffic-specs.sh

if [ "$DEPLOY_WITH_SAME_SA" = "true" ]; then
./demo/deploy-traffic-target-with-same-sa.sh
else
./demo/deploy-traffic-target.sh
fi
fi

if [[ "$CI" != "true" ]]; then
watch -n5 "printf \"Namespace ${K8S_NAMESPACE}:\n\"; kubectl get pods -n ${K8S_NAMESPACE} -o wide; printf \"\n\n\"; printf \"Namespace ${BOOKBUYER_NAMESPACE}:\n\"; kubectl get pods -n ${BOOKBUYER_NAMESPACE} -o wide; printf \"\n\n\"; printf \"Namespace ${BOOKSTORE_NAMESPACE}:\n\"; kubectl get pods -n ${BOOKSTORE_NAMESPACE} -o wide; printf \"\n\n\"; printf \"Namespace ${BOOKTHIEF_NAMESPACE}:\n\"; kubectl get pods -n ${BOOKTHIEF_NAMESPACE} -o wide; printf \"\n\n\"; printf \"Namespace ${BOOKWAREHOUSE_NAMESPACE}:\n\"; kubectl get pods -n ${BOOKWAREHOUSE_NAMESPACE} -o wide"
fi
16 changes: 8 additions & 8 deletions experimental/routes_refactor/demo/scripts/port-forward-all.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

./scripts/port-forward-bookbuyer-ui.sh &
./scripts/port-forward-bookstore-ui-v1.sh &
./scripts/port-forward-bookstore-ui-v2.sh &
./scripts/port-forward-bookthief-ui.sh &
./experimental/routes_refactor/demo/scripts/port-forward-bookbuyer-ui.sh &
./experimental/routes_refactor/demo/scripts/port-forward-bookstore-ui-v1.sh &
./experimental/routes_refactor/demo/scripts/port-forward-bookstore-ui-v2.sh &
./experimental/routes_refactor/demo/scripts/port-forward-bookthief-ui.sh &

./scripts/port-forward-bookbuyer-envoy.sh &
./scripts/port-forward-bookstore-v1-envoy.sh &
./scripts/port-forward-bookstore-v2-envoy.sh &
./scripts/port-forward-bookthief-envoy.sh &
./experimental/routes_refactor/demo/scripts/port-forward-bookbuyer-envoy.sh &
./experimental/routes_refactor/demo/scripts/port-forward-bookstore-v1-envoy.sh &
./experimental/routes_refactor/demo/scripts/port-forward-bookstore-v2-envoy.sh &
./experimental/routes_refactor/demo/scripts/port-forward-bookthief-envoy.sh &

wait
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# shellcheck disable=SC1091
source .env

BOOKBUYER_LOCAL_PORT="${BOOKBUYER_LOCAL_PORT:-8080}"
POD="$(kubectl get pods --selector app=bookbuyer -n "$BOOKBUYER_NAMESPACE" --no-headers | grep 'Running' | awk '{print $1}')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


# shellcheck disable=SC1091
source .env

BOOKBUYER_LOCAL_PORT="${BOOKBUYER_LOCAL_PORT:-8080}"
POD="$(kubectl get pods --selector app=bookbuyer -n "$BOOKBUYER_NAMESPACE" --no-headers | grep 'Running' | awk '{print $1}')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


# shellcheck disable=SC1091
source .env

BOOKSTOREv1_LOCAL_PORT="${BOOKSTOREv1_LOCAL_PORT:-8081}"
POD="$(kubectl get pods --selector app=bookstore --selector version=v1 -n "$BOOKSTORE_NAMESPACE" --no-headers | grep 'Running' | awk '{print $1}')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


# shellcheck disable=SC1091
source .env

BOOKSTOREv1_LOCAL_PORT="${BOOKSTOREv1_LOCAL_PORT:-8082}"
POD="$(kubectl get pods --selector app=bookstore --selector version=v2 -n "$BOOKSTORE_NAMESPACE" --no-headers | grep 'Running' | awk '{print $1}')"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# shellcheck disable=SC1091
source .env

BOOKSTOREv1_LOCAL_PORT="${BOOKSTOREv1_LOCAL_PORT:-8081}"
POD="$(kubectl get pods --selector app=bookstore --selector version=v1 -n "$BOOKSTORE_NAMESPACE" --no-headers | grep 'Running' | awk '{print $1}')"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# shellcheck disable=SC1091
source .env

BOOKSTOREv1_LOCAL_PORT="${BOOKSTOREv1_LOCAL_PORT:-8082}"
POD="$(kubectl get pods --selector app=bookstore --selector version=v2 -n "$BOOKSTORE_NAMESPACE" --no-headers | grep 'Running' | awk '{print $1}')"
Expand Down
Loading

0 comments on commit f18569e

Please sign in to comment.