forked from OpsDocker/pullk8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pullk8s.sh
79 lines (69 loc) · 1.7 KB
/
pullk8s.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
77
78
79
#!/bin/bash
check(){
if [ "$1"x == "--microk8s"x ]
then
logs=`microk8s kubectl get pod --all-namespaces|tail -n +2|grep -v Running|while read line
do
declare -a arr=( $line )
microk8s kubectl describe pod ${arr[1]} --namespace=${arr[0]}
done|grep -i "image"|sed -nr 's/.*(failed to pull|Back-off pulling) image \"([^\"]+)\".*/\2/p'|uniq`
echo ${logs}
fi
}
pull(){
image=$1
imageName=${image/#k8s\.gcr\.io\//}
if [ "$image"x == "$imageName"x ]
then
imageName=${image/#gcr\.io\/google_containers\//}
fi
echo Pull $imageName ...
if [ "$image"x == "$imageName"x ]
then
echo Pull $imageName ...
docker pull $image
exit 0
fi
hubimage=${imageName//\//\-}
if [ -n ”$hubimage“ ]
then
echo Pull $imageName ...
docker pull opsdockerimage/$hubimage
docker tag opsdockerimage/$hubimage $1
docker rmi opsdockerimage/$hubimage
if [ "$2"x == "--microk8s"x ]
then
saveImage=${1#:}
docker save $saveImage > ~/.docker_image.tmp.tar
microk8s ctr image import ~/.docker_image.tmp.tar
rm ~/.docker_image.tmp.tar
fi
fi
}
if [ "$1"x == "check"x ]
then
check $2
exit 0
fi
if [ "$1"x == "pull"x -a $# -ge 2 ]
then
pull $2 $3
exit 0
fi
echo
echo "Usage: pullk8s COMMAND [NAME[:TAG|@DIGEST]] [OPTIONS]"
echo
echo "Pull gcr.io's image for hub.docker.com"
echo
echo "Commands:"
echo " check Check gcr.io's fail pull images."
echo " pull Pull an image or a repository"
echo
echo "Options:"
echo " --microk8s If use MicroK8s release."
echo
echo "Examples:"
echo " pullk8s pull k8s.gcr.io/pause:3.6 --microk8s"
echo " pullk8s pull gcr.io/google_containers/etcd:2.0.12"
echo " pullk8s check --microk8"
exit 1