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

Commit fc6c8a5

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. Fixes: #5820 Signed-off-by: Beraldo Leal <bleal@redhat.com>
1 parent 996bea0 commit fc6c8a5

8 files changed

Lines changed: 93 additions & 11 deletions

File tree

.ci/aarch64/kubernetes/init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ ${SCRIPT_PATH}/../../.ci/install_yq.sh
2121
# Default flannel config has limitation and request for memory, and it may cause OOM on AArch64.
2222
# Though here, we delete memory limitation for all archs, this modified-configuration
2323
# file will only be applied on aarch64.
24-
sudo -E ${GOPATH}/bin/yq d -i -d'*' $network_plugin_config_file $memory_resource > /dev/null
24+
sudo -E ${SCRIPT_PATH}/../../.ci/yq-shim.sh $memory_resource $network_plugin_config_file d > /dev/null
2525

2626
network_plugin_config="$network_plugin_config_file"

.ci/ci-fast-return.sh

Lines changed: 2 additions & 1 deletion
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

Lines changed: 9 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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/ppc64le/kubernetes/init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ ${SCRIPT_PATH}/../../.ci/install_yq.sh
2121
# Default flannel config has limitation and request for memory, and it may cause OOM on ppc64le.
2222
# Though here, we delete memory limitation for all archs, this modified-configuration
2323
# file will only be applied on ppc64le.
24-
sudo -E ${GOPATH}/bin/yq d -i -d'*' $network_plugin_config_file $memory_resource > /dev/null
24+
sudo -E ${SCRIPT_PATH}/../../.ci/yq-shim.sh $memory_resource $network_plugin_config_file d > /dev/null
2525

2626
network_plugin_config="$network_plugin_config_file"

.ci/yq-shim.sh

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

0 commit comments

Comments
 (0)