From e951dd9cbbabe9dbe7f276e5387bd7319a1ef5cd Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Thu, 4 Oct 2018 22:23:59 +1300 Subject: Workaround helm hooks not streaming logs We use Helm hooks to run DB migration and initialization but because there is no feature to [stream hook logs](https://github.com/helm/helm/issues/2298), we use a function to show logs from the `helm upgrade...` command. `$CI_ENVIRONMENT_SLUG-db-initialize` and `$CI_ENVIRONMENT_SLUG-db-migrate` pod selectors come from the auto-deploy-app chart. --- changelogs/unreleased/52197-show-db-hook-logs.yml | 5 +++++ lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml | 24 ++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/52197-show-db-hook-logs.yml diff --git a/changelogs/unreleased/52197-show-db-hook-logs.yml b/changelogs/unreleased/52197-show-db-hook-logs.yml new file mode 100644 index 00000000000..a6fa7664623 --- /dev/null +++ b/changelogs/unreleased/52197-show-db-hook-logs.yml @@ -0,0 +1,5 @@ +--- +title: Show logs from Auto Devops DB initialize and migrate +merge_request: 22107 +author: +type: changed diff --git a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml index 72547c1b407..b4308a61763 100644 --- a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml @@ -625,7 +625,7 @@ rollout 100%: fi if [[ -n "$DB_INITIALIZE" && -z "$(helm ls -q "^$name$")" ]]; then - helm upgrade --install \ + initialize_logs helm upgrade --install \ --wait \ --set service.enabled="$service_enabled" \ --set releaseOverride="$CI_ENVIRONMENT_SLUG" \ @@ -647,7 +647,7 @@ rollout 100%: "$name" \ chart/ - helm upgrade --reuse-values \ + migrate_logs helm upgrade --reuse-values \ --wait \ --set application.initializeCommand="" \ --set application.migrateCommand="$DB_MIGRATE" \ @@ -655,7 +655,7 @@ rollout 100%: "$name" \ chart/ else - helm upgrade --install \ + migrate_logs helm upgrade --install \ --wait \ --set service.enabled="$service_enabled" \ --set releaseOverride="$CI_ENVIRONMENT_SLUG" \ @@ -681,6 +681,24 @@ rollout 100%: kubectl rollout status -n "$KUBE_NAMESPACE" -w "deployment/$name" } + function initialize_logs() { + if "$@"; then + if [[ -n "$DB_INITIALIZE" ]]; then kubectl logs -n "$KUBE_NAMESPACE" -l "job-name=$CI_ENVIRONMENT_SLUG-db-initialize"; fi + else + if [[ -n "$DB_INITIALIZE" ]]; then kubectl logs -n "$KUBE_NAMESPACE" -l "job-name=$CI_ENVIRONMENT_SLUG-db-initialize"; fi + exit 1 + fi + } + + function migrate_logs() { + if "$@"; then + if [[ -n "$DB_MIGRATE" ]]; then kubectl logs -n "$KUBE_NAMESPACE" -l "job-name=$CI_ENVIRONMENT_SLUG-db-migrate"; fi + else + if [[ -n "$DB_MIGRATE" ]]; then kubectl logs -n "$KUBE_NAMESPACE" -l "job-name=$CI_ENVIRONMENT_SLUG-db-migrate"; fi + exit 1 + fi + } + function scale() { track="${1-stable}" percentage="${2-100}" -- cgit v1.2.1