Skip to content

Commit e071465

Browse files
Merge pull request #756 from jiridanek/jd_update_codeserver_annotations
RHOAIENG-2003: feat(metadata/codeserver): update VSCode imagestream annotations with installed software
2 parents 6434946 + 01f4e64 commit e071465

File tree

2 files changed

+85
-27
lines changed

2 files changed

+85
-27
lines changed

ci/check-json.sh

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
#
33
# This script serves to check YAML files in this repository that contain particular
44
# key fields where JSON string is expected. Such JSON strings are extracted and
@@ -10,7 +10,19 @@
1010
# In case of the PR on GitHub, this check is tied to GitHub actions automatically,
1111
# see `.github/workflows` directory.
1212

13-
shopt -s globstar
13+
if ! shopt -s globstar; then
14+
echo "macOS ships bash-3.2 that does not know shopt -s globstar; install newer bash from homebrew"
15+
exit 1
16+
fi
17+
18+
# yq: `brew install yq` or `apt-get install yq`
19+
# json_verify: `brew install yajl` or `apt-get install yajl-tools`
20+
for dep in yq json_verify; do
21+
if ! which -- ${dep} >/dev/null; then
22+
echo "the dependency ${dep} is not installed; install it now"
23+
exit 1
24+
fi
25+
done
1426

1527
function check_json() {
1628
local f="${1}"
@@ -22,15 +34,19 @@ function check_json() {
2234
echo "Checking: '${f}' - for '${string}':"
2335

2436
if grep --quiet --extended-regexp "${string}" "${f}"; then
25-
#if $(grep -e "${string}" "${f}"); then
26-
jsons=$(yq -r ".spec.tags[].annotations.\"${string}\"" "${f}")
27-
28-
while IFS= read -r json; do
29-
echo " ${json}"
30-
echo -n " > "; echo "${json}" | json_verify || ret_code="${?}"
31-
done <<< "${jsons}"
37+
local tmp_dir
38+
tmp_dir=$(mktemp --directory -t check-jsons-in-file-XXXXXXXXXX-)
39+
if ! (cd "${tmp_dir}"; yq --split-exp "\$index" --unwrapScalar ".spec.tags[].annotations.\"${string}\"" "${f}"); then
40+
echo "yq failed to run"
41+
return 1
42+
fi
43+
44+
for json in "${tmp_dir}"/*.yml; do
45+
echo " "; cat "${json}"
46+
echo -n " > "; json_verify < "${json}" || ret_code="${?}"
47+
done
3248
else
33-
echo " Ignoring as this file doesn't contain necessary key field '${string}' for check"
49+
echo " Ignoring as this file doesn't contain necessary key field '${string}' for check"
3450
fi
3551

3652
return "${ret_code}"
@@ -48,20 +64,27 @@ function split_yaml_file() {
4864
return 0
4965
}
5066

51-
ret_code=0
67+
function main() {
68+
local ret_code=0
5269

70+
# Some yaml files can contain more definitions.
71+
# This is a problem for `yq` tool so we need to split these into separate files.
72+
local tmp_dir
73+
tmp_dir=$(mktemp --directory -t check-json-XXXXXXXXXX-)
74+
for f in **/*.yaml; do
75+
echo "Splitting the '${f}' file."
76+
split_yaml_file "${f}" "${tmp_dir}" || ret_code="${?}"
77+
done
5378

54-
# Some yaml files can contain more definitions.
55-
# This is a problem for `yq` tool so we need to split these into separate files.
56-
tmp_dir=$(mktemp --directory --suffix=-check-json)
57-
for f in **/*.yaml; do
58-
echo "Splitting the '${f}' file."
59-
split_yaml_file "${f}" "${tmp_dir}" || ret_code="${?}"
60-
done
79+
for f in "${tmp_dir}"/*; do
80+
check_json "${f}" "opendatahub.io/notebook-software" || ret_code="${?}"
81+
check_json "${f}" "opendatahub.io/notebook-python-dependencies" || ret_code="${?}"
82+
done
6183

62-
for f in "${tmp_dir}"/*; do
63-
check_json "${f}" "opendatahub.io/notebook-software" || ret_code="${?}"
64-
check_json "${f}" "opendatahub.io/notebook-python-dependencies" || ret_code="${?}"
65-
done
84+
exit "${ret_code}"
85+
}
6686

67-
exit "${ret_code}"
87+
# allows sourcing the script into interactive session without executing it
88+
if [[ "${0}" == "${BASH_SOURCE[0]}" ]]; then
89+
main
90+
fi

manifests/base/code-server-notebook-imagestream.yaml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,25 @@ spec:
1616
tags:
1717
# N Version of the image
1818
- annotations:
19-
opendatahub.io/notebook-software: '[{"name":"Python","version":"v3.11"}]'
20-
opendatahub.io/notebook-python-dependencies: '[{"name":"code-server","version":"4.92"}]'
19+
# language=json
20+
opendatahub.io/notebook-software: |
21+
[
22+
{"name": "code-server", "version": "4.92"},
23+
{"name": "Python", "version": "v3.11"}
24+
]
25+
# language=json
26+
opendatahub.io/notebook-python-dependencies: |
27+
[
28+
{"name": "Boto3", "version": "1.34"},
29+
{"name": "Kafka-Python", "version": "2.0"},
30+
{"name": "Matplotlib", "version": "3.8"},
31+
{"name": "Numpy", "version": "1.26"},
32+
{"name": "Pandas", "version": "2.2"},
33+
{"name": "Scikit-learn", "version": "1.4"},
34+
{"name": "Scipy", "version": "1.12"},
35+
{"name": "Sklearn-onnx", "version": "1.16"},
36+
{"name": "ipykernel", "version": "6.29"}
37+
]
2138
openshift.io/imported-from: quay.io/opendatahub/workbench-images
2239
opendatahub.io/workbench-image-recommended: 'true'
2340
opendatahub.io/notebook-build-commit: $(odh-codeserver-notebook-image-commit-n)
@@ -29,8 +46,26 @@ spec:
2946
type: Source
3047
# N-1 Version of the image
3148
- annotations:
32-
opendatahub.io/notebook-software: '[{"name":"Python","version":"v3.9"}]'
33-
opendatahub.io/notebook-python-dependencies: '[{"name":"code-server","version":"4.22"}]'
49+
# language=json
50+
opendatahub.io/notebook-software: |
51+
[
52+
{"name": "code-server", "version": "4.22"},
53+
{"name": "Python", "version": "v3.9"}
54+
]
55+
# language=json
56+
opendatahub.io/notebook-python-dependencies: |
57+
[
58+
{"name": "Boto3", "version": "1.34"},
59+
{"name": "Kafka-Python", "version": "2.0"},
60+
{"name": "Matplotlib", "version": "3.8"},
61+
{"name": "Numpy", "version": "1.26"},
62+
{"name": "Pandas", "version": "2.2"},
63+
{"name": "Plotly", "version": "5.19"},
64+
{"name": "Scikit-learn", "version": "1.4"},
65+
{"name": "Scipy", "version": "1.12"},
66+
{"name": "Sklearn-onnx", "version": "1.16"},
67+
{"name": "ipykernel", "version": "6.29"}
68+
]
3469
openshift.io/imported-from: quay.io/opendatahub/workbench-images
3570
opendatahub.io/workbench-image-recommended: 'false'
3671
opendatahub.io/notebook-build-commit: $(odh-codeserver-notebook-image-commit-n-1)

0 commit comments

Comments
 (0)