Commit 9498add5 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch...

Merge branch '36022-review-app-deployment-fails-with-error-upgrade-failed-has-no-deployed-releases' into 'master'

Add --tiller-namespace to helm commands in scripts

See merge request gitlab-org/gitlab!19858
parents d145a90a cab99a10
[[ "$TRACE" ]] && set -x [[ "$TRACE" ]] && set -x
export TILLER_NAMESPACE="$KUBE_NAMESPACE"
function deploy_exists() { function deploy_exists() {
local namespace="${1}" local namespace="${1}"
...@@ -14,16 +13,18 @@ function deploy_exists() { ...@@ -14,16 +13,18 @@ function deploy_exists() {
} }
function previous_deploy_failed() { function previous_deploy_failed() {
local deploy="${1}" local namespace="${1}"
local deploy="${2}"
echoinfo "Checking for previous deployment of ${deploy}" true echoinfo "Checking for previous deployment of ${deploy}" true
helm status "${deploy}" >/dev/null 2>&1 helm status --tiller-namespace "${namespace}" "${deploy}" >/dev/null 2>&1
local status=$? local status=$?
# if `status` is `0`, deployment exists, has a status # if `status` is `0`, deployment exists, has a status
if [ $status -eq 0 ]; then if [ $status -eq 0 ]; then
echoinfo "Previous deployment found, checking status..." echoinfo "Previous deployment found, checking status..."
deployment_status=$(helm status "${deploy}" | grep ^STATUS | cut -d' ' -f2) deployment_status=$(helm status --tiller-namespace "${namespace}" "${deploy}" | grep ^STATUS | cut -d' ' -f2)
echoinfo "Previous deployment state: ${deployment_status}" echoinfo "Previous deployment state: ${deployment_status}"
if [[ "$deployment_status" == "FAILED" || "$deployment_status" == "PENDING_UPGRADE" || "$deployment_status" == "PENDING_INSTALL" ]]; then if [[ "$deployment_status" == "FAILED" || "$deployment_status" == "PENDING_UPGRADE" || "$deployment_status" == "PENDING_INSTALL" ]]; then
status=0; status=0;
...@@ -37,16 +38,17 @@ function previous_deploy_failed() { ...@@ -37,16 +38,17 @@ function previous_deploy_failed() {
} }
function delete_release() { function delete_release() {
if [ -z "$CI_ENVIRONMENT_SLUG" ]; then local namespace="${KUBE_NAMESPACE}"
local deploy="${CI_ENVIRONMENT_SLUG}"
if [ -z "$deploy" ]; then
echoerr "No release given, aborting the delete!" echoerr "No release given, aborting the delete!"
return return
fi fi
local name="$CI_ENVIRONMENT_SLUG" echoinfo "Deleting release '$deploy'..." true
echoinfo "Deleting release '$name'..." true
helm delete --purge "$name" helm delete --purge --tiller-namespace "${namespace}" "${deploy}"
} }
function delete_failed_release() { function delete_failed_release() {
...@@ -59,7 +61,7 @@ function delete_failed_release() { ...@@ -59,7 +61,7 @@ function delete_failed_release() {
echoinfo "No Review App with ${CI_ENVIRONMENT_SLUG} is currently deployed." echoinfo "No Review App with ${CI_ENVIRONMENT_SLUG} is currently deployed."
else else
# Cleanup and previous installs, as FAILED and PENDING_UPGRADE will cause errors with `upgrade` # Cleanup and previous installs, as FAILED and PENDING_UPGRADE will cause errors with `upgrade`
if previous_deploy_failed "$CI_ENVIRONMENT_SLUG" ; then if previous_deploy_failed "${KUBE_NAMESPACE}" "$CI_ENVIRONMENT_SLUG" ; then
echoinfo "Review App deployment in bad state, cleaning up $CI_ENVIRONMENT_SLUG" echoinfo "Review App deployment in bad state, cleaning up $CI_ENVIRONMENT_SLUG"
delete_release delete_release
else else
...@@ -117,6 +119,7 @@ function ensure_namespace() { ...@@ -117,6 +119,7 @@ function ensure_namespace() {
} }
function install_tiller() { function install_tiller() {
local TILLER_NAMESPACE="$KUBE_NAMESPACE"
echoinfo "Checking deployment/tiller-deploy status in the ${TILLER_NAMESPACE} namespace..." true echoinfo "Checking deployment/tiller-deploy status in the ${TILLER_NAMESPACE} namespace..." true
echoinfo "Initiating the Helm client..." echoinfo "Initiating the Helm client..."
...@@ -131,11 +134,12 @@ function install_tiller() { ...@@ -131,11 +134,12 @@ function install_tiller() {
--override "spec.template.spec.tolerations[0].key"="dedicated" \ --override "spec.template.spec.tolerations[0].key"="dedicated" \
--override "spec.template.spec.tolerations[0].operator"="Equal" \ --override "spec.template.spec.tolerations[0].operator"="Equal" \
--override "spec.template.spec.tolerations[0].value"="helm" \ --override "spec.template.spec.tolerations[0].value"="helm" \
--override "spec.template.spec.tolerations[0].effect"="NoSchedule" --override "spec.template.spec.tolerations[0].effect"="NoSchedule" \
--tiller-namespace "${TILLER_NAMESPACE}"
kubectl rollout status -n "$TILLER_NAMESPACE" -w "deployment/tiller-deploy" kubectl rollout status -n "$TILLER_NAMESPACE" -w "deployment/tiller-deploy"
if ! helm version --debug; then if ! helm version --debug --tiller-namespace "${TILLER_NAMESPACE}"; then
echo "Failed to init Tiller." echo "Failed to init Tiller."
return 1 return 1
fi fi
...@@ -147,7 +151,7 @@ function install_external_dns() { ...@@ -147,7 +151,7 @@ function install_external_dns() {
domain=$(echo "${REVIEW_APPS_DOMAIN}" | awk -F. '{printf "%s.%s", $(NF-1), $NF}') domain=$(echo "${REVIEW_APPS_DOMAIN}" | awk -F. '{printf "%s.%s", $(NF-1), $NF}')
echoinfo "Installing external DNS for domain ${domain}..." true echoinfo "Installing external DNS for domain ${domain}..." true
if ! deploy_exists "${KUBE_NAMESPACE}" "${release_name}" || previous_deploy_failed "${release_name}" ; then if ! deploy_exists "${KUBE_NAMESPACE}" "${release_name}" || previous_deploy_failed "${KUBE_NAMESPACE}" "${release_name}" ; then
echoinfo "Installing external-dns Helm chart" echoinfo "Installing external-dns Helm chart"
helm repo update helm repo update
# Default requested: CPU => 0, memory => 0 # Default requested: CPU => 0, memory => 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment