Skip to content

Commit

Permalink
Get lates release with goproxy
Browse files Browse the repository at this point in the history
Signed-off-by: peppi-lotta <[email protected]>
  • Loading branch information
peppi-lotta committed Nov 27, 2024
1 parent 5e6f687 commit 638627d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 35 deletions.
3 changes: 3 additions & 0 deletions 03_launch_mgmt_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ source lib/releases.sh
# shellcheck disable=SC1091
source lib/network.sh

# Default CAPI_CONFIG_FOLDER to $HOME/.config folder if XDG_CONFIG_HOME not set
CONFIG_FOLDER="${XDG_CONFIG_HOME:-$HOME/.config}"
export CAPI_CONFIG_FOLDER="${CONFIG_FOLDER}/cluster-api"
export IRONIC_HOST="${CLUSTER_BARE_METAL_PROVISIONER_HOST}"
export IRONIC_HOST_IP="${CLUSTER_BARE_METAL_PROVISIONER_IP}"
export REPO_IMAGE_PREFIX="quay.io"
Expand Down
99 changes: 64 additions & 35 deletions lib/releases.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
#!/bin/bash

# Requires parameters url and version. An optional parameter can be given to
# exclude some versions.
# Example usage:
# get_latest_release_from_goproxy "https://proxy.golang.org/sigs.k8s.io/cluster-api/@v/list" "v1.8." "beta|rc|pre|alpha"
get_latest_release_from_goproxy() {
local proxuUrl="${1:?no release path is given}"
local release="${2:?no release given}"
local exclude="${3:-}"

# This gets the latest release
if [[ -z "${exclude}" ]]; then
release_tag=$(curl -si "${proxuUrl}" | sort -rV | grep -m1 "^${release}")
else
# prune based on exluded values given in the command
release_tag=$(curl -si "${proxuUrl}" | sort -rV | grep -vE "${exclude}" | grep -m1 "${release}")
fi

# if release_tag is not found
if [[ -z "${release_tag}" ]]; then
echo "Error: release is not found from ${release_path}" >&2
exit 1
fi
echo "${release_tag}"
}

function get_latest_release() {

# fail when release_path is not passed
Expand Down Expand Up @@ -65,56 +90,60 @@ function get_latest_release() {
fi
}

# CAPM3, CAPI and BMO release path
CAPIRELEASEPATH="{https://api.github.com/repos/${CAPI_BASE_URL:-kubernetes-sigs/cluster-api}/releases}"

CAPIGOPROXY="https://proxy.golang.org/sigs.k8s.io/cluster-api/@v/list"
# CAPM3, CAPI and BMO releases
if [ "${CAPM3RELEASEBRANCH}" = "release-1.6" ]; then
if [[ "${CAPM3RELEASEBRANCH}" = "release-1.6" ]]; then
# 1.6.99 points to the head of the release-1.6 branch. Local override for CAPM3 is created for this version.
export CAPM3RELEASE="v1.6.99"
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release "${CAPIRELEASEPATH}" "v1.6.")}"
elif [ "${CAPM3RELEASEBRANCH}" = "release-1.7" ]; then
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release_from_goproxy "${CAPIGOPROXY}" "v1.6.")}"
elif [[ "${CAPM3RELEASEBRANCH}" = "release-1.7" ]]; then
# 1.7.99 points to the head of the release-1.7 branch. Local override for CAPM3 is created for this version.
export CAPM3RELEASE="v1.7.99"
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release "${CAPIRELEASEPATH}" "v1.7.")}"
elif [ "${CAPM3RELEASEBRANCH}" = "release-1.8" ]; then
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release_from_goproxy "${CAPIGOPROXY}" "v1.7.")}"
elif [[ "${CAPM3RELEASEBRANCH}" = "release-1.8" ]]; then
# 1.8.99 points to the head of the release-1.8 branch. Local override for CAPM3 is created for this version.
export CAPM3RELEASE="v1.8.99"
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release "${CAPIRELEASEPATH}" "v1.8.")}"
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release_from_goproxy "${CAPIGOPROXY}" "v1.8.")}"
else
# 1.9.99 points to the head of the main branch of CAPM3. Local override for CAPM3 is created for this version.
export CAPM3RELEASE="v1.9.99"
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release "${CAPIRELEASEPATH}" "v1.8.")}"
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release_from_goproxy "${CAPIGOPROXY}" "v1.8.")}"
fi

