Skip to content

Commit

Permalink
Helm Upgrade fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac committed Mar 6, 2020
1 parent 2bc13e6 commit 78ec1e2
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 32 deletions.
61 changes: 37 additions & 24 deletions deploy/ci/automation/helmtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ RESET="\033[0m"
BOLD="\033[1m"

echo -e "${YELLOW}${BOLD}"
echo "================="
echo "Stratos Helm Test"
echo "================="
echo "========================================================================================================="
echo "===== Stratos Helm Tests ====="
echo "========================================================================================================="
echo -e "${RESET}"

set -e
Expand Down Expand Up @@ -82,7 +82,7 @@ function checkVersion {
VERS=$1
STATUS=$(helm list ${NAME} | grep ${NAME})
STATUS=$(echo $STATUS | awk '{$1=$1};1')
local HELM_STATUS_REGEX='^([a-z\-]*) ([0-9]*) ([A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]) ([A-Z]*) ([0-9\.a-z\-]*) ([0-9\.]*) ([a-z\-]*)'
local HELM_STATUS_REGEX='^([a-z\-]*) ([0-9]*) ([A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]) ([A-Z]*) ([0-9\.a-z\-]*) ([0-9\.a-z\-]*) ([a-z\-]*)'
echo -e $STATUS
if [[ "${STATUS}" =~ ${HELM_STATUS_REGEX} ]]; then
# 6 is version
Expand All @@ -94,11 +94,17 @@ function checkVersion {
echo "Helm status parsing failed"
exit 1
fi

echo "Helm release version ok (${BASH_REMATCH[5]})"
}

function log {
MSG=$1
echo -e "${CYAN}${BOLD}${MSG}${RESET}"
echo -e "${CYAN}${BOLD}"
echo "========================================================================================================="
echo "==>> ${MSG}"
echo "========================================================================================================="
echo -e "${RESET}"
}

log "Performing checks..."
Expand All @@ -117,6 +123,14 @@ if [ "$EXISTING" -ne 1 ]; then
helm repo add ${HELM_REPO_NAME} ${HELM_REPO}
fi

KUBE_FOLDER="${STRATOS}/deploy/kubernetes"
HELM_TMP="${STRATOS}/deploy/kubernetes/helm-chart"
echo $HELM_TMP
echo "${KUBE_FOLDER}"
pushd "${KUBE_FOLDER}" > /dev/null
rm -rf *.tgz
popd > /dev/null

# Update repos
helm repo update

Expand All @@ -133,37 +147,36 @@ waitForHelmRelease
# Try and upgrade to the latest Chart

# Copy the helm chart folder to a temp location
TMP_DIR=${TMP_DIR:-/tmp}
HELM_TMP=${TMP_DIR}/stratos_helm_test

# Use the buil script to build the Helm Chart
KUBE_FOLDER="${STRATOS}/deploy/kubernetes"
HELM_TMP="${STRATOS}/deploy/kubernetes/helm-chart"
echo $HELM_TMP

rm -rf ${HELM_TMP}
mkdir -p ${HELM_TMP}
cp -R "${STRATOS}/deploy/kubernetes/console" ${HELM_TMP}
echo "${KUBE_FOLDER}"
ls -al "${KUBE_FOLDER}"
rm -rf "${KUBE_FOLDER}/*.tgz"

pushd ${HELM_TMP} > /dev/null
# Make sure we can package the chart
helm package ${HELM_TMP}/console
# Build the chart with the specific version for images
"${STRATOS}/deploy/kubernetes/build.sh" -z -c -n -t ${DEV_IMAGE_VERSION}

CHART_FILE=$(ls ${HELM_TMP}/*.tgz)
CHART_FILE=$(ls ${KUBE_FOLDER}/*.tgz)
CHART_FILE=$(printf %q "${CHART_FILE}")
echo "Chart file path: ${CHART_FILE}"

popd > /dev/null

log "Upgrading using latest Helm Chart"
helm upgrade ${NAME} ${CHART_FILE} --recreate-pods --debug --set consoleVersion=${DEV_IMAGE_VERSION} --set imagePullPolicy=Always

checkVersion console-0.1.0
checkVersion console-${DEV_IMAGE_VERSION}
waitForHelmRelease

# Change just the chart version and try to upgrade
sed -i.bak -e 's/version: 0.1.0/version: 0.2.0/g' ${HELM_TMP}/console/Chart.yaml
sed -i.bak -e 's/appVersion: 0.1.0/appVersion: 0.2.0/g' ${HELM_TMP}/console/Chart.yaml
cat ${HELM_TMP}/console/Chart.yaml
sed -i.bak -e 's/version: '"${DEV_IMAGE_VERSION}"'/version: 0.2.0/g' ${HELM_TMP}/Chart.yaml
sed -i.bak -e 's/appVersion: '"${DEV_IMAGE_VERSION}"'/appVersion: 0.2.0/g' ${HELM_TMP}/Chart.yaml
cat ${HELM_TMP}/Chart.yaml

log "Upgrading using latest Helm Chart (checking chart upgrade)"
helm upgrade ${NAME} ${HELM_TMP}/console --recreate-pods --debug --set consoleVersion=${DEV_IMAGE_VERSION} --set imagePullPolicy=Always
helm upgrade ${NAME} ${HELM_TMP} --recreate-pods --debug --set imagePullPolicy=Always

waitForHelmRelease
checkVersion console-0.2.0
Expand All @@ -172,10 +185,10 @@ checkVersion console-0.2.0
deleteRelease

log "Installing using latest Helm Chart"
helm install ${CHART_FILE} --name ${NAME} --namespace ${NAMESPACE} --set consoleVersion=${DEV_IMAGE_VERSION} --set imagePullPolicy=Always
helm install ${CHART_FILE} --name ${NAME} --namespace ${NAMESPACE} --set imagePullPolicy=Always

waitForHelmRelease
checkVersion console-0.1.0
checkVersion console-${DEV_IMAGE_VERSION}

deleteRelease

Expand All @@ -190,7 +203,7 @@ helm install ${HELM_REPO_NAME}/console --name ${NAME} --namespace ${NAMESPACE}
waitForHelmRelease

log "Upgrading using --reuse-values"
helm upgrade ${NAME} ${HELM_TMP}/console --recreate-pods --debug --reuse-values
helm upgrade ${NAME} ${HELM_TMP} --recreate-pods --debug --reuse-values

waitForHelmRelease
# Should have used same values as before
Expand Down
5 changes: 4 additions & 1 deletion deploy/ci/tasks/dev-releases/create-chart-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ patchHelmChart () {
sed -i -e 's/appVersion: 0.1.0/appVersion: '"${APP_VERSION}"'/g' ${CHART_PATH}/Chart.yaml

# Patch the console image tag in place - otherwise --reuse-values won't work with helm upgrade
sed -i -e 's/{{.Values.consoleVersion}}/'"${TAG}"'/g' ${CHART_PATH}/templates/deployment.yaml
# Make sure we patch this in all files in templates where it occurs
pushd ${CHART_PATH}/templates > dev/null
find . -type f -name '*.yaml' | xargs sed -i -e 's/{{.Values.consoleVersion}}/'"${TAG}"'/g'
popd > /dev/null
}

patchHelmChartDev () {
Expand Down
26 changes: 25 additions & 1 deletion deploy/kubernetes/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ DOCKER_REG_DEFAULTS="true"
CHART_ONLY="false"
ADD_GITHASH_TO_TAG="true"
HAS_CUSTOM_BUILD="false"
PACKAGE_CHART="false"

while getopts ":ho:r:t:Tclb:Opcn" opt; do
while getopts ":ho:r:t:Tclb:Opcnz" opt; do
case $opt in
h)
echo
Expand Down Expand Up @@ -73,6 +74,9 @@ while getopts ":ho:r:t:Tclb:Opcn" opt; do
n)
ADD_GITHASH_TO_TAG="false"
;;
z)
PACKAGE_CHART="true"
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
exit 1
Expand Down Expand Up @@ -247,6 +251,14 @@ sed -i.bak -e 's/hostname: docker.io/hostname: '"${DOCKER_REGISTRY}"'/g' values.

sed -i.bak -e 's/version: 0.1.0/version: '"${TAG}"'/g' Chart.yaml
sed -i.bak -e 's/appVersion: 0.1.0/appVersion: '"${TAG}"'/g' Chart.yaml

# Patch the console image tag in place - otherwise --reuse-values won't work with helm upgrade
# Make sure we patch all files that have this reference
cd templates
find . -type f -name '*.yaml' | xargs sed -i.bak -e 's/{{.Values.consoleVersion}}/'"${TAG}"'/g'
find . -type f -name "*.bak" -delete
cd ..

rm -rf *.bak

# Generate image list
Expand All @@ -255,6 +267,18 @@ ${STRATOS_PATH}/deploy/kubernetes/imagelist-gen.sh .

popd > /dev/null

if [ "${PACKAGE_CHART}" == "true" ]; then
echo "Packaging Helm Chart"
pushd ${STRATOS_PATH}/deploy/kubernetes > /dev/null
PKG_DIST_FOLDER="dist/${TAG}/console"
rm -rf ${PKG_DIST_FOLDER}
mkdir -p ${PKG_DIST_FOLDER}
cp -R ${DEST_HELM_CHART_PATH}/* ${PKG_DIST_FOLDER}
helm package ${PKG_DIST_FOLDER}
rm -rf ${PKG_DIST_FOLDER}
popd > /dev/null
fi

set +e

printf "${BOLD}${YELLOW}"
Expand Down
12 changes: 6 additions & 6 deletions deploy/kubernetes/console/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ metadata:
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
type: Opaque
data:
{{- if .Values.mariadb.rootPassword }}
rootPassword: {{ .Values.mariadb.rootPassword | b64enc | quote }}
{{- if or .Values.mariadb.rootPassword .Values.mariadb.mariadbRootPassword }}
rootPassword: {{ (default .Values.mariadb.rootPassword .Values.mariadb.mariadbRootPassword) | b64enc | quote }}
{{- else }}
rootPassword: {{ randAlphaNum 32 | b64enc | quote }}
{{- end }}
{{- if .Values.mariadb.userPassword }}
password: {{ .Values.mariadb.userPassword | b64enc | quote }}
{{- if or .Values.mariadb.userPassword .Values.mariadb.mariadbPassword }}
password: {{ (default .Values.mariadb.userPassword .Values.mariadb.mariadbPassword) | b64enc | quote }}
{{- else }}
password: {{ randAlphaNum 32 | b64enc | quote }}
{{- end }}
user: {{ .Values.mariadb.user | b64enc | quote }}
database: {{ .Values.mariadb.database | b64enc | quote }}
user: {{ default .Values.mariadb.user .Values.mariadb.mariadbUser | b64enc | quote }}
database: {{ default .Values.mariadb.database .Values.mariadb.mariadbDatabase | b64enc | quote }}
{{- if .Values.console.sessionStoreSecret }}
sessionStoreSecret: {{ .Values.console.sessionStoreSecret | b64enc | quote }}
{{- else }}
Expand Down

0 comments on commit 78ec1e2

Please sign in to comment.