-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
helpers.bash
113 lines (94 loc) · 3.08 KB
/
helpers.bash
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
#!/usr/bin/env bash
function log_msg {
MSG="$1"
echo "***************************************"
echo "*"
echo "*"
echo "* ${MSG}"
echo "*"
echo "*"
echo "***************************************"
}
function retry_function {
set +e
FUNC="$1"
COUNTER=0
MAX_TRIES=10
echo "beginning trying up to ${MAX_TRIES} times function \"${FUNC}\""
while [ $COUNTER -lt $MAX_TRIES ]; do
log_msg "on attempt ${COUNTER} of function \"${FUNC}\""
${FUNC}
if [[ "$?" == "0" ]] ; then
echo "running of \"${FUNC}\" successful"
echo
echo
echo
set -e
return 0
fi
sleep 1
let COUNTER=COUNTER+1
done
log_msg "running function \"${FUNC}\" ${MAX_TRIES} times did not succeed"
set -e
return 1
}
function install_using_apt {
apt-get update
apt-get install --allow-downgrades -y \
"$@"
}
function install_k8s_using_packages {
install_using_apt "$@"
}
function install_k8s_using_binary {
local RELEASE=$1
local CNI_VERSION=$2
local OS=$3
cd $(mktemp -d)
mkdir -p /opt/cni/bin
mkdir -p /etc/systemd/system/kubelet.service.d
curl -sSL "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins${OS}-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz
wget -q https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/amd64/{kubectl,kubeadm,kubelet}
chmod 777 ku*
cp -fv ku* /usr/bin/
rm -rf /etc/systemd/system/kubelet.service || true
# github.com/kubernetes/release is the canonical location for deb/rpm build definitions/specs.
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/v0.2.6/cmd/kubepkg/templates/latest/deb/kubelet/lib/systemd/system/kubelet.service" \
> /etc/systemd/system/kubelet.service
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/v0.2.6/cmd/kubepkg/templates/latest/deb/kubeadm/10-kubeadm.conf" \
> /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
systemctl enable kubelet
}
function pull_image_and_push_to_local_registry {
local IMG=$1
local REGISTRY=$2
local TAG_NAME=$3
local TAG_WITH_REG="${REGISTRY}/${TAG_NAME}"
echo "pulling ${IMG}..."
docker pull "${IMG}"
echo "done pulling ${IMG}"
echo "tagging ${IMG} with tag ${TAG_WITH_REG}"
docker tag "${IMG}" ${TAG_WITH_REG}
echo "done tagging ${IMG} with tag ${TAG_WITH_REG}"
echo "pushing ${TAG_WITH_REG}"
docker push ${TAG_WITH_REG}
echo "done pushing ${TAG_WITH_REG}"
}
function build_cilium_image {
echo "building cilium image..."
make LOCKDEBUG=1 CHECKPTR=1 docker-image-no-clean
echo "tagging cilium image..."
docker tag cilium/cilium k8s1:5000/cilium/cilium-dev
echo "pushing cilium image..."
docker push k8s1:5000/cilium/cilium-dev
}
function build_operator_image {
# build cilium-operator image
echo "building cilium-operator image..."
make LOCKDEBUG=1 CHECKPTR=1 docker-operator-image
echo "tagging cilium-operator image..."
docker tag cilium/operator k8s1:5000/cilium/operator
echo "pushing cilium-operator image..."
docker push k8s1:5000/cilium/operator
}