Skip to content

Commit

Permalink
fix(CVP-4421): get_unreleased_bundles returns a jq error
Browse files Browse the repository at this point in the history
1. Fix get_unreleased_bundles returning a jq error
The variables that were passed to jq --argjson
were not valid json arrays
2. Modify get_highest_bundle_version to return
a bundle image field rather than a bundle name
Signed-off-by: Anna Rania <[email protected]>
  • Loading branch information
Anna Rania authored and dirgim committed Feb 12, 2025
1 parent f9a0dbb commit d28ed88
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
31 changes: 27 additions & 4 deletions test/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,27 @@ extract_differential_fbc_metadata() {

# Ensure that the jq arrays are flattened and unique. The process is different for each operation
if [[ "$EXTRACT_OPERATION" == "unique_bundles" ]]; then
unique_fbc=$(echo "$package_result_fbc" | jq -cR 'split(" ") | map( select(length > 0))')
unique_index=$(echo "$package_result_index" | jq -cR 'split(" ") | map( select(length > 0))')
unique_fbc=$(echo "$package_result_fbc" | tr '\n' ' ' | jq -Rc 'split(" ") | map(select(length > 0))')
unique_index=$(echo "$package_result_index" | tr '\n' ' ' | jq -Rc 'split(" ") | map(select(length > 0))')
elif [[ "$EXTRACT_OPERATION" == "related_images" ]]; then
unique_fbc=$(echo "$package_result_fbc" | jq -s "flatten(1) | unique")
unique_index=$(echo "$package_result_index" | jq -s "flatten(1) | unique")
fi

# Store JSON variables into temporary files to avoid "/usr/bin/jq: Argument list too long"
echo "$unique_index" > /tmp/unique_index.json
echo "$unique_fbc" > /tmp/unique_fbc.json

# Get the images that are only in the fbc fragment
local unreleased_result
unreleased_result=$(jq -n --argjson released "$unique_index" --argjson unreleased "$unique_fbc" '{"released": $released,"unreleased":$unreleased} | .unreleased-.released')
unreleased_result=$(jq -n \
--slurpfile released /tmp/unique_index.json \
--slurpfile unreleased /tmp/unique_fbc.json \
'{"released": $released[0], "unreleased": $unreleased[0]} | .unreleased - .released')

# Cleanup temporary files
rm -f /tmp/unique_index.json /tmp/unique_fbc.json

echo "$unreleased_result"
}

Expand Down Expand Up @@ -948,5 +959,17 @@ get_highest_bundle_version() {
exit 1
fi

echo "$highest_bundle"
# Find the corresponding image name for the highest bundle
local bundle_image
bundle_image=$(echo "$RENDER_OUT_FBC" | jq -r --arg bundle "$highest_bundle" '
select(.schema == "olm.bundle" and .name == $bundle) | .image
')

# Check if an image was found
if [[ -z "$bundle_image" || "$bundle_image" == "null" ]]; then
echo "get_highest_bundle_version: No image found for bundle: $highest_bundle" >&2
exit 1
fi

echo "$bundle_image"
}
10 changes: 9 additions & 1 deletion unittests_bash/test_utils.bats
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ teardown() {

@test "Get Unreleased Bundle: registry/fbc-fragment:tag@valid-success" {
run get_unreleased_bundles -i registry/fbc-fragment:tag@valid-success
echo "$output"
EXPECTED_RESPONSE=$(echo "registry.redhat.io/rhbk/keycloak-operator-bundle@my-sha registry.redhat.io/not-rhbk/operator-bundle@my-other-sha" | tr ' ' '\n')
[[ "${EXPECTED_RESPONSE}" = "${output}" && "$status" -eq 0 ]]
}
Expand Down Expand Up @@ -674,10 +675,17 @@ EOF
}
]
}
{
"schema": "olm.bundle",
"name": "kubevirt-hyperconverged-operator.v4.17.5",
"package": "kubevirt-hyperconverged-v1",
"image": "registry.redhat.io/container-native-virtualization/hco-bundle-registry@sha256:4f100135ccbfc726f4b1887703ef7a08453b48c202ba04c0fb7382f0fec637db",
"properties": []
}
EOF
)
run get_highest_bundle_version "${RENDER_OUT_FBC}" "${PACKAGE_NAME}" "${CHANNEL_NAME}"
EXPECTED_RESPONSE="kubevirt-hyperconverged-operator.v4.17.5"
EXPECTED_RESPONSE="registry.redhat.io/container-native-virtualization/hco-bundle-registry@sha256:4f100135ccbfc726f4b1887703ef7a08453b48c202ba04c0fb7382f0fec637db"
echo "${output}"
[[ "${EXPECTED_RESPONSE}" = "${output}" && "$status" -eq 0 ]]
}
Expand Down

0 comments on commit d28ed88

Please sign in to comment.