/
aliases
177 lines (147 loc) · 5.16 KB
/
aliases
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env zsh
# Aliases I like
alias venv-gimme="source ~/code/dotfiles/venv-gimme-script"
alias k="kubectl"
alias kg="kubectl get"
alias g="git"
# Allow putting misc scripts under dotfiles/bin
export PATH="${PATH}:${HOME}/code/dotfiles/bin"
# Drain a node that is probably running jupyter things
k-drain() {
# We always wanna ignore daemonsets, duh
# Disabling evictions lets us ignore PodDisruptionBudgets
# delete-local-data lets us get rid of pods with emptyDirs
# force is needed to delete user pods - they aren't managed by anything else
k drain --ignore-daemonsets --disable-eviction --delete-local-data --force $@
}
wk() {
# I watch kubernetes resources all the time
# I can do things like `wk 'get node | rg -v user'`
watch "kubectl $@"
}
k-non-running-pods() {
k get pod -A | rg -v Running
}
w() {
# Default 'watch' doesn't support shell aliases
# THIS ONE DOES
/usr/local/bin/watch "$SHELL -ic '$@'"
}
# Get names of kubernetes objects filtered by default output
# Often, you wanna get list of names of a kind of object, so you can
# pass it to something else. For example, you wanna drain all nodes
# that are user nodes. You can do this with some awk and grep.
# it is suhc a common occurance, this alias just streamlines it.
k-g-n() {
KIND="$1"
# Remove kind from $@
shift 1
# Everything other than the first item is passed to rg
FILTER="$@"
# FIXME: Not sure how to pass everything, including options, to rg without a subshell
k get ${KIND} --no-headers | $SHELL -c "rg ${FILTER}" | awk '{ print $1 }'
}
alias kuts="kubectl -n utoronto-staging"
alias kutp="kubectl -n utoronto-prod"
# Resolve a namespace to -prod or -staging
# We mostly wanna look at things in staging, but sometimes in prod too
# FIXME: But in pilot hubs, we don't have -stagin hubs.
# Temporarily killing automatic resolution until that is fixed
hub-namespace-resolve () {
echo -n "${1}"
# NAMESPACE_SPEC="$1"
# echo -n $NAMESPACE_SPEC | rg '\-staging$' > /dev/null && echo -n ${NAMESPACE_SPEC} || echo -n "${NAMESPACE_SPEC}-prod"
}
hub-exec() {
NAMESPACE=$(hub-namespace-resolve $1)
HUB_NAME="$(k -n ${NAMESPACE} get pod -o name -l component=hub)"
k -n ${NAMESPACE} exec -it ${HUB_NAME} -c hub -- /bin/bash
}
hub-scp-to() {
NAMESPACE=$(hub-namespace-resolve $1)
HUB_NAME="$(k -n ${NAMESPACE} get pod -o name -l component=hub | sed 's/pod\///')"
k -n ${NAMESPACE} cp ${2} ${HUB_NAME}:${3} -c hub
}
hub-scp-from() {
NAMESPACE=$(hub-namespace-resolve $1)
HUB_NAME="$(k -n ${NAMESPACE} get pod -o name -l component=hub | sed 's/pod\///')"
k -n ${NAMESPACE} cp ${HUB_NAME}:${2} ${3} -c hub
}
hub-logs() {
NAMESPACE=$(hub-namespace-resolve $1)
shift 1
HUB_NAME="$(k -n ${NAMESPACE} get pod -o name -l component=hub)"
k -n ${NAMESPACE} logs ${HUB_NAME} -c hub $@
}
user-logs() {
NAMESPACE=$(hub-namespace-resolve $1)
shift 1
USER_NAME=$1
shift 1
k -n ${NAMESPACE} logs jupyter-${USER_NAME} -c notebook $@
}
hub-list-user-pods() {
NAMESPACE=$(hub-namespace-resolve $1)
shift 1
k -n ${NAMESPACE} get pod -l component=singleuser-server $@
}
hub-list-core-pods() {
NAMESPACE=$(hub-namespace-resolve $1)
shift 1
k -n ${NAMESPACE} get pod $@ | rg -v 'jupyter-|user-placeholder'
}
kill-pods-like() {
NAMESPACE="${1}"
shift 1
k -n ${NAMESPACE} get pod | rg $@ | awk '{ print $1 }' | parallel -j8 kubectl -n ${NAMESPACE} delete pod --grace-period=1
}
pod-logs-like() {
NAMESPACE="${1}"
# FIXME: Find a way to pass options to rg?
POD_PATTERN="${2}"
shift 2
POD_NAME="$(k -n ${NAMESPACE} get pod | rg ${POD_PATTERN} | awk '{ print $1; }')"
k -n ${NAMESPACE} logs ${POD_NAME} $@
}
pods-all-jupyter() {
k get pod -A | rg jupyter- $@
}
pods-all-non-running() {
k get pod -A | rg -v Running $@
}
k-get-secret() {
k get secret -o go-template='{{range $k,$v := .data}}{{printf "%s: " $k}}{{if not $v}}{{$v}}{{else}}{{$v | base64decode}}{{end}}{{"\n"}}{{end}}' $@
}
ucb-data8x() {
gcloud config set account yuvipanda@gmail.com
gcloud config set project data8x-scratch
k config use-context gke_data8x-scratch_us-central1_data8x-2019-02-20
}
ucb-datahub-2018() {
gcloud config set account yuvipanda@gmail.com
gcloud config set project ucb-datahub-2018
k config use-context gke_ucb-datahub-2018_us-central1_fall-2019
}
binder-prod() {
gcloud config set account yuvipanda@gmail.com
gcloud config set project binderhub-288415
k config use-context gke_binderhub-288415_us-central1_prod
}
binder-staging() {
gcloud config set account yuvipanda@gmail.com
gcloud config set project binderhub-288415
k config use-context gke_binderhub-288415_us-central1_prod
}
2i2c-utoronto() {
k config use-context jupyterhub-2i2c-cluster
}
2i2c-low-touch() {
gcloud config set account yuvipanda@2i2c.org
gcloud config set project two-eye-two-see
k config use-context gke_two-eye-two-see_us-central1-b_low-touch-hubs-cluster
}
2i2c-cloudbank() {
gcloud config set account yuvipanda@2i2c.org
gcloud config set project cb-1003-1696
k config use-context gke_cb-1003-1696_us-central1-b_cloudbank-2i2c-cluster
}