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

Commit 43ed263

Browse files
author
Jürgen Etzlstorfer
authored
feat: adding quickstart resources (#196)
* adding quickstart resources Signed-off-by: jetzlstorfer <juergen.etzlstorfer@dynatrace.com> * small tweaks Signed-off-by: jetzlstorfer <juergen.etzlstorfer@dynatrace.com> * initial commit Signed-off-by: jetzlstorfer <juergen.etzlstorfer@dynatrace.com> * adding git clone Signed-off-by: jetzlstorfer <juergen.etzlstorfer@dynatrace.com> * job executor manifest Signed-off-by: jetzlstorfer <juergen.etzlstorfer@dynatrace.com>
1 parent c58f804 commit 43ed263

20 files changed

Lines changed: 1095 additions & 0 deletions

quickstart/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
remediation_trigger.json

quickstart/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Quickstart
2+
3+
All files needed for the quickstart guide on https://keptn.sh/docs/quickstart/ are maintained here.

quickstart/automated-operations.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
set -e
3+
4+
#source <(curl -s https://raw.githubusercontent.com/keptn/keptn/0.8.5/test/utils.sh)
5+
6+
function print_headline() {
7+
HEADLINE=$1
8+
9+
echo ""
10+
echo "---------------------------------------------------------------------"
11+
echo $HEADLINE
12+
echo "---------------------------------------------------------------------"
13+
echo ""
14+
}
15+
16+
# wait for a deployment to be up and running
17+
function wait_for_deployment_in_namespace() {
18+
DEPLOYMENT=$1; NAMESPACE=$2;
19+
RETRY=0; RETRY_MAX=10;
20+
21+
while [[ $RETRY -lt $RETRY_MAX ]]; do
22+
DEPLOYMENT_LIST=$(eval "kubectl get deployments -n ${NAMESPACE} | awk '/$DEPLOYMENT /'" | awk '{print $1}') # list of multiple deployments when starting with the same name
23+
if [[ -z "$DEPLOYMENT_LIST" ]]; then
24+
RETRY=$((RETRY+1))
25+
echo "Retry: ${RETRY}/${RETRY_MAX} - Deployment not found - waiting 5s for deployment ${DEPLOYMENT} in namespace ${NAMESPACE}"
26+
sleep 5
27+
else
28+
READY_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.status.availableReplicas}')
29+
WANTED_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.spec.replicas}')
30+
UNAVAILABLE_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.status.unavailableReplicas}')
31+
if [[ "$READY_REPLICAS" = "$WANTED_REPLICAS" && "$UNAVAILABLE_REPLICAS" = "" ]]; then
32+
echo "Found deployment ${DEPLOYMENT} in namespace ${NAMESPACE}: ${DEPLOYMENT_LIST}"
33+
break
34+
else
35+
RETRY=$((RETRY+1))
36+
echo "Retry: ${RETRY}/${RETRY_MAX} - Unsufficient replicas for deployment - waiting 5s for deployment ${DEPLOYMENT} in namespace ${NAMESPACE}"
37+
sleep 5
38+
fi
39+
fi
40+
done
41+
42+
if [[ $RETRY == "$RETRY_MAX" ]]; then
43+
print_error "Could not find deployment ${DEPLOYMENT} in namespace ${NAMESPACE}"
44+
exit 1
45+
fi
46+
}
47+
48+
PROJECT="podtatohead"
49+
SERVICE="helloservice"
50+
51+
print_headline "Preparation of Auto-remediation in Production"
52+
53+
echo "Adding SLIs for Prometheus"
54+
keptn add-resource --project=$PROJECT --stage=production --service=$SERVICE --resource=./demo/prometheus/sli.yaml --resourceUri=prometheus/sli.yaml
55+
echo "Adding SLO definition file for the quality gate"
56+
keptn add-resource --project=$PROJECT --stage=production --service=$SERVICE --resource=./demo/slo.yaml --resourceUri=slo.yaml
57+
echo "Adding Remediation Configuration"
58+
keptn add-resource --project=$PROJECT --stage=production --service=$SERVICE --resource=./demo/remediation.yaml --resourceUri=remediation.yaml
59+
60+
print_headline "Deploy Job Executor"
61+
62+
kubectl apply -f ./demo/job/job-executor.yaml
63+
keptn add-resource --project=$PROJECT --service=$SERVICE --stage=production --resource=./demo/job/config.yaml --resourceUri=job/config.yaml
64+
65+
wait_for_deployment_in_namespace "job-executor-service" "keptn"
66+
67+
print_headline "Simulate Alert (Problem)"
68+
echo -e "{\"type\": \"sh.keptn.event.production.remediation.triggered\",\"specversion\":\"1.0\",\"source\":\"https:\/\/github.com\/keptn\/keptn\/prometheus-service\",\"id\": \"f2b878d3-03c0-4e8f-bc3f-454bc1b3d79d\", \"time\": \"2019-06-07T07:02:15.64489Z\", \"contenttype\": \"application\/json\", \"data\": {\"project\": \"podtatohead\",\"stage\": \"production\",\"service\": \"helloservice\",\"problem\": { \"problemTitle\": \"out_of_memory\",\"rootCause\": \"Response time degradation\"}}}" > remediation_trigger.json | keptn send event -f remediation_trigger.json
69+
70+
print_headline "Have a look at the Keptn Bridge and explore the demo project"
71+
72+
echo "You can simulate a new problem any time by executing the following command:"
73+
echo "keptn send event -f remediation_trigger.json"

quickstart/clean-project.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
4+
keptn delete project podtatohead
5+
# rm -rf podtato-head
6+
kubectl delete deploy -n keptn prometheus-service --ignore-not-found=true
7+
kubectl delete deploy -n keptn prometheus-sli-service --ignore-not-found=true
8+
kubectl delete secret -n keptn prometheus-credentials-podtatohead --ignore-not-found=true
9+
kubectl delete ns monitoring --ignore-not-found=true
10+
kubectl delete ns podtatohead-hardening --ignore-not-found=true
11+
kubectl delete ns podtatohead-production --ignore-not-found=true
12+
13+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
deploymentURIsLocal:
2+
- "http://helloservice.podtatohead-hardening:80"
3+
4+
995 Bytes
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
appVersion: 1.16.0
3+
description: A Helm chart for Kubernetes
4+
name: podtatoserver
5+
type: application
6+
version: 0.1.0
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: helloservice
5+
namespace: {{ .Release.Namespace }}
6+
spec:
7+
replicas: {{ .Values.replicaCount }}
8+
selector:
9+
matchLabels:
10+
app: helloservice
11+
template:
12+
metadata:
13+
labels:
14+
app: helloservice
15+
spec:
16+
terminationGracePeriodSeconds: 5
17+
containers:
18+
- name: server
19+
image: {{ .Values.image}}
20+
imagePullPolicy: Always
21+
ports:
22+
- containerPort: 9000
23+
env:
24+
- name: PORT
25+
value: "9000"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: helloservice
5+
namespace: {{ .Release.Namespace }}
6+
spec:
7+
selector:
8+
app: helloservice
9+
ports:
10+
- name: http
11+
port: 80
12+
protocol: TCP
13+
targetPort: 9000
14+
type: ClusterIP
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
image: ghcr.io/podtato-head/podtatoserver:v0.1.1
2+
replicaCount: 1

0 commit comments

Comments
 (0)