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

Commit

Permalink
ci: adding yq-shim to support v3 and v4
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
beraldoleal committed May 31, 2024
1 parent 996bea0 commit fc6c8a5
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .ci/aarch64/kubernetes/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ ${SCRIPT_PATH}/../../.ci/install_yq.sh
# Default flannel config has limitation and request for memory, and it may cause OOM on AArch64.
# Though here, we delete memory limitation for all archs, this modified-configuration
# file will only be applied on aarch64.
sudo -E ${GOPATH}/bin/yq d -i -d'*' $network_plugin_config_file $memory_resource > /dev/null
sudo -E ${SCRIPT_PATH}/../../.ci/yq-shim.sh $memory_resource $network_plugin_config_file d > /dev/null

network_plugin_config="$network_plugin_config_file"
3 changes: 2 additions & 1 deletion .ci/ci-fast-return.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ filenames=""
read_yaml() {
${cidir}/install_yq.sh 1>&5 2>&1

res=$(yq read "$1" "$2")
yq_shim="${cidir}/yq-shim.sh"
res=$(${yq_shim} "$2" "$1" r)
[ "$res" == "null" ] && res=""
echo $res
return 0
Expand Down
14 changes: 9 additions & 5 deletions .ci/ci_crio_entry_point.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,25 @@ cd "${katacontainers_repo_dir}"
# Install yq
${GOPATH}/src/${tests_repo}/.ci/install_yq.sh

# YQ_SHIM Usage:
# ./yq-shim.sh <query> <path to yaml> <action> [value]
YQ_SHIM=${GOPATH}/src/${tests_repo}/.ci/yq-shim.sh

# CRI-O switched to using go 1.18+
golang_version="1.18.1"
yq w -i versions.yaml languages.golang.meta.newest-version "${golang_version}"
${YQ_SHIM} languages.golang.meta.newest-version versions.yaml w "${golang_version}"

critools_version="${branch_release_number}.0"
[ ${critools_version} == "1.24.0" ] && critools_version="1.24.2"
echo "Using critools ${critools_version}"
yq w -i versions.yaml externals.critools.version "${critools_version}"
yq r versions.yaml externals.critools.version
${YQ_SHIM} externals.critools.version versions.yaml w "${critools_version}"
${YQ_SHIM} externals.critools.version versions.yaml r

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`
kubernetes_version="${latest_kubernetes_from_repo}-00"
echo "Using kubernetes ${kubernetes_version}"
yq w -i versions.yaml externals.kubernetes.version "${kubernetes_version}"
yq r versions.yaml externals.kubernetes.version
${YQ_SHIM} externals.kubernetes.version versions.yaml w "${kubernetes_version}"
${YQ_SHIM} externals.kubernetes.version versions.yaml r

# Run kata-containers setup
cd "${tests_repo_dir}"
Expand Down
2 changes: 1 addition & 1 deletion .ci/filter/filter_k8s_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ main()
# install yq if not exist
${CI_DIR}/install_yq.sh > /dev/null

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

Expand Down
2 changes: 1 addition & 1 deletion .ci/filter/filter_test_union.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ main()
{
# install yq if not exist
${ci_dir}/install_yq.sh
local array_test=$("${GOPATH_LOCAL}/bin/yq" read "${test_config_file}" "${test_filter_flag}")
local array_test=$("${ci_dir}/yq-shim.sh" "${test_filter_flag}" "${test_config_file}" r)
[ "${array_test}" = "null" ] && return
mapfile -t _array_test <<< "${array_test}"
for entry in "${_array_test[@]}"
Expand Down
3 changes: 2 additions & 1 deletion .ci/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ function get_dep_from_yaml_db(){

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

result=$("${GOPATH}/bin/yq" r -X "$versions_file" "$dependency")
yq_shim="${GOPATH}/src/${tests_repo}/.ci/yq-shim.sh"
result=$("${yq_shim}" "$dependency" "$versions_file" r)
[ "$result" = "null" ] && result=""
echo "$result"
}
Expand Down
2 changes: 1 addition & 1 deletion .ci/ppc64le/kubernetes/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ ${SCRIPT_PATH}/../../.ci/install_yq.sh
# Default flannel config has limitation and request for memory, and it may cause OOM on ppc64le.
# Though here, we delete memory limitation for all archs, this modified-configuration
# file will only be applied on ppc64le.
sudo -E ${GOPATH}/bin/yq d -i -d'*' $network_plugin_config_file $memory_resource > /dev/null
sudo -E ${SCRIPT_PATH}/../../.ci/yq-shim.sh $memory_resource $network_plugin_config_file d > /dev/null

network_plugin_config="$network_plugin_config_file"
76 changes: 76 additions & 0 deletions .ci/yq-shim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
# Copyright (c) 2024 Red Hat, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
set -euo pipefail

usage() { echo "Usage: $0 <query> <path to yaml> <action> [value]"; }

QUERY="${1-}"
YAML_PATH="${2-}"
ACTION="${3-}"
VALUE="${4-}"
VERSION=""

handle_v3() {
query="${QUERY#.}"

case ${ACTION} in
r)
yq r "${YAML_PATH}" "${query}"
;;
w)
yq w -i "${YAML_PATH}" "${query}" "${VALUE}"
;;
d)
yq d -i -d'*' "${YAML_PATH}" "${query}"
;;
*)
usage
exit 1
;;
esac
}

handle_v4() {
query=".${QUERY#.}"
case ${ACTION} in
r)
yq "${query}" "${YAML_PATH}"
;;
w)
export VALUE
yq -i "${query} = strenv(VALUE)" "${YAML_PATH}"
;;
d)
yq -i "del(${query})" "${YAML_PATH}"
;;
*)
usage
exit 1
;;
esac
}

if [ "$QUERY" == "-h" ]; then
usage
exit 0
elif [ $# -lt 3 ]; then
usage >&2
exit 1
fi

if ! command -v yq > /dev/null; then
echo "yq not found in path" >&2
exit 1
fi

if yq --version | grep '^.* version v4.*$' > /dev/null; then
handle_v4
elif yq --version | grep '^.* version 3.*$' > /dev/null; then
handle_v3
else
echo "unsupported yq version" >&2
exit 1
fi

0 comments on commit fc6c8a5

Please sign in to comment.