Skip to content

Commit a7a7f5d

Browse files
committed
report correct version when multiple images invoked
1 parent da9f681 commit a7a7f5d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

collection-scripts/version

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#!/usr/bin/env bash
22

33
function version() {
4-
# get version from image
5-
version=$( \
6-
oc status | grep '^pod' | \
7-
sed -n -r -e 's/.*([[:digit:]]+\.[[:digit:]]+(:?\.[[:digit:]])?(:?-[^@]+)?).*/\1/p' \
8-
)
94

10-
# if version not found, fallback to imageID
11-
[ -z "${version}" ] && version=$(oc status | grep '^pod.*runs' | sed -r -e 's/^pod.*runs //')
5+
# get gather container image and imageID
6+
read -r image imageID < <(oc get pod ${POD_NAME} -o jsonpath='{range .status.containerStatuses[?(@.name=="gather")]}{.image} {.imageID}{end}')
127

13-
# if version still not found, use Unknown
8+
# attempt to get semantic-like version from image
9+
version=$(echo ${image} | sed -n -r -e 's/.*:([[:digit:]]+\.[[:digit:]]+(:?\.[[:digit:]])?(:?-[^@]+)?).*/\1/p')
10+
11+
# if version is not set, fallback to imageID
12+
[ -z "${version}" ] && version=${imageID}
13+
14+
# if version still not set, use Unknown
1415
[ -z "${version}" ] && version="Unknown"
1516

1617
echo ${version}

0 commit comments

Comments
 (0)