Skip to content

Commit

Permalink
Tests: Use CI images, and improve getting snapshot from Quay (#1452)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>

---------

Signed-off-by: Jacob Baungard Hansen <[email protected]>
  • Loading branch information
jacobbaungard authored May 31, 2024
1 parent 0c92c63 commit 375b31f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 53 deletions.
47 changes: 20 additions & 27 deletions cicd-scripts/customize-mco.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 17 additions & 26 deletions scripts/test-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}

0 comments on commit 375b31f

Please sign in to comment.