-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_worker.sh.template
55 lines (47 loc) · 1.3 KB
/
config_worker.sh.template
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
#!/bin/sh
apk add curl jq sudo vim
rancher_server="__RANCHER_SERVER__"
admin_password="__ADMIN_PASSWORD__"
cluster_name="__CLUSTER_NAME__"
ROLEFLAGS="__ROLEFLAGS__"
# https://github.com/rancher/rancher/issues/12205#issuecomment-385661588
mount --make-rshared /
# Login
while true; do
LOGINRESPONSE=$(curl \
-s "https://$rancher_server/v3-public/localProviders/local?action=login" -H 'content-type: application/json' --data-binary '{"username":"admin","password":"'$admin_password'"}' --insecure)
LOGINTOKEN=$(echo $LOGINRESPONSE | jq -r .token)
if [ -n "$LOGINTOKEN" ]; then
break
else
sleep 5
fi
done
# Test if cluster is created
while true; do
CLUSTERID=$(curl \
-sLk \
-H "Authorization: Bearer $LOGINTOKEN" \
"https://$rancher_server/v3/clusters?name=$cluster_name" | jq -r '.data[].id')
if [ -n "$CLUSTERID" ]; then
break
else
sleep 5
fi
done
# Get token
# Test if cluster is created
while true; do
AGENTCMD=$(curl \
-sLk \
-H "Authorization: Bearer $LOGINTOKEN" \
"https://$rancher_server/v3/clusterregistrationtoken?clusterId=$CLUSTERID" | jq -r '.data[].nodeCommand' | head -1)
if [ -n "$AGENTCMD" ]; then
break
else
sleep 5
fi
done
# Show the command
COMPLETECMD="$AGENTCMD $ROLEFLAGS"
$COMPLETECMD