6
6
# This script is not intended to be run directly
7
7
# Assumes bin/common.sh has been sourced
8
8
9
- if [ ! $( which helm) ]; then
10
- echo " helm not found on the current PATH"
11
- exit 1
9
+ if [ ! " $( which helm) " ]; then
10
+ echo " helm not found on the current PATH"
11
+ exit 1
12
12
fi
13
13
14
14
helmVer=$( helm version --short 2> /dev/null)
15
+ # shellcheck disable=SC2116,SC2086,SC2207
15
16
hver=( $( echo ${helmVer// [^0-9]/ } ) )
16
17
HELM_VER_MAJOR=${hver[0]}
17
18
HELM_VER_MINOR=${hver[1]}
@@ -25,115 +26,116 @@ if [ "$HELM_VER_MAJOR" == "2" ]; then
25
26
fi
26
27
27
28
if [ " $V4M_HELM_USE_LATEST " == " true" ]; then
28
- log_warn " ******This feature is NOT intended for use outside the project maintainers*******"
29
- log_warn " Environment variable V4M_HELM_USE_LATEST set; deploying *latest* version of all Helm charts"
29
+ log_warn " ******This feature is NOT intended for use outside the project maintainers*******"
30
+ log_warn " Environment variable V4M_HELM_USE_LATEST set; deploying *latest* version of all Helm charts"
30
31
fi
31
32
32
33
function helm2ReleaseExists {
33
- release=$1
34
- log_debug " Checking for Helm 2.x release of [$release ]"
35
- releases=$( kubectl get configmap --all-namespaces -l " OWNER=TILLER" -o name)
36
- if [[ $releases =~ configmap/$release \. v[0-9]+ ]]; then
37
- log_debug " A Helm 2.x release of [$release ] exists"
38
- return 0
39
- else
40
- return 1
41
- fi
34
+ release=$1
35
+ log_debug " Checking for Helm 2.x release of [$release ]"
36
+ releases=$( kubectl get configmap --all-namespaces -l " OWNER=TILLER" -o name)
37
+ if [[ $releases =~ configmap/$release \. v[0-9]+ ]]; then
38
+ log_debug " A Helm 2.x release of [$release ] exists"
39
+ return 0
40
+ else
41
+ return 1
42
+ fi
42
43
}
43
44
44
45
function helm3ReleaseExists {
45
- release=$1
46
- namespace=$2
47
- log_debug " Checking for Helm 3.x release of [$release ]"
48
- releases=$( kubectl get secret -n $namespace -l name=$release ,owner=helm -o name)
49
- if [[ $releases =~ secret/sh\. helm\. release\. v1\. $release \. v[0-9]+ ]]; then
50
- log_debug " A Helm 3.x release of [$release ] exists"
51
- return 0
52
- else
53
- return 1
54
- fi
46
+ release=$1
47
+ namespace=$2
48
+ log_debug " Checking for Helm 3.x release of [$release ]"
49
+ releases=$( kubectl get secret -n " $namespace " -l name=" $release " ,owner=helm -o name)
50
+ if [[ $releases =~ secret/sh\. helm\. release\. v1\. $release \. v[0-9]+ ]]; then
51
+ log_debug " A Helm 3.x release of [$release ] exists"
52
+ return 0
53
+ else
54
+ return 1
55
+ fi
55
56
}
56
57
57
58
function helm2ReleaseCheck {
58
- if [ " $HELM_RELEASE_CHECK " != " false" ]; then
59
- release=$1
60
- if helm2ReleaseExists $release ; then
61
- log_error " A Helm 2.x release of [$release ] already exists"
62
- log_error " Helm [$HELM_VER_FULL ] cannot manage the Helm 2.x release of [$release ]"
63
- exit 1
59
+ if [ " $HELM_RELEASE_CHECK " != " false" ]; then
60
+ release=$1
61
+ if helm2ReleaseExists " $release " ; then
62
+ log_error " A Helm 2.x release of [$release ] already exists"
63
+ log_error " Helm [$HELM_VER_FULL ] cannot manage the Helm 2.x release of [$release ]"
64
+ exit 1
65
+ fi
64
66
fi
65
- fi
66
67
}
67
68
68
69
function helmRepoAdd {
69
- repo=$1
70
- repoURL=$2
71
-
72
- # # If this is an air gap deployment, do nothing
73
- if [ " $AIRGAP_DEPLOYMENT " == " true" ]; then
74
- return 0
75
- fi
76
-
77
- HELM_FORCE_REPO_UPDATE=${HELM_FORCE_REPO_UPDATE:- true}
78
- if [[ ! $( helm repo list 2> /dev/null) =~ $repo [[:space:]] ]]; then
79
- log_info " Adding [$repo ] helm repository"
80
- helm repo add $repo $repoURL
81
- else
82
- log_debug " The helm repo [$repo ] already exists"
83
- if [ " $HELM_FORCE_REPO_UPDATE " == " true" ]; then
84
- log_debug " Forcing update of [$repo ] helm repo to [$repoURL ]"
85
-
86
- # Helm 3.3.2 changed 'repo add' behavior and added the --force-update flag
87
- # https://github.com/helm/helm/releases/tag/v3.3.2
88
- if [[ $HELM_VER_MINOR -lt 3 || ( $HELM_VER_MINOR -eq 3 && $HELM_VER_PATCH -lt 2) ]]; then
89
- helm repo add $repo $repoURL
90
- else
91
- helm repo add --force-update $repo $repoURL
92
- fi
70
+ repo=$1
71
+ repoURL=$2
93
72
73
+ # # If this is an air gap deployment, do nothing
74
+ if [ " $AIRGAP_DEPLOYMENT " == " true" ]; then
75
+ return 0
76
+ fi
77
+
78
+ HELM_FORCE_REPO_UPDATE=${HELM_FORCE_REPO_UPDATE:- true}
79
+ # shellcheck disable=SC1087
80
+ if [[ ! $( helm repo list 2> /dev/null) =~ $repo [[:space:]] ]]; then
81
+ log_info " Adding [$repo ] helm repository"
82
+ helm repo add " $repo " " $repoURL "
83
+ else
84
+ log_debug " The helm repo [$repo ] already exists"
85
+ if [ " $HELM_FORCE_REPO_UPDATE " == " true" ]; then
86
+ log_debug " Forcing update of [$repo ] helm repo to [$repoURL ]"
87
+
88
+ # Helm 3.3.2 changed 'repo add' behavior and added the --force-update flag
89
+ # https://github.com/helm/helm/releases/tag/v3.3.2
90
+ if [[ $HELM_VER_MINOR -lt 3 || ( $HELM_VER_MINOR -eq 3 && $HELM_VER_PATCH -lt 2) ]]; then
91
+ helm repo add " $repo " " $repoURL "
92
+ else
93
+ helm repo add --force-update " $repo " " $repoURL "
94
+ fi
95
+ fi
94
96
fi
95
- fi
96
97
}
97
98
98
99
function get_helmchart_reference {
99
- local chart_repository chart_name chart_version
100
-
101
- chart_repository=$1
102
- chart_name=$2
103
- chart_version=$3
104
-
105
- if [ -z " $chart_repository " ]; then
106
- echo " 'ERROR: Helm chart repository not specified'"
107
- return 1
108
- elif [ -z " $chart_name " ]; then
109
- echo " 'ERROR: Helm chart name not specified'"
110
- return 1
111
- elif [ -z " $chart_version " ]; then
112
- echo " 'ERROR: Helm chart version not specified'"
113
- return 1
114
- else
115
- # all parms have values
116
- :
117
- fi
118
-
119
- if [ " $AIRGAP_HELM_FORMAT " == " tgz" ]; then
120
- echo " ${AIRGAP_HELM_REPO} /${chart_name} -${chart_version} .tgz"
121
- elif [ " $AIRGAP_HELM_FORMAT " == " oci" ]; then
122
- echo " oci://${AIRGAP_HELM_REPO} /${chart_repository} /${chart_name} "
123
- else
124
- echo " ${chart_repository} /${chart_name} "
125
- fi
100
+ local chart_repository chart_name chart_version
101
+
102
+ chart_repository=$1
103
+ chart_name=$2
104
+ chart_version=$3
105
+
106
+ if [ -z " $chart_repository " ]; then
107
+ echo " 'ERROR: Helm chart repository not specified'"
108
+ return 1
109
+ elif [ -z " $chart_name " ]; then
110
+ echo " 'ERROR: Helm chart name not specified'"
111
+ return 1
112
+ elif [ -z " $chart_version " ]; then
113
+ echo " 'ERROR: Helm chart version not specified'"
114
+ return 1
115
+ else
116
+ # all parms have values
117
+ :
118
+ fi
119
+
120
+ if [ " $AIRGAP_HELM_FORMAT " == " tgz" ]; then
121
+ echo " ${AIRGAP_HELM_REPO} /${chart_name} -${chart_version} .tgz"
122
+ elif [ " $AIRGAP_HELM_FORMAT " == " oci" ]; then
123
+ echo " oci://${AIRGAP_HELM_REPO} /${chart_repository} /${chart_name} "
124
+ else
125
+ echo " ${chart_repository} /${chart_name} "
126
+ fi
126
127
}
127
128
function get_helm_versionstring {
128
129
if [ " $V4M_HELM_USE_LATEST " == " true" ]; then
129
- : # return null string
130
+ : # return null string
130
131
else
131
- # Explicitly use printf instead of echo to avoid quote issues
132
- printf -- " --version %s" " $1 "
132
+ # Explicitly use printf instead of echo to avoid quote issues
133
+ printf -- " --version %s" " $1 "
133
134
fi
134
135
135
136
return
136
137
}
138
+
137
139
export HELM_VER_FULL HELM_VER_MAJOR HELM_VER_MINOR HELM_VER_PATCH
138
140
export -f helm2ReleaseExists
139
141
export -f helm3ReleaseExists
0 commit comments