From df4a9a99ef43ee4629c2cfca686267d7b047ce00 Mon Sep 17 00:00:00 2001 From: TannerGabriel Date: Mon, 13 Dec 2021 10:48:20 +0100 Subject: [PATCH 1/2] Check OS for open command Signed-off-by: TannerGabriel --- quickstart/expose-keptn.sh | 13 ++++++++++--- quickstart/multistage-delivery.sh | 10 ++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/quickstart/expose-keptn.sh b/quickstart/expose-keptn.sh index 2a43e21..4b46758 100755 --- a/quickstart/expose-keptn.sh +++ b/quickstart/expose-keptn.sh @@ -121,13 +121,20 @@ do # echo "retries: $retries / $MAX_RETRIES" if [ ${http_code} -eq 200 ]; then echo "Attempting to open Keptn bridge on http://$INGRESS_IP.nip.io:$INGRESS_PORT/bridge" - if ! command -v open &> /dev/null + + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + OPEN=('xdg-open') + else + OPEN=('open') + fi + + if ! command -v "${OPEN[@]}" &> /dev/null then echo "Open command not found. Printing connection details instead" + echo http://$INGRESS_IP.nip.io:$INGRESS_PORT/bridge break else - open http://$INGRESS_IP.nip.io:$INGRESS_PORT/bridge - break + "${OPEN[@]}" http://$INGRESS_IP.nip.io:$INGRESS_PORT/bridge fi fi echo "Keptn bridge not yet available, waiting $SLEEP_TIME seconds and then trying again" diff --git a/quickstart/multistage-delivery.sh b/quickstart/multistage-delivery.sh index 0e24e72..2670073 100755 --- a/quickstart/multistage-delivery.sh +++ b/quickstart/multistage-delivery.sh @@ -199,11 +199,17 @@ echo "Attempt to open Keptn Bridge in 5 seconds..." echo "Demo setup will continue in the background while you can explore the Keptn Bridge..." sleep 5 -if ! command -v open &> /dev/null +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + OPEN=('xdg-open') +else + OPEN=('open') +fi + +if ! command -v "${OPEN[@]}" &> /dev/null then echo http://$INGRESS_IP.nip.io:$INGRESS_PORT/bridge/project/podtatohead/sequence else - open http://$INGRESS_IP.nip.io:$INGRESS_PORT/bridge/project/podtatohead/sequence + "${OPEN[@]}" http://$INGRESS_IP.nip.io:$INGRESS_PORT/bridge/project/podtatohead/sequence fi From 13ac311e7550504790a63258fe117fc4e4d93b59 Mon Sep 17 00:00:00 2001 From: TannerGabriel Date: Thu, 16 Dec 2021 19:08:20 +0100 Subject: [PATCH 2/2] Fix bash file formatting Signed-off-by: TannerGabriel --- quickstart/multistage-delivery.sh | 118 +++++++++++++++--------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/quickstart/multistage-delivery.sh b/quickstart/multistage-delivery.sh index 2670073..7205f82 100755 --- a/quickstart/multistage-delivery.sh +++ b/quickstart/multistage-delivery.sh @@ -10,78 +10,78 @@ SLOW_VERSION=v0.1.2 #source <(curl -s https://raw.githubusercontent.com/keptn/keptn/0.8.5/test/utils.sh) function print_headline() { - HEADLINE=$1 - - echo "" - echo "---------------------------------------------------------------------" - echo $HEADLINE - echo "---------------------------------------------------------------------" - echo "" + HEADLINE=$1 + + echo "" + echo "---------------------------------------------------------------------" + echo $HEADLINE + echo "---------------------------------------------------------------------" + echo "" } function verify_helm_installation(){ - if ! command -v helm &> /dev/null - then - echo "Could not find helm. Please install helm to proceed further." - exit - fi + if ! command -v helm &> /dev/null + then + echo "Could not find helm. Please install helm to proceed further." + exit + fi } function print_error() { - echo "::error file=${BASH_SOURCE[1]##*/},line=${BASH_LINENO[0]}::$(timestamp) ${*}" + echo "::error file=${BASH_SOURCE[1]##*/},line=${BASH_LINENO[0]}::$(timestamp) ${*}" } function verify_test_step() { - if [[ $1 != '0' ]]; then - print_error "$2" - print_error "Keptn test step failed" - exit 1 - fi + if [[ $1 != '0' ]]; then + print_error "$2" + print_error "Keptn test step failed" + exit 1 + fi } function verify_namespace_exists() { - NAMESPACE=$1; - - NAMESPACE_LIST=$(eval "kubectl get namespaces -L istio-injection | grep ${NAMESPACE} | awk '/$NAMESPACE/'" | awk '{print $1}') - - if [[ -z "$NAMESPACE_LIST" ]]; then - print_error "Could not find namespace ${NAMESPACE}" - exit 2 - else - echo "Found namespace ${NAMESPACE}" - fi + NAMESPACE=$1; + + NAMESPACE_LIST=$(eval "kubectl get namespaces -L istio-injection | grep ${NAMESPACE} | awk '/$NAMESPACE/'" | awk '{print $1}') + + if [[ -z "$NAMESPACE_LIST" ]]; then + print_error "Could not find namespace ${NAMESPACE}" + exit 2 + else + echo "Found namespace ${NAMESPACE}" + fi } # wait for a deployment to be up and running function wait_for_deployment_in_namespace() { - DEPLOYMENT=$1; NAMESPACE=$2; - RETRY=0; RETRY_MAX=10; - - while [[ $RETRY -lt $RETRY_MAX ]]; do - DEPLOYMENT_LIST=$(eval "kubectl get deployments -n ${NAMESPACE} | awk '/$DEPLOYMENT /'" | awk '{print $1}') # list of multiple deployments when starting with the same name - if [[ -z "$DEPLOYMENT_LIST" ]]; then - RETRY=$((RETRY+1)) - echo "Retry: ${RETRY}/${RETRY_MAX} - Deployment not found - waiting 15s for deployment ${DEPLOYMENT} in namespace ${NAMESPACE}" - sleep 15 - else - READY_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.status.availableReplicas}') - WANTED_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.spec.replicas}') - UNAVAILABLE_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.status.unavailableReplicas}') - if [[ "$READY_REPLICAS" = "$WANTED_REPLICAS" && "$UNAVAILABLE_REPLICAS" = "" ]]; then - echo "Found deployment ${DEPLOYMENT} in namespace ${NAMESPACE}: ${DEPLOYMENT_LIST}" - break - else - RETRY=$((RETRY+1)) - echo "Retry: ${RETRY}/${RETRY_MAX} - Unsufficient replicas for deployment - waiting 15s for deployment ${DEPLOYMENT} in namespace ${NAMESPACE}" - sleep 15 - fi + DEPLOYMENT=$1; NAMESPACE=$2; + RETRY=0; RETRY_MAX=10; + + while [[ $RETRY -lt $RETRY_MAX ]]; do + DEPLOYMENT_LIST=$(eval "kubectl get deployments -n ${NAMESPACE} | awk '/$DEPLOYMENT /'" | awk '{print $1}') # list of multiple deployments when starting with the same name + if [[ -z "$DEPLOYMENT_LIST" ]]; then + RETRY=$((RETRY+1)) + echo "Retry: ${RETRY}/${RETRY_MAX} - Deployment not found - waiting 15s for deployment ${DEPLOYMENT} in namespace ${NAMESPACE}" + sleep 15 + else + READY_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.status.availableReplicas}') + WANTED_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.spec.replicas}') + UNAVAILABLE_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.status.unavailableReplicas}') + if [[ "$READY_REPLICAS" = "$WANTED_REPLICAS" && "$UNAVAILABLE_REPLICAS" = "" ]]; then + echo "Found deployment ${DEPLOYMENT} in namespace ${NAMESPACE}: ${DEPLOYMENT_LIST}" + break + else + RETRY=$((RETRY+1)) + echo "Retry: ${RETRY}/${RETRY_MAX} - Unsufficient replicas for deployment - waiting 15s for deployment ${DEPLOYMENT} in namespace ${NAMESPACE}" + sleep 15 + fi + fi + done + + if [[ $RETRY == "$RETRY_MAX" ]]; then + print_error "Could not find deployment ${DEPLOYMENT} in namespace ${NAMESPACE}" + exit 1 fi - done - - if [[ $RETRY == "$RETRY_MAX" ]]; then - print_error "Could not find deployment ${DEPLOYMENT} in namespace ${NAMESPACE}" - exit 1 - fi } @@ -89,7 +89,7 @@ INGRESS_PORT=$1 INGRESS_IP=127.0.0.1 if [ -z "$INGRESS_PORT" ]; then - INGRESS_PORT=8082 + INGRESS_PORT=8082 fi @@ -108,7 +108,7 @@ verify_test_step $? "keptn create project command failed." print_headline "Create a Keptn service" echo "keptn create service $SERVICE --project=${PROJECT} " -keptn create service $SERVICE --project="${PROJECT}" +keptn create service $SERVICE --project="${PROJECT}" print_headline "Add Helm chart for $SERVICE" keptn add-resource --project=$PROJECT --service=$SERVICE --all-stages --resource=./demo/helm/helloservice.tgz --resourceUri=helm/helloservice.tgz @@ -207,9 +207,9 @@ fi if ! command -v "${OPEN[@]}" &> /dev/null then - echo http://$INGRESS_IP.nip.io:$INGRESS_PORT/bridge/project/podtatohead/sequence + echo http://$INGRESS_IP.nip.io:$INGRESS_PORT/bridge/project/podtatohead/sequence else - "${OPEN[@]}" http://$INGRESS_IP.nip.io:$INGRESS_PORT/bridge/project/podtatohead/sequence + "${OPEN[@]}" http://$INGRESS_IP.nip.io:$INGRESS_PORT/bridge/project/podtatohead/sequence fi