diff --git a/.ci/aarch64/kubernetes/init.sh b/.ci/aarch64/kubernetes/init.sh index aa73be8e0..dced60f88 100755 --- a/.ci/aarch64/kubernetes/init.sh +++ b/.ci/aarch64/kubernetes/init.sh @@ -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" diff --git a/.ci/ci-fast-return.sh b/.ci/ci-fast-return.sh index e165c12f6..678ad268b 100755 --- a/.ci/ci-fast-return.sh +++ b/.ci/ci-fast-return.sh @@ -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 diff --git a/.ci/ci_crio_entry_point.sh b/.ci/ci_crio_entry_point.sh index 05cbd8e6f..decd9a4d6 100644 --- a/.ci/ci_crio_entry_point.sh +++ b/.ci/ci_crio_entry_point.sh @@ -121,21 +121,25 @@ cd "${katacontainers_repo_dir}" # Install yq ${GOPATH}/src/${tests_repo}/.ci/install_yq.sh +# YQ_SHIM Usage: +# ./yq-shim.sh [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}" diff --git a/.ci/filter/filter_k8s_test.sh b/.ci/filter/filter_k8s_test.sh index 2b90076d9..b4188160d 100755 --- a/.ci/filter/filter_k8s_test.sh +++ b/.ci/filter/filter_k8s_test.sh @@ -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}" diff --git a/.ci/filter/filter_test_union.sh b/.ci/filter/filter_test_union.sh index 8dd7de862..69ba0b704 100755 --- a/.ci/filter/filter_test_union.sh +++ b/.ci/filter/filter_test_union.sh @@ -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[@]}" diff --git a/.ci/lib.sh b/.ci/lib.sh index 7156a3a26..4aac64c5b 100755 --- a/.ci/lib.sh +++ b/.ci/lib.sh @@ -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" } diff --git a/.ci/ppc64le/kubernetes/init.sh b/.ci/ppc64le/kubernetes/init.sh index 57c6d2740..22b3ad20e 100644 --- a/.ci/ppc64le/kubernetes/init.sh +++ b/.ci/ppc64le/kubernetes/init.sh @@ -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" diff --git a/.ci/yq-shim.sh b/.ci/yq-shim.sh new file mode 100755 index 000000000..723d06099 --- /dev/null +++ b/.ci/yq-shim.sh @@ -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 [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