You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: scripts/functions.sh
+103-1Lines changed: 103 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -164,6 +164,79 @@ function clusterIsReady() {
164
164
fi
165
165
}
166
166
167
+
functioncheckClusterVersion() {
168
+
states=$(${K8S_CLI_BIN} get clusterversion version -o jsonpath='{.status.history[*].state}')
169
+
if [[ -z"${states}" ]];then
170
+
echo"Can't check version since cluster is not OpenShift"
171
+
else
172
+
versions=$(${K8S_CLI_BIN} get clusterversion version -o jsonpath='{.status.history[*].version}')
173
+
version=""
174
+
175
+
# get the current version finding *Completed* state
176
+
if [[ "$(declare -p states)"=~"declare -a" ]];then
177
+
# handle states and versions as arrays
178
+
if [ "${#states[@]}"-eq"${#versions[@]}" ];then
179
+
foriin"${!states[@]}";do
180
+
if [[ "${states[$i]}"="Completed" ]];then
181
+
version="${versions[$i]}"
182
+
fi
183
+
done
184
+
fi
185
+
else
186
+
# handle states and versions as strings
187
+
if [ "${states}"="Completed" ];then
188
+
version="${versions}"
189
+
fi
190
+
fi
191
+
192
+
if [ -z"${version}" ];then
193
+
# allow running if no version found since the user may be running an upgrade
194
+
echo"Warning: can't find current version in the clusterversion history"
195
+
echo"Is the cluster upgrading?"
196
+
return 0
197
+
else
198
+
echo"OpenShift version: $version"
199
+
fi
200
+
201
+
returnCode=0
202
+
result=""
203
+
204
+
if [[ "$command"="packets" ]];then
205
+
compare_versions "$version" 4.16.0
206
+
if [ "$result"-eq 0 ];then
207
+
echo"- Packet capture requires OpenShift 4.16 or higher"
208
+
returnCode=1
209
+
fi
210
+
fi
211
+
212
+
if [[ "${options[*]}"==*"enable_all"*||"${options[*]}"==*"enable_network_events"* ]];then
213
+
compare_versions "$version" 4.19.0
214
+
if [ "$result"-eq 0 ];then
215
+
echo"- Network events requires OpenShift 4.19 or higher"
216
+
returnCode=1
217
+
fi
218
+
fi
219
+
220
+
if [[ "${options[*]}"==*"enable_all"*||"${options[*]}"==*"enable_udn_mapping"* ]];then
221
+
compare_versions "$version" 4.18.0
222
+
if [ "$result"-eq 0 ];then
223
+
echo"- UDN mapping requires OpenShift 4.18 or higher"
224
+
returnCode=1
225
+
fi
226
+
fi
227
+
228
+
if [[ "${options[*]}"==*"enable_all"*||"${options[*]}"==*"enable_pkt_drop"* ]];then
229
+
compare_versions "$version" 4.14.0
230
+
if [ "$result"-eq 0 ];then
231
+
echo"- Packet drops requires OpenShift 4.14 or higher"
232
+
returnCode=1
233
+
fi
234
+
fi
235
+
236
+
return$returnCode
237
+
fi
238
+
}
239
+
167
240
functionnamespaceFound() {
168
241
# ensure namespace doesn't exist, else we should not override content
169
242
if${K8S_CLI_BIN} get namespace "$namespace" --ignore-not-found=true | grep -q "$namespace";then
@@ -264,6 +337,11 @@ function setup() {
264
337
exit 1
265
338
fi
266
339
340
+
if! checkClusterVersion;then
341
+
printf'Remove not compatible features and try again\n'>&2
342
+
exit 1
343
+
fi
344
+
267
345
if namespaceFound;then
268
346
printf"%s namespace already exists. Ensure someone else is not running another capture on this cluster. Else use 'oc netobserv cleanup' to remove the namespace first.\n""$namespace">&2
269
347
skipCleanup="true"
@@ -701,6 +779,30 @@ function defaultValue() {
701
779
fi
702
780
}
703
781
782
+
functionwaitDaemonset(){
783
+
echo"Waiting for daemonset pods to be ready..."
784
+
retries=10
785
+
while [[ $retries-ge 0 ]];do
786
+
sleep 5
787
+
ready=$($K8S_CLI_BIN -n "$namespace" get daemonset netobserv-cli -o jsonpath="{.status.numberReady}")
788
+
required=$($K8S_CLI_BIN -n "$namespace" get daemonset netobserv-cli -o jsonpath="{.status.desiredNumberScheduled}")
789
+
reasons=$($K8S_CLI_BIN get pods -n "$namespace" -o jsonpath='{.items[*].status.containerStatuses[*].state.waiting.reason}')
0 commit comments