-
Notifications
You must be signed in to change notification settings - Fork 14
/
common.sh
76 lines (63 loc) · 1.43 KB
/
common.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
#!/bin/bash
genpass(){
< /dev/urandom LC_ALL=C tr -dc Aa-zZ0-9 | head -c "${1:-32}"
}
apply_config(){
if [ ! -f "$1" ]; then
echo "${1:-file} not found"
return 1
fi
retry oc apply -f "$1" 2>/dev/null
}
apply_kustomize(){
if [ ! -f "${1}/kustomization.yaml" ]; then
echo "Please provide a dir with 'kustomization.yaml'"
echo "'kustomization.yaml' not found in ${1}"
return 1
fi
retry oc apply -k "$1" 2>/dev/null
}
apply_firmly(){
if [ ! -f "${1:-.}/kustomization.yaml" ]; then
echo "Please provide a dir with 'kustomization.yaml'"
echo "'kustomization.yaml' not found in ${1}"
return 1
fi
# until oc kustomize "${1}" --enable-helm | oc apply -f- 2>/dev/null
until_true oc apply -k "${1}" 2>/dev/null
}
until_true(){
echo "Running:" "${@}"
echo "Press <ctrl> + c to cancel"
until "${@}" 1>&2
do
echo "again..."
sleep 20
done
echo "[OK]"
}
retry(){
local attempts=30
local delay=20
echo "Running:" "${@}"
echo "Attempts: ${attempts}"
echo "Delay: ${delay}s"
# until "${@}" 1>&2
until "${@}"
do
if [[ $attempts -gt "1" ]]; then
((attempts--))
echo "Remaining attempts: $attempts - waiting ${delay}s"
sleep $delay
else
echo "[FAILED]"
return 1
fi
done
echo "[OK]"
}
extract_function(){
EXPORT_NAME=${1:-ocp_aws_cluster}
FILE=${2:-scripts/library/ocp.sh}
sed -n '/'"${EXPORT_NAME}"'(){/,/^}/p' "${FILE}"
}