summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2018-10-04 22:23:59 +1300
committerThong Kuah <tkuah@gitlab.com>2018-10-09 15:35:51 +1300
commite951dd9cbbabe9dbe7f276e5387bd7319a1ef5cd (patch)
treea9fdb063e65112954b3d043814f02fb0423b8dbf
parentb86631a5213ca0c950d51aa5362c8d752296e8d7 (diff)
downloadgitlab-ce-52197-show-db-hook-logs.tar.gz
Workaround helm hooks not streaming logs52197-show-db-hook-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.
-rw-r--r--changelogs/unreleased/52197-show-db-hook-logs.yml5
-rw-r--r--lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml24
2 files changed, 26 insertions, 3 deletions
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}"