Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #126 from keptn/release-0.7.0
Browse files Browse the repository at this point in the history
adding scripts for automation
  • Loading branch information
johannes-b authored Aug 24, 2020
2 parents 245be02 + bd94170 commit 390cd51
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 0 deletions.
110 changes: 110 additions & 0 deletions dynatrace-oneagent/deploy-dynatrace-oneagent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash
set -e

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'.bak' -e "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
}

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

kubectl apply -f https://github.com/Dynatrace/dynatrace-oneagent-operator/releases/latest/download/kubernetes.yaml

echo "Waiting a little bit before we continue..."
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

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 "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
61 changes: 61 additions & 0 deletions istio-configuration/configure-istio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
set -e

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 - <<EOF
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: istio
name: api-keptn-ingress
namespace: keptn
spec:
rules:
- host: $INGRESS_IP.nip.io
http:
paths:
- backend:
serviceName: api-gateway-nginx
servicePort: 80
EOF

# Applying public gateway
kubectl apply -f - <<EOF
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: public-gateway
namespace: istio-system
spec:
selector:
istio: ingressgateway
servers:
- port:
name: http
number: 80
protocol: HTTP
hosts:
- '*'
EOF

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 | kubectl apply -f -

# Restart helm service
kubectl delete pod -n keptn -lapp.kubernetes.io/name=helm-service
38 changes: 38 additions & 0 deletions load-generation/cartsloadgen/deploy/cartsloadgen-prod.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 390cd51

Please sign in to comment.