-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.sh
executable file
·254 lines (207 loc) · 5.92 KB
/
env.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/env bash
BASE_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")") ;
OUTPUT_DIR=${BASE_DIR}/output ;
# shellcheck source=/dev/null
source "${BASE_DIR}/helpers/print.sh" ;
ENV_CONF=env.json ;
if ! [[ -f "${ENV_CONF}" ]] ; then
print_error "Cannot find ${ENV_CONF}, aborting..." ;
exit 1 ;
fi
if ! which jq &>/dev/null ; then
print_error "Package for json parsing jq is not installed, please run 'sudo apt-get install -y jq'" ;
exit 2 ;
fi
if ! jq -r ".topology" "${ENV_CONF}" &>/dev/null ; then
print_error "Unable to parse topology from ${ENV_CONF}, aborting..." ;
exit 3 ;
fi
function get_topology {
jq -r ".topology" "${ENV_CONF}" ;
}
function get_scenario {
jq -r ".scenario" "${ENV_CONF}" ;
}
function get_topology_dir {
echo "${BASE_DIR}/topologies/$(get_topology)" ;
}
function get_scenario_dir {
echo "${BASE_DIR}/topologies/$(get_topology)/scenarios/$(get_scenario)" ;
}
TOPOLOGY_CONF=$(get_topology_dir)/infra.json ;
if ! [[ -f "${TOPOLOGY_CONF}" ]] ; then
print_error "Cannot find ${TOPOLOGY_CONF}, aborting..." ;
exit 4 ;
fi
###### MP Cluster ######
function get_mp_k8s_provider {
jq -r ".mp_cluster.k8s_provider" "${TOPOLOGY_CONF}" ;
}
function get_mp_k8s_version {
jq -r ".mp_cluster.k8s_version" "${TOPOLOGY_CONF}" ;
}
function get_mp_name {
jq -r ".mp_cluster.name" "${TOPOLOGY_CONF}" ;
}
function get_mp_region {
jq -r ".mp_cluster.region" "${TOPOLOGY_CONF}" ;
}
function get_mp_trust_domain {
jq -r ".mp_cluster.trust_domain" "${TOPOLOGY_CONF}" ;
}
function get_mp_vm_count {
jq -r ".mp_cluster.vms | length" "${TOPOLOGY_CONF}" ;
}
function get_mp_vm_image_by_index {
i=${1} ;
jq -r ".mp_cluster.vms[${i}].image" "${TOPOLOGY_CONF}" ;
}
function get_mp_vm_name_by_index {
i=${1} ;
jq -r ".mp_cluster.vms[${i}].name" "${TOPOLOGY_CONF}" ;
}
function get_mp_zone {
jq -r ".mp_cluster.zone" "${TOPOLOGY_CONF}" ;
}
###### CP Clusters ######
function get_cp_count {
jq -r ".cp_clusters | length" "${TOPOLOGY_CONF}" ;
}
function get_cp_k8s_provider_by_index {
i=${1} ;
jq -r ".cp_clusters[${i}].k8s_provider" "${TOPOLOGY_CONF}" ;
}
function get_cp_k8s_version_by_index {
i=${1} ;
jq -r ".cp_clusters[${i}].k8s_version" "${TOPOLOGY_CONF}" ;
}
function get_cp_name_by_index {
i=${1} ;
jq -r ".cp_clusters[${i}].name" "${TOPOLOGY_CONF}" ;
}
function get_cp_vm_count_by_index {
i=${1} ;
jq -r ".cp_clusters[${i}].vms | length" "${TOPOLOGY_CONF}" ;
}
function get_cp_vm_image_by_index {
i=${1} ;
j=${2} ;
jq -r ".cp_clusters[${i}].vms[${j}].image" "${TOPOLOGY_CONF}" ;
}
function get_cp_vm_name_by_index {
i=${1} ;
j=${2} ;
jq -r ".cp_clusters[${i}].vms[${j}].name" "${TOPOLOGY_CONF}" ;
}
function get_cp_region_by_index {
i=${1} ;
jq -r ".cp_clusters[${i}].region" "${TOPOLOGY_CONF}" ;
}
function get_cp_trust_domain_by_index {
i=${1} ;
jq -r ".cp_clusters[${i}].trust_domain" "${TOPOLOGY_CONF}" ;
}
function get_cp_zone_by_index {
i=${1} ;
jq -r ".cp_clusters[${i}].zone" "${TOPOLOGY_CONF}" ;
}
### TSB Configuration ###
function get_tetrate_repo_password {
jq -r ".tsb.tetrate_repo.password" "${ENV_CONF}" ;
}
function get_tetrate_repo_user {
jq -r ".tsb.tetrate_repo.user" "${ENV_CONF}" ;
}
function get_tsb_install_method {
jq -r ".tsb.install_method" "${ENV_CONF}" ;
}
function get_tsb_istio_version {
jq -r ".tsb.istio_version" "${ENV_CONF}" ;
}
function get_tsb_version {
jq -r ".tsb.version" "${ENV_CONF}" ;
}
### TSB installation templates files ###
function get_mp_cp_cr_template_file {
echo "$(get_topology_dir)/$(jq -r ".mp_cluster.templates.cp_tctl" "${TOPOLOGY_CONF}")" ;
}
function get_mp_cp_helm_template_file {
echo "$(get_topology_dir)/$(jq -r ".mp_cluster.templates.cp_helm" "${TOPOLOGY_CONF}")" ;
}
function get_mp_mp_cr_template_file {
echo "$(get_topology_dir)/$(jq -r ".mp_cluster.templates.mp_tctl" "${TOPOLOGY_CONF}")" ;
}
function get_mp_mp_helm_template_file {
echo "$(get_topology_dir)/$(jq -r ".mp_cluster.templates.mp_helm" "${TOPOLOGY_CONF}")" ;
}
function get_cp_cr_template_file_by_index {
i=${1} ;
echo "$(get_topology_dir)/$(jq -r ".cp_clusters[${i}].templates.cp_tctl" "${TOPOLOGY_CONF}")" ;
}
function get_cp_helm_template_file_by_index {
i=${1} ;
echo "$(get_topology_dir)/$(jq -r ".cp_clusters[${i}].templates.cp_helm" "${TOPOLOGY_CONF}")" ;
}
### Output directories ###
function get_certs_output_dir {
mkdir -p "${OUTPUT_DIR}/certs" ;
echo "${OUTPUT_DIR}/certs" ;
}
function get_mp_output_dir {
mkdir -p "${OUTPUT_DIR}/$(get_mp_name)" ;
echo "${OUTPUT_DIR}/$(get_mp_name)" ;
}
function get_cp_output_dir {
i=${1} ;
mkdir -p "${OUTPUT_DIR}/$(get_cp_name_by_index ${i})" ;
echo "${OUTPUT_DIR}/$(get_cp_name_by_index ${i})" ;
}
### Parsing Tests
#
# get_k8s_version;
# get_mp_name;
# get_mp_region;
# get_mp_trust_domain;
# get_mp_vm_count;
# get_mp_vm_image_by_index 0;
# get_mp_vm_image_by_index 1;
# get_mp_vm_name_by_index 0;
# get_mp_vm_name_by_index 1;
# get_mp_zone;
# get_cp_count;
# get_cp_name_by_index 0;
# get_cp_region_by_index 0;
# get_cp_trust_domain_by_index 0;
# get_cp_zone_by_index 0;
# get_cp_name_by_index 1;
# get_cp_vm_count_by_index 0;
# get_cp_vm_name_by_index 0 0;
# get_cp_vm_name_by_index 0 1;
# get_cp_vm_image_by_index 0 0;
# get_cp_vm_image_by_index 0 1;
# get_cp_vm_count_by_index 1;
# get_cp_vm_name_by_index 1 0;
# get_cp_vm_name_by_index 1 1;
# get_cp_vm_image_by_index 1 0;
# get_cp_vm_image_by_index 1 1;
# get_cp_region_by_index 1;
# get_cp_trust_domain_by_index 1;
# get_cp_zone_by_index 1;
# get_tsb_repo_password;
# get_tsb_repo_url;
# get_tsb_repo_user;
# get_tsb_version;
# get_tsb_istio_version;
# get_certs_output_dir;
# get_mp_output_dir;
# get_cp_output_dir 0;
# get_cp_output_dir 1;
# get_mp_cp_cr_template_file;
# get_mp_cp_helm_template_file;
# get_mp_mp_cr_template_file;
# get_mp_mp_helm_template_file;
# get_cp_cr_template_file_by_index 0;
# get_cp_cr_template_file_by_index 1;
# get_cp_helm_template_file_by_index 0;
# get_cp_helm_template_file_by_index 1;
# get_scenario_dir;