-
Notifications
You must be signed in to change notification settings - Fork 374
/
install-vm.sh
185 lines (167 loc) · 5.09 KB
/
install-vm.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env bash
# Copyright 2022 Antrea Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eo pipefail
function echoerr {
>&2 echo "$@"
}
_usage="Usage: $0 [--ns <Namespace>] [--bin <AntreaAgentSavePath>] [--config <AgentConfigSavePath>] [--kubeconfig <KubeconfigSavePath>] [--antrea-kubeconfig <AntreaKubeconfigSavePath>] [--nodename <ExternalNodeName>] [--help|-h]
--ns Namespace to be used by the antrea-agent.
--bin Path of the antrea-agent binary
--config Path of the antrea-agent configuration file
--kubeconfig Path of the kubeconfig to access K8s API Server
--antrea-kubeconfig Path of the kubeconfig to access Antrea API Server
--nodename ExternalNode name to be used by the antrea-agent
--help, -h Print this message and exit
Please run the script as sudo user"
function print_usage {
echoerr "$_usage"
}
function print_help {
echoerr "Try '$0 --help' for more information."
}
INSTALL_PATH="/usr/sbin"
AGENT_BIN_PATH=""
CONFIG_PATH=""
KUBECONFIG=""
ANTREAKUBECONFIG=""
AGENT_NAMESPACE=""
NODE_NAME="$(hostname)"
AGENT_LOG_DIR="/var/log/antrea"
AGENT_CONF_PATH="/etc/antrea"
# List of supported OS versions, verified by antrea.
declare -a SUPPORTED_OS=("Ubuntu 18.04", "Ubuntu 20.04")
check_supported_platform() {
echo "Checking supported OS platform"
dist_version="$(lsb_release -is) $(lsb_release -rs)"
for ver in "${SUPPORTED_OS[@]}"; do
if [ "$ver" == "$dist_version" ]; then
return
fi
done
echoerr "Error ${SUPPORTED_OS[*]} are supported"
exit 1
}
copy_antrea_agent_files() {
if [[ ! -f "$CONFIG_PATH" ]]; then
echoerr "Error $CONFIG_PATH file not found"
exit 1
fi
mkdir -p $AGENT_CONF_PATH
echo "Copying $CONFIG_PATH to $AGENT_CONF_PATH"
cp $CONFIG_PATH $AGENT_CONF_PATH
if [[ ! -f "$KUBECONFIG" ]]; then
echoerr "Error $KUBECONFIG file not found"
exit 1
fi
echo "Copying $KUBECONFIG to $AGENT_CONF_PATH"
cp "$KUBECONFIG" "${AGENT_CONF_PATH}/antrea-agent.kubeconfig"
chmod 600 "${AGENT_CONF_PATH}/antrea-agent.kubeconfig"
if [[ ! -f "$ANTREA_KUBECONFIG" ]]; then
echoerr "Error $ANTREA_KUBECONFIG file not found"
exit 1
fi
echo "Copying $ANTREA_KUBECONFIG to $AGENT_CONF_PATH"
cp "$ANTREA_KUBECONFIG" "${AGENT_CONF_PATH}/antrea-agent.antrea.kubeconfig"
chmod 600 "${AGENT_CONF_PATH}/antrea-agent.antrea.kubeconfig"
}
update_antrea_agent_conf() {
echo "Updating clientConnection and antreaClientConnection"
sed -i "s|kubeconfig: |kubeconfig: $AGENT_CONF_PATH/|g" $AGENT_CONF_PATH/antrea-agent.conf
echo "Updating externalNodeNamespace to $AGENT_NAMESPACE"
sed -i "s|#externalNodeNamespace: default|externalNodeNamespace: $AGENT_NAMESPACE|g" $AGENT_CONF_PATH/antrea-agent.conf
}
start_antrea_agent_service() {
if [[ ! -f "$AGENT_BIN_PATH" ]]; then
echoerr "Error $AGENT_BIN_PATH file not found"
exit 1
fi
mkdir -p $AGENT_LOG_DIR
mkdir -p $INSTALL_PATH
cp "$AGENT_BIN_PATH" "$INSTALL_PATH"
cat >/etc/systemd/system/antrea-agent.service << EOF
[Unit]
Description="antrea-agent as a systemd service"
After=network.target
[Service]
Environment="NODE_NAME=$NODE_NAME"
ExecStart=$INSTALL_PATH/antrea-agent \
--config=$AGENT_CONF_PATH/antrea-agent.conf \
--logtostderr=false \
--log_file=$AGENT_LOG_DIR/antrea-agent.log
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable antrea-agent
echo "Starting antrea-agent service"
systemctl start antrea-agent
systemctl status antrea-agent
}
validate_argument() {
if [[ $2 == --* || -z $2 ]]; then
echoerr "Error invalid argument for $1: <$2>"
print_usage
exit 1
fi
}
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--ns)
AGENT_NAMESPACE="$2"
validate_argument $1 $2
shift 2
;;
--bin)
AGENT_BIN_PATH="$2"
validate_argument $1 $2
shift 2
;;
--config)
CONFIG_PATH="$2"
validate_argument $1 $2
shift 2
;;
--kubeconfig)
KUBECONFIG="$2"
validate_argument $1 $2
shift 2
;;
--antrea-kubeconfig)
ANTREA_KUBECONFIG="$2"
validate_argument $1 $2
shift 2
;;
--nodename)
NODE_NAME="$2"
validate_argument $1, $2
shift 2
;;
-h|--help)
print_usage
exit 0
;;
*) # unknown option
echoerr "Unknown option $1"
exit 1
;;
esac
done
check_supported_platform
copy_antrea_agent_files
update_antrea_agent_conf
start_antrea_agent_service