-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathe2e.sh
executable file
·94 lines (76 loc) · 4.63 KB
/
e2e.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
set -euo pipefail
ARTIFACT_DIR="${ARTIFACT_DIR:-/tmp/artifacts}"
KIND_CLUSTER_NAME="observatorium-promtail"
KUBECTL="${KUBECTL:-./tmp/bin/kubectl}"
OS_TYPE=$(echo `uname -s` | tr '[:upper:]' '[:lower:]')
trap 'tear_down; exit 0' EXIT
setup() {
source .bingo/variables.env
$KIND create cluster --name "${KIND_CLUSTER_NAME}"
curl -L https://storage.googleapis.com/kubernetes-release/release/"$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)"/bin/$OS_TYPE/amd64/kubectl -o ./tmp/bin/kubectl
chmod +x ./tmp/bin/kubectl
}
test_e2e(){
$KUBECTL apply -f https://raw.githubusercontent.com/coreos/kube-prometheus/master/manifests/setup/prometheus-operator-0servicemonitorCustomResourceDefinition.yaml
$KUBECTL apply -f https://raw.githubusercontent.com/coreos/kube-prometheus/master/manifests/setup/prometheus-operator-0prometheusruleCustomResourceDefinition.yaml
# Deploy dex
$KUBECTL create ns dex || true
$KUBECTL apply -f ./vendor/observatorium/manifests/dex-secret.yaml
$KUBECTL apply -f ./vendor/observatorium/manifests/dex-pvc.yaml
$KUBECTL apply -f ./vendor/observatorium/manifests/dex-deployment.yaml
$KUBECTL apply -f ./vendor/observatorium/manifests/dex-service.yaml
$KUBECTL rollout status --timeout=10m -n dex deploy/dex || (must_gather "$ARTIFACT_DIR" && exit 1)
# Deploy observatorium
$KUBECTL create ns observatorium-minio || true
$KUBECTL create ns observatorium || true
$KUBECTL apply -f ./vendor/observatorium/manifests
$KUBECTL rollout status --timeout=10m -n observatorium-minio deploy/minio || (must_gather "$ARTIFACT_DIR" && exit 1)
$KUBECTL rollout status --timeout=10m -n observatorium deploy/observatorium-xyz-loki-distributor || (must_gather "$ARTIFACT_DIR" && exit 1)
$KUBECTL rollout status --timeout=10m -n observatorium statefulset/observatorium-xyz-loki-ingester || (must_gather "$ARTIFACT_DIR" && exit 1)
$KUBECTL rollout status --timeout=10m -n observatorium statefulset/observatorium-xyz-loki-querier || (must_gather "$ARTIFACT_DIR" && exit 1)
# Deploy promtail
$KUBECTL apply -f environments/dev/manifests/observatorium-promtail-serviceaccount.yaml
$KUBECTL apply -f environments/dev/manifests/observatorium-promtail-clusterrole.yaml
$KUBECTL apply -f environments/dev/manifests/observatorium-promtail-clusterrolebinding.yaml
$KUBECTL apply -f environments/dev/manifests/observatorium-promtail-configmap.yaml
$KUBECTL apply -f environments/dev/manifests/observatorium-promtail-daemonset.yaml
$KUBECTL rollout status --timeout=10m -n observatorium daemonset/observatorium-promtail || (must_gather "$ARTIFACT_DIR" && exit 1)
# Deploy up-job
$KUBECTL apply -f environments/dev/manifests/observatorium-up-logs-configmap.yaml
$KUBECTL apply -f environments/dev/manifests/observatorium-up-logs.yaml
$KUBECTL wait --for=condition=complete --timeout=5m -n default job/observatorium-up-logs || (must_gather "$ARTIFACT_DIR" && exit 1)
}
tear_down(){
source .bingo/variables.env
$KIND delete cluster --name "${KIND_CLUSTER_NAME}"
}
must_gather() {
local artifact_dir="$1"
for namespace in default dex observatorium observatorium-minio; do
mkdir -p "$artifact_dir/$namespace"
for name in $($KUBECTL get pods -n "$namespace" -o jsonpath='{.items[*].metadata.name}') ; do
$KUBECTL -n "$namespace" describe pod "$name" > "$artifact_dir/$namespace/$name.describe"
$KUBECTL -n "$namespace" get pod "$name" -o yaml > "$artifact_dir/$namespace/$name.yaml"
for initContainer in $($KUBECTL -n "$namespace" get po "$name" -o jsonpath='{.spec.initContainers[*].name}') ; do
$KUBECTL -n "$namespace" logs "$name" -c "$initContainer" > "$artifact_dir/$namespace/$name-$initContainer.logs"
done
for container in $($KUBECTL -n "$namespace" get po "$name" -o jsonpath='{.spec.containers[*].name}') ; do
$KUBECTL -n "$namespace" logs "$name" -c "$container" > "$artifact_dir/$namespace/$name-$container.logs"
done
done
done
$KUBECTL describe nodes > "$artifact_dir/nodes"
$KUBECTL get pods --all-namespaces > "$artifact_dir/pods"
$KUBECTL get daemonset --all-namespaces > "$artifact_dir/daemonsets"
$KUBECTL get deploy --all-namespaces > "$artifact_dir/deployments"
$KUBECTL get job --all-namespaces > "$artifact_dir/jobs"
$KUBECTL get statefulset --all-namespaces > "$artifact_dir/statefulsets"
$KUBECTL get services --all-namespaces > "$artifact_dir/services"
$KUBECTL get endpoints --all-namespaces > "$artifact_dir/endpoints"
}
main(){
setup
test_e2e
}
main