From 375b31fba18a675289155a94df03c3709c76e580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20Baung=C3=A5rd=20Hansen?= Date: Fri, 31 May 2024 16:55:47 +0200 Subject: [PATCH] Tests: Use CI images, and improve getting snapshot from Quay (#1452) * Tests: Improve getting snapshots from Quay - Get the version from `COMPONENT_VERSION` instead of hardcoding it in two places - Improve the regex so it explicitly sets the z version number to 1-2 digits avoiding mistakes in matches (i.e 2.10.* could match 2.2.10) - Don't differentiate between how we get snapshot between release and other branches (just always get the latest snapshot we can find for the release we want) - Since Quay returns multiple pages of tags, we might get unlikly and not get any tags for the release we actually want. Therefore we add quay side filtering as well to ensure we only get snapshots for a specific release, and also ensure we get the most number of results we can (100 is the max) Signed-off-by: Jacob Baungard Hansen * Tests: Always use CI generated images Prior to this commit, we would try to determine which components have changed, and only if a component changed, we would use the CI generated image. Otherwise we would try to get the latest snapshot from Quay. However, the way we get the latest snapshot from Quay is not guranteed to give us the very latest version (it will give us probably a resonably recent one), so to make sure we always test the latest change, just use all the images built using CI. Signed-off-by: Jacob Baungard Hansen --------- Signed-off-by: Jacob Baungard Hansen --- cicd-scripts/customize-mco.sh | 47 +++++++++++++++-------------------- scripts/test-utils.sh | 43 +++++++++++++------------------- 2 files changed, 37 insertions(+), 53 deletions(-) diff --git a/cicd-scripts/customize-mco.sh b/cicd-scripts/customize-mco.sh index 1e05394c3..1a6051f27 100755 --- a/cicd-scripts/customize-mco.sh +++ b/cicd-scripts/customize-mco.sh @@ -29,33 +29,26 @@ update_mco_cr() { if [ "${OPENSHIFT_CI}" == "true" ]; then # discard unstaged changes cd ${ROOTDIR} && git checkout -- . - for component_name in ${CHANGED_COMPONENTS}; do - component_anno_name=$(echo ${component_name} | sed 's/-/_/g') - get_image ${component_name} - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-${component_anno_name}-image: ${IMAGE}" ${ROOTDIR}/examples/mco/e2e/v1beta1/observability.yaml - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-${component_anno_name}-image: ${IMAGE}" ${ROOTDIR}/examples/mco/e2e/v1beta2/observability.yaml - done - else - if [[ -n ${RBAC_QUERY_PROXY_IMAGE_REF} ]]; then - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-rbac_query_proxy-image: ${RBAC_QUERY_PROXY_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta1/observability.yaml - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-rbac_query_proxy-image: ${RBAC_QUERY_PROXY_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta2/observability.yaml - fi - if [[ -n ${ENDPOINT_MONITORING_OPERATOR_IMAGE_REF} ]]; then - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-endpoint_monitoring_operator-image: ${ENDPOINT_MONITORING_OPERATOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta1/observability.yaml - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-endpoint_monitoring_operator-image: ${ENDPOINT_MONITORING_OPERATOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta2/observability.yaml - fi - if [[ -n ${GRAFANA_DASHBOARD_LOADER_IMAGE_REF} ]]; then - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-grafana_dashboard_loader-image: ${GRAFANA_DASHBOARD_LOADER_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta1/observability.yaml - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-grafana_dashboard_loader-image: ${GRAFANA_DASHBOARD_LOADER_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta2/observability.yaml - fi - if [[ -n ${METRICS_COLLECTOR_IMAGE_REF} ]]; then - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-metrics_collector-image: ${METRICS_COLLECTOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta1/observability.yaml - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-metrics_collector-image: ${METRICS_COLLECTOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta2/observability.yaml - fi - if [[ -n ${OBSERVATORIUM_OPERATOR_IMAGE_REF} ]]; then - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-observatorium_operator-image: ${OBSERVATORIUM_OPERATOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta1/observability.yaml - ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-metrics_collector-image: ${OBSERVATORIUM_OPERATOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta2/observability.yaml - fi + fi + if [[ -n ${RBAC_QUERY_PROXY_IMAGE_REF} ]]; then + ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-rbac_query_proxy-image: ${RBAC_QUERY_PROXY_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta1/observability.yaml + ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-rbac_query_proxy-image: ${RBAC_QUERY_PROXY_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta2/observability.yaml + fi + if [[ -n ${ENDPOINT_MONITORING_OPERATOR_IMAGE_REF} ]]; then + ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-endpoint_monitoring_operator-image: ${ENDPOINT_MONITORING_OPERATOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta1/observability.yaml + ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-endpoint_monitoring_operator-image: ${ENDPOINT_MONITORING_OPERATOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta2/observability.yaml + fi + if [[ -n ${GRAFANA_DASHBOARD_LOADER_IMAGE_REF} ]]; then + ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-grafana_dashboard_loader-image: ${GRAFANA_DASHBOARD_LOADER_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta1/observability.yaml + ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-grafana_dashboard_loader-image: ${GRAFANA_DASHBOARD_LOADER_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta2/observability.yaml + fi + if [[ -n ${METRICS_COLLECTOR_IMAGE_REF} ]]; then + ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-metrics_collector-image: ${METRICS_COLLECTOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta1/observability.yaml + ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-metrics_collector-image: ${METRICS_COLLECTOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta2/observability.yaml + fi + if [[ -n ${OBSERVATORIUM_OPERATOR_IMAGE_REF} ]]; then + ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-observatorium_operator-image: ${OBSERVATORIUM_OPERATOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta1/observability.yaml + ${SED_COMMAND} "/annotations.*/a \ \ \ \ mco-metrics_collector-image: ${OBSERVATORIUM_OPERATOR_IMAGE_REF}" ${ROOTDIR}/examples/mco/e2e/v1beta2/observability.yaml fi # Add mco-imageTagSuffix annotation diff --git a/scripts/test-utils.sh b/scripts/test-utils.sh index 53f86ad30..c59b4d471 100755 --- a/scripts/test-utils.sh +++ b/scripts/test-utils.sh @@ -2,38 +2,29 @@ # Copyright (c) 2024 Red Hat, Inc. # Copyright Contributors to the Open Cluster Management project -VERSION="2.11.0" +WORKDIR="$( + cd "$(dirname "$0")" || exit + pwd -P +)" -# Use the PR mirror image for PRs against main branch. -get_pr_image() { - BRANCH="" - LATEST_SNAPSHOT="" - - if [[ ${PULL_BASE_REF} == "main" ]]; then - LATEST_SNAPSHOT="${VERSION}-PR${PULL_NUMBER}-${PULL_PULL_SHA}" - fi - - # trim the leading and tailing quotes - LATEST_SNAPSHOT="${LATEST_SNAPSHOT#\"}" - LATEST_SNAPSHOT="${LATEST_SNAPSHOT%\"}" - echo ${LATEST_SNAPSHOT} -} +# Gets version from the component version without the z, i.e 2.11 +VERSION=$(awk -F '.' '{ print $1"."$2 }' <"$WORKDIR"/../COMPONENT_VERSION) +# Tries to get the latest snapshot for the current release +# Note if there are more than 100 snapshots per release +# we might not get the latest as the quay API can only return +# 100 results, and we only look at the first page. get_latest_snapshot() { - BRANCH="" - LATEST_SNAPSHOT="" SNAPSHOT_RELEASE=${SNAPSHOT_RELEASE:=$VERSION} - MATCH=$SNAPSHOT_RELEASE".*-SNAPSHOT" - if [[ ${PULL_BASE_REF} == "release-"* ]]; then - BRANCH=${PULL_BASE_REF#"release-"} - LATEST_SNAPSHOT=$(curl https://quay.io/api/v1/repository/open-cluster-management/multicluster-observability-operator | jq '.tags|with_entries(select(.key|test("'${BRANCH}'.*-SNAPSHOT-*")))|keys[length-1]') - fi - if [[ ${LATEST_SNAPSHOT} == "null" ]] || [[ ${LATEST_SNAPSHOT} == "" ]]; then - LATEST_SNAPSHOT=$(curl https://quay.io/api/v1/repository/stolostron/multicluster-observability-operator/tag/ | jq --arg MATCH "$MATCH" '.tags[] | select(.name | match($MATCH; "i") ).name' | sort -r --version-sort | head -n 1) - fi + # matches: + # version number (i.e 2.11) + # z version 1-2 digits + # -SNAPSHOT + MATCH=$SNAPSHOT_RELEASE".\d{1,2}-SNAPSHOT" + LATEST_SNAPSHOT=$(curl "https://quay.io/api/v1/repository/stolostron/multicluster-observability-operator/tag/?filter_tag_name=like:$SNAPSHOT_RELEASE&limit=100" | jq --arg MATCH "$MATCH" '.tags[] | select(.name | match($MATCH; "i") ).name' | sort -r --version-sort | head -n 1) # trim the leading and tailing quotes LATEST_SNAPSHOT="${LATEST_SNAPSHOT#\"}" LATEST_SNAPSHOT="${LATEST_SNAPSHOT%\"}" - echo ${LATEST_SNAPSHOT} + echo "${LATEST_SNAPSHOT}" }