blob: b6c6cb62c5c6ed6dda13cbb45f1a45842288b6e1 (
plain)
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
|
#!/bin/sh -eu
#
# Copyright (C) 2020 Axis Communications AB
#
# SPDX-License-Identifier: Apache-2.0
ENV_CONF=/etc/systemd/system/k3s-agent.service.d/10-env.conf
usage() {
echo "
USAGE:
${0##*/} [OPTIONS]
OPTIONS:
--token value, -t value Token to use for authentication [\$K3S_TOKEN]
--token-file value Token file to use for authentication [\$K3S_TOKEN_FILE]
--server value, -s value Server to connect to [\$K3S_URL]
--node-name value Node name [\$K3S_NODE_NAME]
--resolv-conf value Kubelet resolv.conf file [\$K3S_RESOLV_CONF]
--cluster-secret value Shared secret used to bootstrap a cluster [\$K3S_CLUSTER_SECRET]
-h print this
"
}
[ $# -gt 0 ] || {
usage
exit
}
case $1 in
-*)
;;
*)
usage
exit 1
;;
esac
rm -f $ENV_CONF
mkdir -p ${ENV_CONF%/*}
echo [Service] > $ENV_CONF
while getopts "t:s:-:h" opt; do
case $opt in
h)
usage
exit
;;
t)
VAR_NAME=K3S_TOKEN
;;
s)
VAR_NAME=K3S_URL
;;
-)
[ $# -ge $OPTIND ] || {
usage
exit 1
}
opt=$OPTARG
eval OPTARG='$'$OPTIND
OPTIND=$(($OPTIND + 1))
case $opt in
token)
VAR_NAME=K3S_TOKEN
;;
token-file)
VAR_NAME=K3S_TOKEN_FILE
;;
server)
VAR_NAME=K3S_URL
;;
node-name)
VAR_NAME=K3S_NODE_NAME
;;
resolv-conf)
VAR_NAME=K3S_RESOLV_CONF
;;
cluster-secret)
VAR_NAME=K3S_CLUSTER_SECRET
;;
help)
usage
exit
;;
*)
usage
exit 1
;;
esac
;;
*)
usage
exit 1
;;
esac
echo Environment=$VAR_NAME=$OPTARG >> $ENV_CONF
done
chmod 0644 $ENV_CONF
rm -rf /var/lib/rancher/k3s/agent
systemctl daemon-reload
systemctl restart k3s-agent
systemctl enable k3s-agent.service
|