-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcluster-utils.sh
64 lines (47 loc) · 1.52 KB
/
cluster-utils.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
#!/usr/bin/env bash
PSPDIR=4-pod-security-policies/demo
function waitForExternalIp() {
local SERVICE_NAME="$1"
local NAMESPACE="$2"
local ip=""
while [[ -z ${ip} ]]; do
ip=$(findServiceExternalIp "${SERVICE_NAME}" "${NAMESPACE}")
sleep 1
done
echo "${ip}"
}
function findServiceExternalIp() {
local NAMESPACE=${2-}
if [[ ! -z "${NAMESPACE}" ]]; then
NAMESPACE="-n ${NAMESPACE}"
fi
kubectl get service $1 -o=jsonpath="{.status.loadBalancer.ingress[0].ip}" ${NAMESPACE}
}
function findIngressHostname() {
local NAMESPACE=${2-}
if [[ ! -z "${NAMESPACE}" ]]; then
NAMESPACE="-n ${NAMESPACE}"
fi
kubectl get ingress $1 -o=jsonpath="{.spec.rules[0].host}" ${NAMESPACE}
}
function writeEtcHosts() {
local IP=$1
local NEW_HOSTNAME=$2
echo "Writing the following to /etc/hosts: ${IP} ${NEW_HOSTNAME}"
echo "${IP} ${NEW_HOSTNAME}" | sudo tee --append /etc/hosts
}
function kubectlIdempotent() {
kubectl "$@" --dry-run=client -o yaml | kubectl apply -f -
}
function waitForPodReady() {
local POD_NAME="$1"
local NAMESPACE="$2"
local isReady=""
while [[ -z ${isReady} ]]; do
local isReady=$(kubectl get pod -n "${NAMESPACE}" $(kubectl get pods -n "${NAMESPACE}" | awk -v pod_name="$POD_NAME" '$0 ~ pod_name {print $1;exit}') -o json | jq '.status.conditions[] | select(.type=="Ready" and .status=="True")')
echo "Waiting for pod ${POD_NAME} in namespace ${NAMESPACE} to become ready"
sleep 1
done
# For some reasons pods still refuse after they are ready :-/
sleep 1
}