CAPIBRANCH="${CAPIBRANCH:-${CAPIRELEASE}}"

# On first iteration, jq might not be installed
if [[ "$CAPIRELEASE" == "" ]]; then
command -v jq &>/dev/null && echo "Failed to fetch CAPI release from Github" && exit 1
fi

if [[ "$CAPM3RELEASE" == "" ]]; then
command -v jq &>/dev/null && echo "Failed to fetch CAPM3 release from Github" && exit 1
if [[ -z "${CAPIRELEASE}" ]]; then
echo "Failed to fetch CAPI release from GOPROXY, now trying to fetch with Github"
# CAPM3, CAPI and BMO release path
CAPIRELEASEPATH="{https://api.github.com/repos/${CAPI_BASE_URL:-kubernetes-sigs/cluster-api}/releases}"

# CAPM3, CAPI and BMO releases
if [[ "${CAPM3RELEASEBRANCH}" = "release-1.6" ]]; then
# 1.6.99 points to the head of the release-1.6 branch. Local override for CAPM3 is created for this version.
export CAPM3RELEASE="v1.6.99"
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release "${CAPIRELEASEPATH}" "v1.6.")}"
elif [[ "${CAPM3RELEASEBRANCH}" = "release-1.7" ]]; then
# 1.7.99 points to the head of the release-1.7 branch. Local override for CAPM3 is created for this version.
export CAPM3RELEASE="v1.7.99"
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release "${CAPIRELEASEPATH}" "v1.7.")}"
elif [[ "${CAPM3RELEASEBRANCH}" = "release-1.8" ]]; then
# 1.8.99 points to the head of the release-1.8 branch. Local override for CAPM3 is created for this version.
export CAPM3RELEASE="v1.8.99"
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release "${CAPIRELEASEPATH}" "v1.8.")}"
else
# 1.9.99 points to the head of the main branch of CAPM3. Local override for CAPM3 is created for this version.
export CAPM3RELEASE="v1.9.99"
export CAPIRELEASE="${CAPIRELEASE:-$(get_latest_release "${CAPIRELEASEPATH}" "v1.8.")}"
fi
fi

# Set CAPI_CONFIG_FOLDER variable according to CAPIRELEASE minor version
# Starting from CAPI v1.5.0 version cluster-api config folder location has changed
# to XDG_CONFIG_HOME folder.
# Following code defines the cluster-api config folder location according to CAPI
# release version

# TODO(Sunnatillo): Following condition should be removed when CAPM3 v1.4 reaches EOL
# NOTE(Sunnatillo): When CAPM3 v1.4 reaches EOL CAPI_CONFIG_FOLDER variable can be removed
# for the sake of reducing variables
CAPIBRANCH="${CAPIBRANCH:-${CAPIRELEASE}}"

version_string="${CAPIRELEASE#v}"
IFS='.' read -r _ minor _ <<< "$version_string"
if [[ -z "${CAPIRELEASE}" ]]; then
echo "Failed to fetch CAPI release from Github"
exit 1
fi

if [ "$minor" -lt 5 ]; then
export CAPI_CONFIG_FOLDER="${HOME}/.cluster-api"
else
# Default CAPI_CONFIG_FOLDER to $HOME/.config folder if XDG_CONFIG_HOME not set
CONFIG_FOLDER="${XDG_CONFIG_HOME:-$HOME/.config}"
export CAPI_CONFIG_FOLDER="${CONFIG_FOLDER}/cluster-api"
if [[ -z "${CAPM3RELEASE}" ]]; then
echo "Failed to fetch CAPM3 release from Github"
exit 1
fi

0 comments on commit 638627d

Please sign in to comment.