#!/bin/bash
VALID_CHANNELS="stable candidate fast"
from="$1"
if [ -z "$from" ]; then
echo "Provide an openshift version to check upgrade path"
exit 1
fi
shift
to="$1"
if [ -z "$to" ]; then
to="$( echo "$from" | cut -d. -f1-2 | paste -sd. )"
fi
shift
channel="${1:-stable}"
if ! echo "$VALID_CHANNELS" | grep -q -w "$channel"; then
echo "Channel must be one of: $VALID_CHANNELS"
exit 1
fi
url="https://api.openshift.com/api/upgrades_info/v1/graph?channel=${channel}-${to}&arch=amd64"
echo "Checking upgrade path from ${from} to ${to} at ${url}"
curl \
--silent \
--header 'Accept:application/json' \
"$url" \
| jq -r ". as \$graph
| \$graph.nodes
| map(.version == \"${from}\")
| index(true) as \$orig
| \$graph.edges
| map(select(.[0] == \$orig)[1])
| map(\$graph.nodes[.])[].version" \
| sort --version-sort