summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Griffith <dyl.griffith@gmail.com>2018-11-08 17:36:21 +0000
committerDylan Griffith <dyl.griffith@gmail.com>2018-11-09 10:08:20 +0000
commitf852b23537d34c1e6a6106413fba17dae2d75784 (patch)
tree007945438d0a9b9beb53b6f7a10cb4e0f89aaf41
parentb991661080ced37f895542e721198dba7940c1fb (diff)
downloadgitlab-ce-f852b23537d34c1e6a6106413fba17dae2d75784.tar.gz
Fix error handling in cluster_platform_configure_worker
I have also extracted an issue in https://gitlab.com/gitlab-org/gitlab-ce/issues/53738 to surface these errors to users but now I am just fixing the bug where kubernetes_namespace is undefined while handling this error
-rw-r--r--app/workers/cluster_platform_configure_worker.rb2
-rw-r--r--spec/workers/cluster_platform_configure_worker_spec.rb14
2 files changed, 15 insertions, 1 deletions
diff --git a/app/workers/cluster_platform_configure_worker.rb b/app/workers/cluster_platform_configure_worker.rb
index 68e8335a09d..8f3689f0166 100644
--- a/app/workers/cluster_platform_configure_worker.rb
+++ b/app/workers/cluster_platform_configure_worker.rb
@@ -17,6 +17,6 @@ class ClusterPlatformConfigureWorker
end
rescue ::Kubeclient::HttpError => err
- Rails.logger.error "Failed to create/update Kubernetes Namespace. id: #{kubernetes_namespace.id} message: #{err.message}"
+ Rails.logger.error "Failed to create/update Kubernetes namespace for cluster_id: #{cluster_id} with error: #{err.message}"
end
end
diff --git a/spec/workers/cluster_platform_configure_worker_spec.rb b/spec/workers/cluster_platform_configure_worker_spec.rb
index 1a7ad8923f6..b51f6e07c6a 100644
--- a/spec/workers/cluster_platform_configure_worker_spec.rb
+++ b/spec/workers/cluster_platform_configure_worker_spec.rb
@@ -30,4 +30,18 @@ describe ClusterPlatformConfigureWorker, '#execute' do
described_class.new.perform(123)
end
end
+
+ context 'when kubeclient raises error' do
+ let(:cluster) { create(:cluster, :project) }
+
+ it 'rescues and logs the error' do
+ allow_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute).and_raise(::Kubeclient::HttpError.new(500, 'something baaaad happened', ''))
+
+ expect(Rails.logger)
+ .to receive(:error)
+ .with("Failed to create/update Kubernetes namespace for cluster_id: #{cluster.id} with error: something baaaad happened")
+
+ described_class.new.perform(cluster.id)
+ end
+ end
end