diff --git a/scripts/build-controller-release.sh b/scripts/build-controller-release.sh index d950942a..a31a3afe 100755 --- a/scripts/build-controller-release.sh +++ b/scripts/build-controller-release.sh @@ -25,6 +25,12 @@ if ! k8s_controller_gen_version_equals "$CONTROLLER_TOOLS_VERSION"; then exit 1 fi +if ! helm_version_equals_or_greater "$HELM_VERSION"; then + echo "FATAL: Existing version of helm "`helm version --template='Version: {{.Version}}'`", required version is $HELM_VERSION." + echo "FATAL: Please update helm, or uninstall helm and install the required version with scripts/install-helm.sh." + exit 1 +fi + ACK_GENERATE_CACHE_DIR=${ACK_GENERATE_CACHE_DIR:-"$HOME/.cache/aws-controllers-k8s"} # The ack-generate code generator is in a separate source code repository, # typically at $GOPATH/src/github.com/aws-controllers-k8s/code-generator diff --git a/scripts/install-helm.sh b/scripts/install-helm.sh new file mode 100755 index 00000000..a939881b --- /dev/null +++ b/scripts/install-helm.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# ./scripts/install-helm.sh +# +# Installs the latest version helm if not installed. +# +# NOTE: helm will be installed to /usr/local/bin/helm + +set -eo pipefail + +SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +ROOT_DIR="$SCRIPTS_DIR/.." + +source "$SCRIPTS_DIR/lib/common.sh" + +if ! is_installed helm ; then + __helm_url="https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3" + echo -n "installing helm from $__helm_url ... " + curl --silent "$__helm_url" | bash 1>/dev/null + echo "ok." +fi diff --git a/scripts/lib/common.sh b/scripts/lib/common.sh index d4002865..d9f6f018 100755 --- a/scripts/lib/common.sh +++ b/scripts/lib/common.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash CONTROLLER_TOOLS_VERSION="v0.7.0" +HELM_VERSION="v3.7" # setting the -x option if debugging is true if [[ "${DEBUG:-"false"}" = "true" ]]; then @@ -91,18 +92,18 @@ debug_msg() { echo "$__debug_prefix$__indent$__msg" } -# controller_gen_version_equals accepts a string version and returns 0 if the +# k8s_controller_gen_version_equals accepts a string version and returns 0 if the # installed version of controller-gen matches the supplied version, otherwise # returns 1 # # Usage: # -# if controller_gen_version_equals "v0.4.0"; then +# if k8s_controller_gen_version_equals "v0.4.0"; then # echo "controller-gen is at version 0.4.0" # fi k8s_controller_gen_version_equals() { - currentver="$(controller-gen --version | cut -d' ' -f2 | tr -d '\n')"; - requiredver="$1"; + local currentver="$(controller-gen --version | cut -d' ' -f2 | tr -d '\n')"; + local requiredver="$1"; if [ "$currentver" = "$requiredver" ]; then return 0 else @@ -110,6 +111,22 @@ k8s_controller_gen_version_equals() { fi; } +# helm_version_equals_or_greater accepts a string version and returns 0 if the +# installed version of helm matches or greater than the supplied version, +# otherwise returns 1 +# +# Usage: +# +# if helm_version_equals_or_greater "v3.9.0"; then +# echo "Installed helm version is greater than or equal to version v3.9.0" +# fi +helm_version_equals_or_greater() { + local currentver="$(helm version --template='Version: {{.Version}}'| cut -d' ' -f2 | tr -d '\n')" + local requiredver="$1" + printf '%s\n%s\n' $requiredver $currentver | sort -C -V + return $? +} + # is_public_ecr_logged_in returns 0 if the Docker client is authenticated # with ECR public and therefore can pull and push to ECR public, otherwise # returns 1