forked from jupyterhub/zero-to-jupyterhub-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common
executable file
·79 lines (73 loc) · 2.92 KB
/
common
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
#!/bin/bash
# Use https://www.shellcheck.net/ to reduce mistakes if you make changes to this file.
#
# shellcheck disable=SC2015
# Note that A && B || C is not if-then-else. C may run when A is true.
# shellcheck disable=SC2016
# Expressions don't expand in single quotes, use double quotes for that.
# shellcheck disable=SC2086
# Double quote to prevent globbing and word splitting.
setup_helm () {
echo "setup helm ${HELM_VERSION}"
curl -sf https://raw.githubusercontent.com/helm/helm/HEAD/scripts/get-helm-3 | DESIRED_VERSION=${HELM_VERSION} bash
}
await_kubectl_rollout() {
kubectl rollout status --watch --timeout 300s "$1"
}
await_pebble() {
await_kubectl_rollout deployment/pebble \
&& await_kubectl_rollout deployment/pebble-coredns
}
await_jupyterhub() {
await_kubectl_rollout deployment/proxy \
&& await_kubectl_rollout deployment/hub \
&& (
if kubectl get deploy/autohttps &> /dev/null; then
await_kubectl_rollout deployment/autohttps
fi
) \
&& (
if kubectl get deploy/user-scheduler &> /dev/null; then
await_kubectl_rollout deployment/user-scheduler
fi
)
}
await_autohttps_tls_cert_acquisition() {
i=0; while [ $i -ne 60 ]; do
kubectl logs deploy/autohttps -c traefik | grep "Adding certificate" \
&& acquired_cert=true && break \
|| acquired_cert=false && sleep 0.5 && i=$((i + 1))
done
if [ "$acquired_cert" != "true" ]; then
echo "Certificate acquisition failed!"
kubectl get service,networkpolicy,configmap,pod
kubectl describe pod -l app.kubernetes.io/name=pebble
kubectl logs deploy/pebble --all-containers # --prefix
kubectl describe pod -l app.kubernetes.io/name=pebble-coredns
kubectl logs deploy/pebble-coredns --all-containers # --prefix
kubectl describe pod -l component=autohttps
kubectl logs deploy/autohttps --all-containers # --prefix
exit 1
fi
# a precausion as pebble logs is a bad indicator of the readiness state of
# Traefik's readiness to use the cert for TLS termination.
sleep 1
}
await_autohttps_tls_cert_save() {
i=0; while [ $i -ne 60 ]; do
kubectl logs deploy/autohttps -c secret-sync | grep "Created secret" \
&& saved_cert=true && break \
|| saved_cert=false && sleep 0.5 && i=$((i + 1))
done
if [ "$saved_cert" != "true" ]; then
echo "Certificate acquisition failed!"
kubectl get service,networkpolicy,configmap,pod
kubectl describe pod -l app.kubernetes.io/name=pebble
kubectl logs deploy/pebble --all-containers # --prefix
kubectl describe pod -l app.kubernetes.io/name=pebble-coredns
kubectl logs deploy/pebble-coredns --all-containers # --prefix
kubectl describe pod -l component=autohttps
kubectl logs deploy/autohttps --all-containers # --prefix
exit 1
fi
}