-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions
66 lines (55 loc) · 1.7 KB
/
functions
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
serve() {
local port=${1:-8000}
local ip=$(ipconfig getifaddr en0)
echo "Serving on ${ip}:${port} ..."
python -m SimpleHTTPServer ${port}
}
# Open PR on GitHub
pr() {
if type gh &> /dev/null; then
gh pr view -w
else
echo "gh is not installed"
fi
}
#################
# k8s
#################
kexec () {
kubectl exec -it $1 -- ${2:-bash}
}
# Get the pod names (just the names) of all pods in a namespace.
kgpns () {
echo $(kubectl get pods ${1} -o go-template --template '{{range .items}}{{.metadata.name}}{{" "}}{{end}}')
}
# Delete all pods within a namespace.
kdap () {
read "kdelete?This will attempt to delete all pods within the namespace. Do you want to continue?(y/N) "
if [[ "${kdelete}" =~ ^[yY]$ ]]; then
kubectl delete pods $(kgpns ${1}) ${1}
fi
}
# Drain node
kdrain () {
read "kdrainnode? This will drain the node ${1}, delete local data, and ignore daemonsets. Do you want to continue?(y/N) "
if [[ "${kdrainnode}" =~ ^[yY]$ ]]; then
kubectl drain ${1} --delete-local-data --force --ignore-daemonsets
fi
}
checkcert() {
if [ -z "${1}" ]; then
echo "ERROR: No domain specified.";
return 1;
fi;
local domain="${1}";
local temp=$(echo | openssl s_client -connect "${domain}:443" -servername "${domain}" 2>/dev/null | openssl x509 -noout -enddate -issuer -subject);
local subject=$(echo "${temp}" | grep "subject=" | sed -e "s/subject=//" | sed $'s/\\//\\\n/g' | grep "O=" | sed -e "s/O=//");
if [ ! -z "${subject}" ]; then
echo "Subject: " ${subject};
fi;
echo -n "Issued By: ";
echo "${temp}" | grep "issuer=" | sed -e "s/^.*CN=//";
echo -n "Expires: ";
echo "${temp}" | grep "notAfter=" | sed -e "s/notAfter=//";
}
c() { printf "%s\n" "$@" | bc -l; }