Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 257140d

Browse files
committed
ci: adding yq-shim to support v3 and v4
Some tests uses yq installed by this repository but other tests might use yq installed by the kata-containers repository. We are pushing yq to v4 within the main kata repository and this shim will handle only basic syntax of yq v3 and v4 during the transition period. Signed-off-by: Beraldo Leal <[email protected]>
1 parent 772105b commit 257140d

File tree

6 files changed

+88
-9
lines changed

6 files changed

+88
-9
lines changed

.ci/ci-fast-return.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ filenames=""
6363
read_yaml() {
6464
${cidir}/install_yq.sh 1>&5 2>&1
6565

66-
res=$(yq read "$1" "$2")
66+
yq_shim="${cidir}/yq-shim.sh"
67+
res=$(${yq_shim} "$2" "$1" r)
6768
[ "$res" == "null" ] && res=""
6869
echo $res
6970
return 0

.ci/ci_crio_entry_point.sh

+9-5
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,25 @@ cd "${katacontainers_repo_dir}"
121121
# Install yq
122122
${GOPATH}/src/${tests_repo}/.ci/install_yq.sh
123123

124+
# YQ_SHIM Usage:
125+
# ./yq-shim.sh <query> <path to yaml> <action> [value]
126+
YQ_SHIM=${GOPATH}/src/${tests_repo}/.ci/yq-shim.sh
127+
124128
# CRI-O switched to using go 1.18+
125129
golang_version="1.18.1"
126-
yq w -i versions.yaml languages.golang.meta.newest-version "${golang_version}"
130+
${YQ_SHIM} languages.golang.meta.newest-version versions.yaml w "${golang_version}"
127131

128132
critools_version="${branch_release_number}.0"
129133
[ ${critools_version} == "1.24.0" ] && critools_version="1.24.2"
130134
echo "Using critools ${critools_version}"
131-
yq w -i versions.yaml externals.critools.version "${critools_version}"
132-
yq r versions.yaml externals.critools.version
135+
${YQ_SHIM} externals.critools.version versions.yaml w "${critools_version}"
136+
${YQ_SHIM} externals.critools.version versions.yaml r
133137

134138
latest_kubernetes_from_repo=`LC_ALL=C sudo dnf -y repository-packages kubernetes info --available kubelet-${branch_release_number}* | grep Version | cut -d':' -f 2 | xargs`
135139
kubernetes_version="${latest_kubernetes_from_repo}-00"
136140
echo "Using kubernetes ${kubernetes_version}"
137-
yq w -i versions.yaml externals.kubernetes.version "${kubernetes_version}"
138-
yq r versions.yaml externals.kubernetes.version
141+
${YQ_SHIM} externals.kubernetes.version versions.yaml w "${kubernetes_version}"
142+
${YQ_SHIM} externals.kubernetes.version versions.yaml r
139143

140144
# Run kata-containers setup
141145
cd "${tests_repo_dir}"

.ci/filter/filter_k8s_test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ main()
2828
# install yq if not exist
2929
${CI_DIR}/install_yq.sh > /dev/null
3030

31-
local K8S_SKIP_UNION=$("${GOPATH_LOCAL}/bin/yq" read "${K8S_CONFIG_FILE}" "${K8S_FILTER_FLAG}")
31+
local K8S_SKIP_UNION=$("${CI_DIR}/yq-shim.sh" "${K8S_FILTER_FLAG}" "${K8S_CONFIG_FILE}" r)
3232
[ "${K8S_SKIP_UNION}" == "null" ] && return
3333
mapfile -t _K8S_SKIP_UNION <<< "${K8S_SKIP_UNION}"
3434

.ci/filter/filter_test_union.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ main()
2323
{
2424
# install yq if not exist
2525
${ci_dir}/install_yq.sh
26-
local array_test=$("${GOPATH_LOCAL}/bin/yq" read "${test_config_file}" "${test_filter_flag}")
26+
local array_test=$("${ci_dir}/yq-shim.sh" "${test_filter_flag}" "${test_config_file}" r)
2727
[ "${array_test}" = "null" ] && return
2828
mapfile -t _array_test <<< "${array_test}"
2929
for entry in "${_array_test[@]}"

.ci/lib.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ function get_dep_from_yaml_db(){
188188

189189
"${GOPATH}/src/${tests_repo}/.ci/install_yq.sh" >&2
190190

191-
result=$("${GOPATH}/bin/yq" r -X "$versions_file" "$dependency")
191+
yq_shim="${GOPATH}/src/${tests_repo}/.ci/yq-shim.sh"
192+
result=$("${yq_shim}" "$dependency" "$versions_file" r)
192193
[ "$result" = "null" ] && result=""
193194
echo "$result"
194195
}

.ci/yq-shim.sh

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
usage() { echo "Usage: $0 <query> <path to yaml> <action> [value]"; }
6+
7+
QUERY="${1-}"
8+
YAML_PATH="${2-}"
9+
ACTION="${3-}"
10+
VALUE="${4-}"
11+
VERSION=""
12+
13+
handle_v3() {
14+
query="${QUERY#.}"
15+
16+
case ${ACTION} in
17+
r)
18+
yq r "${YAML_PATH}" "${query}"
19+
;;
20+
w)
21+
yq w -i "${YAML_PATH}" "${query}" "${VALUE}"
22+
;;
23+
d)
24+
yq d -i -d'*' "${YAML_PATH}" "${query}"
25+
;;
26+
*)
27+
usage
28+
exit 1
29+
;;
30+
esac
31+
}
32+
33+
handle_v4() {
34+
query=".${QUERY#.}"
35+
case ${ACTION} in
36+
r)
37+
yq "${query}" "${YAML_PATH}"
38+
;;
39+
w)
40+
export VALUE
41+
yq -i "${query} = strenv(VALUE)" "${YAML_PATH}"
42+
;;
43+
d)
44+
yq -i "del(${query})" "${YAML_PATH}"
45+
;;
46+
*)
47+
usage
48+
exit 1
49+
;;
50+
esac
51+
}
52+
53+
if [ "$QUERY" == "-h" ]; then
54+
usage
55+
exit 0
56+
elif [ $# -lt 3 ]; then
57+
usage >&2
58+
exit 1
59+
fi
60+
61+
if ! command -v yq > /dev/null; then
62+
echo "yq not found in path" >&2
63+
exit 1
64+
fi
65+
66+
if yq --version | grep '^.* version v4.*$' > /dev/null; then
67+
handle_v4
68+
elif yq --version | grep '^.* version 3.*$' > /dev/null; then
69+
handle_v3
70+
else
71+
echo "unsupported yq version" >&2
72+
exit 1
73+
fi

0 commit comments

Comments
 (0)