From 56ee90b53cf706b19105aa3fd48b845e4d473a70 Mon Sep 17 00:00:00 2001 From: Matt Royal Date: Tue, 24 Nov 2020 10:38:28 -0800 Subject: [PATCH] Terminate istio sidecar after migrations if it exists Without this change the job never completes because the istio-proxy runs forever. We make a request to the Istio sidecar admin port (15000) to terminate it. If we receive a non-200 response or an exception occurs, we print details and exit 0. [#175367511] Co-authored-by: Matt Royal Co-authored-by: Travis Patterson --- Procfile | 2 +- lib/tasks/db.rake | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Procfile b/Procfile index bd657cc69ff..746b87ac849 100644 --- a/Procfile +++ b/Procfile @@ -3,5 +3,5 @@ local-worker: bundle exec rake jobs:local api-worker: bundle exec rake jobs:generic clock: bundle exec rake clock:start deployment-updater: bundle exec rake deployment_updater:start -migrate: /bin/bash -c 'bundle exec rake db:connect && bundle exec rake db:setup_database' +migrate: /bin/bash -c 'bundle exec rake db:connect && bundle exec rake db:setup_database && bundle exec rake db:terminate_istio_if_exists' diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 8cee4c1b9c4..7dffee99402 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -165,6 +165,13 @@ namespace :db do end end + desc 'Terminate Istio sidecar for migration job (if one exists)' + task :terminate_istio_if_exists do + puts 'Terminating Istio sidecar' + + terminate_istio_sidecar_if_exists + end + desc 'Validate Deployments are not missing encryption keys' task :validate_encryption_keys do RakeConfig.context = :api @@ -302,4 +309,18 @@ namespace :db do end end end + + def terminate_istio_sidecar_if_exists + client = HTTPClient.new + response = client.request(:post, 'http://localhost:15000/quitquitquit') + + unless response.code == 200 + puts "Failed to terminate Istio sidecar. Received response code: #{response.code}" + return + end + + puts 'Istio sidecar is now terminated' + rescue => e + puts "Request to Istio sidecar failed. This is expected if your kubernetes cluster does not use Istio. Error: #{e}" + end end