forked from jaggedmountain/k-alias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkdn
executable file
·40 lines (32 loc) · 908 Bytes
/
kdn
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
#!/bin/bash
# - kup: download file from pod
# - example: `kup pod:/path/file.ext`
# - example: `kup pod:/path/file.ext newfile.ext`
# - example: `kup pod:/path/file.ext dst/`
# - example: `kup pod:/path/file.ext dst/newfile.ext`
# - example: `kup pod:container:/path/file.ext`
if [ -z "$1" ]; then
kubectl get pod
exit
fi
resource=${1%:*}
path=${1##*:}
if [ "$resource" == "$1" ]; then path=""; fi
target=${resource%:*}
container=${resource##*:}
if [ "$target" == "$resource" ]; then container=""; fi
pod=`kubectl get pod | grep $target | head -n1 | awk '{print $1}'`
if [ -z "$pod" ]; then
echo no pod found.
exit
fi
fn=${2##*/}
dst=${2%/*}
if [ -z "$fn" ]; then fn=`basename $path`; fi
if [ -z "$dst" ]; then dst="."; fi
if [ -n "$dst" ]; then mkdir -p $dst; fi
if [ -n "$container" ]; then
kubectl cp $pod:$path -c $container $dst/$fn
else
kubectl cp $pod:$path $dst/$fn
fi