Skip to content

Commit cdb0d99

Browse files
authored
Helm install check (#359)
Issue #, if available: aws-controllers-k8s/community#1436 Description of changes: - Add helm version check function - Add helm installation helper script - Modify k8s_controller_gen_version_equals function and its comment By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent fe61d04 commit cdb0d99

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

scripts/build-controller-release.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ if ! k8s_controller_gen_version_equals "$CONTROLLER_TOOLS_VERSION"; then
2525
exit 1
2626
fi
2727

28+
if ! helm_version_equals_or_greater "$HELM_VERSION"; then
29+
echo "FATAL: Existing version of helm "`helm version --template='Version: {{.Version}}'`", required version is $HELM_VERSION."
30+
echo "FATAL: Please update helm, or uninstall helm and install the required version with scripts/install-helm.sh."
31+
exit 1
32+
fi
33+
2834
ACK_GENERATE_CACHE_DIR=${ACK_GENERATE_CACHE_DIR:-"$HOME/.cache/aws-controllers-k8s"}
2935
# The ack-generate code generator is in a separate source code repository,
3036
# typically at $GOPATH/src/github.com/aws-controllers-k8s/code-generator

scripts/install-helm.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# ./scripts/install-helm.sh
4+
#
5+
# Installs the latest version helm if not installed.
6+
#
7+
# NOTE: helm will be installed to /usr/local/bin/helm
8+
9+
set -eo pipefail
10+
11+
SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
12+
ROOT_DIR="$SCRIPTS_DIR/.."
13+
14+
source "$SCRIPTS_DIR/lib/common.sh"
15+
16+
if ! is_installed helm ; then
17+
__helm_url="https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3"
18+
echo -n "installing helm from $__helm_url ... "
19+
curl --silent "$__helm_url" | bash 1>/dev/null
20+
echo "ok."
21+
fi

scripts/lib/common.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22

33
CONTROLLER_TOOLS_VERSION="v0.7.0"
4+
HELM_VERSION="v3.7"
45

56
# setting the -x option if debugging is true
67
if [[ "${DEBUG:-"false"}" = "true" ]]; then
@@ -91,25 +92,41 @@ debug_msg() {
9192
echo "$__debug_prefix$__indent$__msg"
9293
}
9394

94-
# controller_gen_version_equals accepts a string version and returns 0 if the
95+
# k8s_controller_gen_version_equals accepts a string version and returns 0 if the
9596
# installed version of controller-gen matches the supplied version, otherwise
9697
# returns 1
9798
#
9899
# Usage:
99100
#
100-
# if controller_gen_version_equals "v0.4.0"; then
101+
# if k8s_controller_gen_version_equals "v0.4.0"; then
101102
# echo "controller-gen is at version 0.4.0"
102103
# fi
103104
k8s_controller_gen_version_equals() {
104-
currentver="$(controller-gen --version | cut -d' ' -f2 | tr -d '\n')";
105-
requiredver="$1";
105+
local currentver="$(controller-gen --version | cut -d' ' -f2 | tr -d '\n')";
106+
local requiredver="$1";
106107
if [ "$currentver" = "$requiredver" ]; then
107108
return 0
108109
else
109110
return 1
110111
fi;
111112
}
112113

114+
# helm_version_equals_or_greater accepts a string version and returns 0 if the
115+
# installed version of helm matches or greater than the supplied version,
116+
# otherwise returns 1
117+
#
118+
# Usage:
119+
#
120+
# if helm_version_equals_or_greater "v3.9.0"; then
121+
# echo "Installed helm version is greater than or equal to version v3.9.0"
122+
# fi
123+
helm_version_equals_or_greater() {
124+
local currentver="$(helm version --template='Version: {{.Version}}'| cut -d' ' -f2 | tr -d '\n')"
125+
local requiredver="$1"
126+
printf '%s\n%s\n' $requiredver $currentver | sort -C -V
127+
return $?
128+
}
129+
113130
# is_public_ecr_logged_in returns 0 if the Docker client is authenticated
114131
# with ECR public and therefore can pull and push to ECR public, otherwise
115132
# returns 1

0 commit comments

Comments
 (0)