From 2340a0ee51af78f68c67b32c58d713071f5532b2 Mon Sep 17 00:00:00 2001 From: Andreas Grimmer Date: Fri, 24 Jul 2020 13:28:05 +0200 Subject: [PATCH 1/8] Fix selector --- onboarding-carts/manifests/manifest-carts-db.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onboarding-carts/manifests/manifest-carts-db.yaml b/onboarding-carts/manifests/manifest-carts-db.yaml index 11d85ca..24f4663 100644 --- a/onboarding-carts/manifests/manifest-carts-db.yaml +++ b/onboarding-carts/manifests/manifest-carts-db.yaml @@ -55,4 +55,4 @@ spec: port: 27017 targetPort: 27017 selector: - name: carts-db + app: carts-db From 90f75823edff11d5100a011cbd2648c780c58eb5 Mon Sep 17 00:00:00 2001 From: TannerGabriel Date: Fri, 7 Aug 2020 13:24:57 +0200 Subject: [PATCH 2/8] Dynatrace oneagent and istio automated configuration scripts --- .../deploy-dynatrace-oneagent.sh | 47 ++++++++++++++++ istio-configuration/configure-istio.sh | 54 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100755 dynatrace-oneagent/deploy-dynatrace-oneagent.sh create mode 100644 istio-configuration/configure-istio.sh diff --git a/dynatrace-oneagent/deploy-dynatrace-oneagent.sh b/dynatrace-oneagent/deploy-dynatrace-oneagent.sh new file mode 100755 index 0000000..7588d52 --- /dev/null +++ b/dynatrace-oneagent/deploy-dynatrace-oneagent.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +if [ -z "$DT_TENANT" ]; then + echo "Please supply a value for the environment variable DT_TENANT" + exit 1 +fi + +if [ -z "$DT_API_TOKEN" ]; then + echo "Please supply a value for the environment variable DT_API_TOKEN" + exit 1 +fi + +if [ -z "$DT_PAAS_TOKEN" ]; then + echo "Please supply a value for the environment variable DT_PAAS_TOKEN" + exit 1 +fi + +function replace_value_in_yaml_file() { + OLDVAL=$1; NEWVAL=$2; FILE=$3 + + sed -i "s#$OLDVAL#$NEWVAL#g" $FILE +} + +kubectl create namespace dynatrace +sleep 10 + +kubectl apply -f https://github.com/Dynatrace/dynatrace-oneagent-operator/releases/latest/download/kubernetes.yaml + +echo "Waiting a little bit before we continue..." +sleep 30 +echo "Continuing now!" + +kubectl -n dynatrace create secret generic oneagent --from-literal="apiToken=$DT_API_TOKEN" --from-literal="paasToken=$DT_PAAS_TOKEN" + +curl -o cr.yaml https://raw.githubusercontent.com/Dynatrace/dynatrace-oneagent-operator/master/deploy/cr.yaml + +export URL=$(echo https://ENVIRONMENTID.live.dynatrace.com/api) +export API_URL=$(echo https://${DT_TENANT}/api) +replace_value_in_yaml_file $URL $API_URL cr.yaml + +kubectl apply -f cr.yaml + +echo "Waiting a little bit before we continue..." +sleep 20 +echo "Continuing now!" + +rm cr.yaml \ No newline at end of file diff --git a/istio-configuration/configure-istio.sh b/istio-configuration/configure-istio.sh new file mode 100644 index 0000000..7d859c8 --- /dev/null +++ b/istio-configuration/configure-istio.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +echo "Configure Istio and Keptn" + +# Get Ingress gateway IP-Address +export INGRESS_IP=$(kubectl -n istio-system get svc istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + +# Applying ingress-manifest +kubectl apply -f - < Date: Mon, 10 Aug 2020 10:15:59 +0200 Subject: [PATCH 3/8] Added better verification steps to dynatrace oneagent installation --- .../deploy-dynatrace-oneagent.sh | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/dynatrace-oneagent/deploy-dynatrace-oneagent.sh b/dynatrace-oneagent/deploy-dynatrace-oneagent.sh index 7588d52..40c6557 100755 --- a/dynatrace-oneagent/deploy-dynatrace-oneagent.sh +++ b/dynatrace-oneagent/deploy-dynatrace-oneagent.sh @@ -21,27 +21,57 @@ function replace_value_in_yaml_file() { sed -i "s#$OLDVAL#$NEWVAL#g" $FILE } +function wait_for_deployment_in_namespace() { + DEPLOYMENT=$1; NAMESPACE=$2; + RETRY=0; RETRY_MAX=50; + + 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} - Wait 10s 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}') + if [[ "$READY_REPLICAS" = "$WANTED_REPLICAS" ]]; then + echo "Found deployment ${DEPLOYMENT} in namespace ${NAMESPACE}: ${DEPLOYMENT_LIST}" + break + else + RETRY=$[$RETRY+1] + echo "Retry: ${RETRY}/${RETRY_MAX} - Wait 15s for deployment ${DEPLOYMENT} in namespace ${NAMESPACE}" + sleep 15 + fi + fi + done + + if [[ $RETRY == $RETRY_MAX ]]; then + echo "Error: Could not find deployment ${DEPLOYMENT} in namespace ${NAMESPACE}" + exit 1 + fi +} + kubectl create namespace dynatrace -sleep 10 +sleep 5 kubectl apply -f https://github.com/Dynatrace/dynatrace-oneagent-operator/releases/latest/download/kubernetes.yaml echo "Waiting a little bit before we continue..." -sleep 30 +sleep 10 echo "Continuing now!" kubectl -n dynatrace create secret generic oneagent --from-literal="apiToken=$DT_API_TOKEN" --from-literal="paasToken=$DT_PAAS_TOKEN" curl -o cr.yaml https://raw.githubusercontent.com/Dynatrace/dynatrace-oneagent-operator/master/deploy/cr.yaml -export URL=$(echo https://ENVIRONMENTID.live.dynatrace.com/api) -export API_URL=$(echo https://${DT_TENANT}/api) +URL=https://ENVIRONMENTID.live.dynatrace.com/api +API_URL=https://${DT_TENANT}/api replace_value_in_yaml_file $URL $API_URL cr.yaml kubectl apply -f cr.yaml -echo "Waiting a little bit before we continue..." -sleep 20 -echo "Continuing now!" +echo "Verifying Dynatrace oneagent installation" +wait_for_deployment_in_namespace "dynatrace-oneagent-operator" "dynatrace" +wait_for_deployment_in_namespace "dynatrace-oneagent-webhook" "dynatrace" rm cr.yaml \ No newline at end of file From 1f927a0bdb031a12010baf70b363ac425d535bf6 Mon Sep 17 00:00:00 2001 From: TannerGabriel Date: Mon, 10 Aug 2020 10:22:50 +0200 Subject: [PATCH 4/8] Istio configuration verification steps and minor bug fixes --- istio-configuration/configure-istio.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) mode change 100644 => 100755 istio-configuration/configure-istio.sh diff --git a/istio-configuration/configure-istio.sh b/istio-configuration/configure-istio.sh old mode 100644 new mode 100755 index 7d859c8..72d3dbb --- a/istio-configuration/configure-istio.sh +++ b/istio-configuration/configure-istio.sh @@ -5,6 +5,12 @@ echo "Configure Istio and Keptn" # Get Ingress gateway IP-Address export INGRESS_IP=$(kubectl -n istio-system get svc istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}') +# Check if IP-Address is not empty or pending +if [ -z "$INGRESS_IP" ] || [ "$INGRESS_IP" = "Pending" ] ; then + echo "INGRESS_IP is empty. Make sure that the Ingress gateway is ready" + exit 1 +fi + # Applying ingress-manifest kubectl apply -f - < Date: Mon, 10 Aug 2020 12:35:57 +0200 Subject: [PATCH 5/8] add loadgen for prod only --- .../deploy/cartsloadgen-prod.yaml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 load-generation/cartsloadgen/deploy/cartsloadgen-prod.yaml diff --git a/load-generation/cartsloadgen/deploy/cartsloadgen-prod.yaml b/load-generation/cartsloadgen/deploy/cartsloadgen-prod.yaml new file mode 100644 index 0000000..412ace4 --- /dev/null +++ b/load-generation/cartsloadgen/deploy/cartsloadgen-prod.yaml @@ -0,0 +1,38 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: loadgen +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: cartsloadgen + namespace: loadgen +spec: + replicas: 1 + selector: + matchLabels: + app: cartsloadgen + template: + metadata: + labels: + app: cartsloadgen + spec: + containers: + - name: cartsloadgen + image: docker.io/keptnexamples/cartsloadgenerator:0.1 + imagePullPolicy: Always + env: + - name: KEPTN_DOMAIN + value: svc.cluster.local + - name: CARTS_STAGES + value: "carts-primary.sockshop-production" + - name: ITEM_ID + value: "03fef6ac-1896-4ce8-bd69-b798f85c6e0b" + - name: CARTS_ID + value: "3395a43e-2d88-40de-b95f-e00e1502085b" + - name: SLEEP_TIME + value: "0.3" + - name: MAX_CARTS_ITEMS + value: "20" From 3c642869fa5f4ba87d6cce4f3c193da64798646d Mon Sep 17 00:00:00 2001 From: TannerGabriel Date: Mon, 10 Aug 2020 16:14:40 +0200 Subject: [PATCH 6/8] Changed kubernetes command to support older kubectl versions --- istio-configuration/configure-istio.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/istio-configuration/configure-istio.sh b/istio-configuration/configure-istio.sh index 72d3dbb..c24fe35 100755 --- a/istio-configuration/configure-istio.sh +++ b/istio-configuration/configure-istio.sh @@ -54,7 +54,7 @@ echo "Waiting a little bit" sleep 10 # Creating Keptn ingress config map -kubectl create configmap -n keptn ingress-config --from-literal=ingress_hostname_suffix=$(kubectl -n keptn get ingress api-keptn-ingress -ojsonpath='{.spec.rules[0].host}') --from-literal=ingress_port=80 --from-literal=ingress_protocol=http --from-literal=istio_gateway=public-gateway.istio-system -oyaml --dry-run=client | kubectl apply -f - +kubectl create configmap -n keptn ingress-config --from-literal=ingress_hostname_suffix=$(kubectl -n keptn get ingress api-keptn-ingress -ojsonpath='{.spec.rules[0].host}') --from-literal=ingress_port=80 --from-literal=ingress_protocol=http --from-literal=istio_gateway=public-gateway.istio-system -oyaml --dry-run | kubectl apply -f - # Restart helm service kubectl delete pod -n keptn -lapp.kubernetes.io/name=helm-service \ No newline at end of file From 3f58faffe4c4550eae6ee5a864f65657eb668375 Mon Sep 17 00:00:00 2001 From: jetzlstorfer Date: Tue, 11 Aug 2020 10:02:28 +0200 Subject: [PATCH 7/8] fix sed command for mac os --- dynatrace-oneagent/deploy-dynatrace-oneagent.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynatrace-oneagent/deploy-dynatrace-oneagent.sh b/dynatrace-oneagent/deploy-dynatrace-oneagent.sh index 40c6557..a6f2097 100755 --- a/dynatrace-oneagent/deploy-dynatrace-oneagent.sh +++ b/dynatrace-oneagent/deploy-dynatrace-oneagent.sh @@ -18,7 +18,7 @@ fi function replace_value_in_yaml_file() { OLDVAL=$1; NEWVAL=$2; FILE=$3 - sed -i "s#$OLDVAL#$NEWVAL#g" $FILE + sed -i'.bak' -e "s#$OLDVAL#$NEWVAL#g" $FILE } function wait_for_deployment_in_namespace() { From 1484dee8c34f47874ab20c14a6e137216a8cc3f5 Mon Sep 17 00:00:00 2001 From: TannerGabriel Date: Tue, 11 Aug 2020 10:52:02 +0200 Subject: [PATCH 8/8] Exit on command fails + validate oneagent daemonset state --- .../deploy-dynatrace-oneagent.sh | 33 +++++++++++++++++++ istio-configuration/configure-istio.sh | 1 + 2 files changed, 34 insertions(+) diff --git a/dynatrace-oneagent/deploy-dynatrace-oneagent.sh b/dynatrace-oneagent/deploy-dynatrace-oneagent.sh index 40c6557..4124571 100755 --- a/dynatrace-oneagent/deploy-dynatrace-oneagent.sh +++ b/dynatrace-oneagent/deploy-dynatrace-oneagent.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e if [ -z "$DT_TENANT" ]; then echo "Please supply a value for the environment variable DT_TENANT" @@ -51,6 +52,37 @@ function wait_for_deployment_in_namespace() { fi } +function wait_for_daemonset_in_namespace() { + DAEMONSET=$1; NAMESPACE=$2; + RETRY=0; RETRY_MAX=50; + + while [[ $RETRY -lt $RETRY_MAX ]]; do + DAEMONSET_LIST=$(eval "kubectl get daemonset -n ${NAMESPACE} | awk '/$DAEMONSET /'" | awk '{print $1}') + if [[ -z "$DAEMONSET_LIST" ]]; then + RETRY=$[$RETRY+1] + echo "Retry: ${RETRY}/${RETRY_MAX} - Wait 15s for daemonset ${DAEMONSET} in namespace ${NAMESPACE}" + sleep 15 + else + READY_REPLICAS=$(eval kubectl get daemonset $DAEMONSET -n $NAMESPACE -o=jsonpath='{$.status.desiredNumberScheduled}') + WANTED_REPLICAS=$(eval kubectl get daemonset $DAEMONSET -n $NAMESPACE -o=jsonpath='{$.status.numberAvailable}') + if [[ "$READY_REPLICAS" = "$WANTED_REPLICAS" ]]; then + echo "Found daemonset ${DAEMONSET} in namespace ${NAMESPACE}: ${DAEMONSET_LIST}" + break + else + RETRY=$[$RETRY+1] + echo "Retry: ${RETRY}/${RETRY_MAX} - Wait 15s for daemonset ${DAEMONSET} in namespace ${NAMESPACE}" + sleep 15 + fi + fi + done + + if [[ $RETRY == $RETRY_MAX ]]; then + echo "Error: Could not find daemonset ${DAEMONSET} in namespace ${NAMESPACE}" + exit 1 + fi +} + + kubectl create namespace dynatrace sleep 5 @@ -73,5 +105,6 @@ kubectl apply -f cr.yaml echo "Verifying Dynatrace oneagent installation" wait_for_deployment_in_namespace "dynatrace-oneagent-operator" "dynatrace" wait_for_deployment_in_namespace "dynatrace-oneagent-webhook" "dynatrace" +wait_for_daemonset_in_namespace "oneagent" "dynatrace" rm cr.yaml \ No newline at end of file diff --git a/istio-configuration/configure-istio.sh b/istio-configuration/configure-istio.sh index c24fe35..70b7874 100755 --- a/istio-configuration/configure-istio.sh +++ b/istio-configuration/configure-istio.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e echo "Configure Istio and Keptn"