Skip to content

Commit c27f164

Browse files
committed
One call for oc status
1 parent 27c03a3 commit c27f164

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

collection-scripts/version

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
#!/usr/bin/env bash
2+
export IMAGE=$( oc status | grep '^pod')
23

34
function version() {
45
# get version from image (major.minor.micro, e.g. v4.11.0)
5-
version=v$( \
6-
oc status | grep '^pod' | \
7-
sed -n -r -e 's/.*(([[:digit:]])+\.([[:digit:]])+\.([[:digit:]])+).*/\1/p' \
8-
)
9-
# if version not found, fallback to imageID
10-
[ -z "${version}" ] && version=$(oc status | grep '^pod.*runs' | sed -r -e 's/^pod.*runs //')
6+
version=v$(sed -n -r -e 's/.*(([[:digit:]])+\.([[:digit:]])+\.([[:digit:]])+).*/\1/p' <<< $IMAGE)
7+
8+
# if version is still not found, use 0.0.0-unknown
9+
[ -z "${version}" ] && version="0.0.0-unknown"
1110

12-
# if version still not found, use Unknown
13-
[ -z "${version}" ] && version="Unknown"
1411
echo ${version}
1512
}
1613

1714
function imageId() {
18-
# get imageId (e.g. repository@digest )
19-
imageId=$(oc status | grep '^pod' | sed -r -e 's/^pod.*runs //' | awk '{print $2}')
15+
# get image id (e.g. repository@digest )
16+
imageId=$(sed -r -e 's/^pod.*runs //' <<< $IMAGE | awk '{print $2}')
17+
18+
# if image_id is not found, use Unknown
19+
[ -z "${imageId}" ] && imageId="Unknown-Image"
2020

21-
# if imageId is not found, use Unknown
22-
[ -z "${imageId}" ] && imageId="Unknown"
2321
echo ${imageId}
2422

2523
}

0 commit comments

Comments
 (0)