forked from intel/workload-services-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-sut-k8s.sh
executable file
·186 lines (177 loc) · 4.63 KB
/
setup-sut-k8s.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
186
#!/bin/bash -e
#
# Apache v2 license
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
DIR="$( cd "$( dirname "$0" )" &> /dev/null && pwd )"
. "$DIR"/setup-common.sh
print_help () {
echo "Usage: [options] <user@controller-ip[:private-ip]> <user>@worker-ip[:private-ip] [<user>@worker-ip[:private_ip]...]"
echo ""
echo "--port port Specify the ssh port."
echo "--nointelcert Do not install Intel certificates."
echo "--no-password Do not ask for password. Use DEV_SUDO_PASSWORD, SUT_SSH_PASSWORD and/or SUT_SUDO_PASSWORD instead."
echo "--worker Specify the worker group."
echo "--client Specify the client group."
echo "--controller Specify the controller group."
echo ""
exit 3
}
if [ ${#@} -lt 2 ]; then
print_help
fi
ssh_port=22
controller_hosts=()
worker_hosts=()
client_hosts=()
setup_ansible_options=()
setup_native_options=()
ansible_options=(
'-e' 'k8s_reset=true'
'-e' 'containerd_reset=true'
'-e' 'k8s_enable_registry=false'
)
[ ! -e vars.yaml ] || ansible_options+=(-e "@vars.yaml")
last=""
vm_group="controller"
for v in $@; do
k1="$(echo "${v#--}" | cut -f1 -d=)"
v1="$(echo "${v#--}" | cut -f2- -d= | sed 's/%20/ /g')"
case "$v" in
--help)
print_help
;;
--worker)
vm_group=worker
;;
--client)
vm_group=client
;;
--controller)
vm_group=controller
;;
--port=*)
ssh_port="${v#--port=}"
;;
--port)
;;
--nointelcert)
setup_native_options+=("$v")
;;
--no-password)
setup_ansible_options+=("$v")
setup_native_options+=("$v")
;;
--*=*)
validate_ansible_option $k1 $v
setup_native_options+=("$v")
ansible_options+=("-e" "$k1=$v1")
;;
--no*)
validate_ansible_option ${k1#no} $v
setup_native_options+=("$v")
ansible_options+=("-e" "${k1#no}=false")
;;
--*)
validate_ansible_option $k1 $v
setup_native_options+=("$v")
ansible_options+=("-e" "$k1=true")
;;
*)
if [ "$last" = "--port" ]; then
ssh_port="$v"
elif [[ "$v" = *"@"* ]]; then
case "$vm_group" in
controller)
controller_hosts+=("$v")
vm_group=worker
;;
worker)
worker_hosts+=("$v")
;;
client)
client_hosts+=("$v")
;;
esac
else
echo "Unsupported argument: $v"
exit 3
fi
;;
esac
last="$v"
done
./setup-ansible.sh "${setup_ansible_options[@]}" 2>&1 | tee setup-sut-k8s.logs
./setup-sut-native.sh --port $ssh_port --controller ${controller_hosts[@]} --worker ${worker_hosts[@]} --client ${client_hosts[@]} "${setup_native_options[@]}" 2>&1 | tee -a setup-sut-k8s.logs
controller=${controller_hosts[0]}
controller_hh="${controller/*@/}"
controller_h1="${controller_hh/:*/}"
controller_h2="${controller_hh/*:/}"
workers="$(
i=0
for h in ${worker_hosts[@]}; do
hh="${h/*@/}"
h1="${hh/:*/}"
h2="${hh/*:/}"
cat <<EOF
worker-$i: &worker-$i
ansible_host: "${h1}"
ansible_user: "${h/@*/}"
private_ip: "${h2:-$h1}"
ansible_port: "$ssh_port"
EOF
i=$((i+1));done)"
workers_ref="$(i=0;for h in ${worker_hosts[@]}; do cat <<EOF
worker-$i: *worker-$i
EOF
i=$((i+1));done)"
clients="$(
i=0
for h in ${client_hosts[@]}; do
hh="${h/*@/}"
h1="${hh/:*/}"
h2="${hh/*:/}"
cat <<EOF
client-$i: &client-$i
ansible_host: "${h1}"
ansible_user: "${h/@*/}"
private_ip: "${h2:-$h1}"
ansible_port: "$ssh_port"
EOF
i=$((i+1));done)"
clients_ref="$(i=0;for h in ${client_hosts[@]}; do cat <<EOF
client-$i: *client-$i
EOF
i=$((i+1));done)"
. <(sed '/^# BEGIN WSF Setup/,/^# END WSF Setup/{d}' /etc/environment)
export http_proxy https_proxy no_proxy
rm -f /tmp/wsf-setup-ssh-* 2> /dev/null || true
ANSIBLE_ROLES_PATH=../terraform/template/ansible/kubernetes/roles:../terraform/template/ansible/common/roles:../terraform/template/ansible/traces/roles ANSIBLE_INVENTORY_ENABLED=yaml ansible-playbook --flush-cache -vv -e wl_logs_dir="$DIR" -e my_ip_list=1.1.1.1 "${ansible_options[@]}" --inventory <(cat <<EOF
all:
children:
cluster_hosts:
hosts:
controller-0: &controller-0
ansible_host: "${controller_h1}"
ansible_user: "${controller/@*/}"
private_ip: "${controller_h2:-$controller_h1}"
ansible_port: "$ssh_port"
$workers
$clients
controller:
hosts:
controller-0: *controller-0
workload_hosts:
hosts:
$workers_ref
$clients_ref
trace_hosts:
hosts:
$workers_ref
$clients_ref
off_cluster_hosts:
hosts:
EOF
) ./setup-sut-k8s.yaml 2>&1 | tee -a setup-sut-k8s.logs
rm -f cluster-info.json timing.yaml