5 Install (or upgrade) an umbrella Helm Chart, and its subcharts, as separate Helm Releases
7 The umbrella Helm Chart is broken apart into a parent release and subchart releases.
8 Subcharts the are disabled (<chart>.enabled=false) will not be installed or upgraded.
9 All releases are grouped and deployed within the same namespace.
12 The deploy arguments must be a release and chart. The chart
13 argument can be either: a chart reference('stable/onap'), a path to a chart directory,
14 a packaged chart, or a fully qualified URL. For chart references, the latest
15 version will be specified unless the '--version' flag is set.
17 To override values in a chart, use either the '--values' flag and pass in a file
18 or use the '--set' flag and pass configuration from the command line, to force string
19 values, use '--set-string'.
21 You can specify the '--values'/'-f' flag multiple times. The priority will be given to the
22 last (right-most) file specified. For example, if both myvalues.yaml and override.yaml
23 contained a key called 'Test', the value set in override.yaml would take precedence:
25 $ helm deploy demo ./onap --namespace onap -f openstack.yaml -f overrides.yaml
27 You can specify the '--set' flag multiple times. The priority will be given to the
28 last (right-most) set specified. For example, if both 'bar' and 'newbar' values are
29 set for a key called 'foo', the 'newbar' value would take precedence:
31 $ helm deploy demo local/onap --namespace onap -f overrides.yaml --set log.enabled=false --set vid.enabled=false
34 helm deploy [RELEASE] [CHART] [flags]
37 --namespace string namespace to install the release into. Defaults to the current kube config namespace.
38 --set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
39 --set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
40 -f, --values valueFiles specify values in a YAML file or a URL(can specify multiple) (default [])
41 --verbose enables full helm install/upgrade output during deploy
42 --set-last-applied set the last-applied-configuration annotation on all objects.This annotation is required to restore services using Ark/Veloro backup restore.
46 generate_overrides() {
47 SUBCHART_NAMES=($(cat $COMPUTED_OVERRIDES | grep -v '^\s\s'))
49 for index in "${!SUBCHART_NAMES[@]}"; do
50 START=${SUBCHART_NAMES[index]}
51 END=${SUBCHART_NAMES[index+1]}
52 if [ "$START" = "global:" ]; then
53 echo "global:" > $GLOBAL_OVERRIDES
54 cat $COMPUTED_OVERRIDES | sed '/common:/,/consul:/d' \
55 | sed -n '/^'"$START"'/,/'log:'/p' | sed '1d;$d' >> $GLOBAL_OVERRIDES
57 SUBCHART_DIR="$CACHE_SUBCHART_DIR/$(echo "$START" |cut -d':' -f1)"
58 if [ -d "$SUBCHART_DIR" ]; then
59 if [ -z "$END" ]; then
60 cat $COMPUTED_OVERRIDES | sed -n '/^'"$START"'/,/'"$END"'/p' \
61 | sed '1d;$d' | cut -c3- > $SUBCHART_DIR/subchart-overrides.yaml
63 cat $COMPUTED_OVERRIDES | sed -n '/^'"$START"'/,/^'"$END"'/p' \
64 | sed '1d;$d' | cut -c3- > $SUBCHART_DIR/subchart-overrides.yaml
72 resolve_deploy_flags() {
75 i=0 ; while [ "$i" -lt "$n" ]; do
77 if [ "$PARAM" = "-f" ] || \
78 [ "$PARAM" = "--values" ] || \
79 [ "$PARAM" = "--set" ] || \
80 [ "$PARAM" = "--set-string" ] || \
81 [ "$PARAM" = "--version" ]; then
82 # skip param and its value
85 DEPLOY_FLAGS="$DEPLOY_FLAGS $PARAM"
96 until (kubectl get deployment -n $HELM_NAMESPACE | grep -P "\b$1\b") &>/dev/null; do
97 (( ++try > retries )) && exit 1
98 echo "$1 not found. Retry $try/$retries"
101 echo "$1 found. Waiting for pod intialisation"
106 #Deploy the srtimzi-kafka chart in advance. Dependent charts require the entity-operator
107 #for management of the strimzi crds
109 echo "waiting for ${RELEASE}-strimzi-entity-operator to be deployed"
110 check_for_dep ${RELEASE}-strimzi-entity-operator
114 if [ -z "$SUBCHART_RELEASE" ] || [ "$SUBCHART_RELEASE" = "$subchart" ]; then
115 LOG_FILE=$LOG_DIR/"${RELEASE}-${subchart}".log
118 helm upgrade -i "${RELEASE}-${subchart}" $CACHE_SUBCHART_DIR/$subchart \
119 $DEPLOY_FLAGS -f $GLOBAL_OVERRIDES -f $SUBCHART_OVERRIDES \
122 if [ "$VERBOSE" = "true" ]; then
125 echo "release \"${RELEASE}-${subchart}\" deployed"
127 # Add annotation last-applied-configuration if set-last-applied flag is set
128 if [ "$SET_LAST_APPLIED" = "true" ]; then
129 helm get manifest "${RELEASE}-${subchart}" \
130 | kubectl apply set-last-applied --create-annotation -n $HELM_NAMESPACE -f - \
134 if [ "$DELAY" = "true" ]; then
142 if [ -z "$1" ] || [ -z "$2" ]; then
149 FLAGS=$(echo ${@} | sed 's/^ *[^ ]* *[^ ]* *//')
150 CHART_REPO="$(echo "$CHART_URL" | cut -d'/' -f1)"
151 CHART_NAME="$(echo "$CHART_URL" | cut -d'/' -f2)"
153 CACHE_DIR=~/.local/share/helm/plugins/deploy/cache
154 echo "Use cache dir: $CACHE_DIR"
155 CHART_DIR=$CACHE_DIR/$CHART_NAME
156 CACHE_SUBCHART_DIR=$CHART_DIR-subcharts
157 LOG_DIR=$CHART_DIR/logs
159 # determine if verbose output is enabled
161 if expr "$FLAGS" : ".*--verbose.*" ; then
162 FLAGS="$(echo $FLAGS| sed -n 's/--verbose//p')"
165 # determine if delay for deployment is enabled
167 if expr "$FLAGS" : ".*--delay.*" ; then
168 FLAGS="$(echo $FLAGS| sed -n 's/--delay//p')"
171 # determine if set-last-applied flag is enabled
172 SET_LAST_APPLIED="false"
173 if expr "$FLAGS" : ".*--set-last-applied.*" ; then
174 FLAGS="$(echo $FLAGS| sed -n 's/--set-last-applied//p')"
175 SET_LAST_APPLIED="true"
177 if expr "$FLAGS" : ".*--dry-run.*" ; then
179 FLAGS="$FLAGS --debug"
182 # should pass all flags instead
183 NAMESPACE="$(echo $FLAGS | sed -n 's/.*\(namespace\).\s*/\1/p' | cut -c10- | cut -d' ' -f1)"
185 VERSION="$(echo $FLAGS | sed -n 's/.*\(version\).\s*/\1/p' | cut -c8- | cut -d' ' -f1)"
187 if [ ! -z $VERSION ]; then
188 VERSION="--version $VERSION"
191 # Remove all override values passed in as arguments. These will be used during dry run
192 # to resolve computed override values. Remaining flags will be passed on during
193 # actual upgrade/install of parent and subcharts.
194 DEPLOY_FLAGS=$(resolve_deploy_flags "$FLAGS")
196 # determine if upgrading individual subchart or entire parent + subcharts
197 SUBCHART_RELEASE="$(echo "$RELEASE" |cut -d'-' -f2)"
198 # update specified subchart without parent
199 RELEASE="$(echo "$RELEASE" |cut -d'-' -f1)"
200 if [ "$SUBCHART_RELEASE" = "$RELEASE" ]; then
204 # clear previously cached charts
207 # fetch umbrella chart (parent chart containing subcharts)
208 if [ -d "$CHART_URL" ]; then
210 cp -R $CHART_URL/* $CHART_DIR/
212 charts=$CHART_DIR/charts/*
213 for subchart in $charts ; do
214 tar xzf ${subchart} -C $CHART_DIR/charts/
216 rm -rf $CHART_DIR/charts/*.tgz
218 echo "fetching $CHART_URL"
219 helm fetch $CHART_URL --untar --untardir $CACHE_DIR $VERSION
222 # create log driectory
225 # move out subcharts to process separately
226 mkdir -p $CACHE_SUBCHART_DIR
227 mv $CHART_DIR/charts/* $CACHE_SUBCHART_DIR/
228 # temp hack - parent chart needs common subchart
229 mv $CACHE_SUBCHART_DIR/common $CHART_DIR/charts/
231 # disable dependencies
232 rm $CHART_DIR/Chart.lock
233 sed -n '1,/dependencies:/p;/description:/,$p' $CHART_DIR/Chart.yaml | grep -v dependencies > $CHART_DIR/deploy_Chart.yaml
234 mv $CHART_DIR/Chart.yaml $CHART_DIR/Chart.deploy
235 mv $CHART_DIR/deploy_Chart.yaml $CHART_DIR/Chart.yaml
237 # compute overrides for parent and all subcharts
238 COMPUTED_OVERRIDES=$CACHE_DIR/$CHART_NAME/computed-overrides.yaml
239 helm upgrade -i $RELEASE $CHART_DIR $FLAGS --dry-run --debug \
240 | sed -n '/COMPUTED VALUES:/,/HOOKS:/p' | sed '1d;$d' > $COMPUTED_OVERRIDES
242 # extract global overrides to apply to parent and all subcharts
243 GLOBAL_OVERRIDES=$CHART_DIR/global-overrides.yaml
244 generate_overrides $COMPUTED_OVERRIDES $GLOBAL_OVERRIDES
246 # upgrade/install parent chart first
247 if [ -z "$SUBCHART_RELEASE" ]; then
248 LOG_FILE=$LOG_DIR/${RELEASE}.log
251 helm upgrade -i $RELEASE $CHART_DIR $DEPLOY_FLAGS -f $COMPUTED_OVERRIDES \
254 if [ "$VERBOSE" = "true" ]; then
257 echo "release \"$RELEASE\" deployed"
259 # Add annotation last-applied-configuration if set-last-applied flag is set
260 if [ "$SET_LAST_APPLIED" = "true" ]; then
261 helm get manifest ${RELEASE} \
262 | kubectl apply set-last-applied --create-annotation -n $HELM_NAMESPACE -f - \
267 # upgrade/install each "enabled" subchart
268 cd $CACHE_SUBCHART_DIR/
269 #“helm ls” is an expensive command in that it can take a long time to execute.
270 #So cache the results to prevent repeated execution.
271 ALL_HELM_RELEASES=$(helm ls -q)
273 for subchart in strimzi cassandra mariadb-galera postgres ; do
274 SUBCHART_OVERRIDES=$CACHE_SUBCHART_DIR/$subchart/subchart-overrides.yaml
277 if [ -f $SUBCHART_OVERRIDES ]; then
278 SUBCHART_ENABLED=$(cat $SUBCHART_OVERRIDES | grep -c "^enabled: true")
280 if [ "${subchart}" = "strimzi" ] && [ $SUBCHART_ENABLED -eq 1 ]; then
283 # Deploy them at first
284 if [ $SUBCHART_ENABLED -eq 1 ]; then
287 array=($(echo "$ALL_HELM_RELEASES" | grep "${RELEASE}-${subchart}"))
289 for i in $(seq $(($n-1)) -1 0); do
290 helm del "${array[i]}"
295 for subchart in * ; do
296 SUBCHART_OVERRIDES=$CACHE_SUBCHART_DIR/$subchart/subchart-overrides.yaml
299 if [ -f $SUBCHART_OVERRIDES ]; then
300 SUBCHART_ENABLED=$(cat $SUBCHART_OVERRIDES | grep -c "^enabled: true")
302 if [ "${subchart}" = "strimzi" ] || [ "${subchart}" = "cassandra" ] || [ "${subchart}" = "mariadb-galera" ] || [ "${subchart}" = "postgres" ]; then
306 if [ $SUBCHART_ENABLED -eq 1 ]; then
309 array=($(echo "$ALL_HELM_RELEASES" | grep "${RELEASE}-${subchart}"))
311 for i in $(seq $(($n-1)) -1 0); do
312 helm del "${array[i]}"
317 # report on success/failures of installs/upgrades
318 helm ls --all-namespaces | grep -i FAILED | grep $RELEASE
320 HELM_VER=$(helm version --template "{{.Version}}")
323 case "${1:-"help"}" in
334 deploy $1 $2 $(echo ${@} | sed 's/^ *[^ ]* *[^ ]* *//')