diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-11-20 14:49:28 +1300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-11-27 10:42:34 +1300 |
commit | f99b699af1d5b5b462d432838483eff0fa7f941e (patch) | |
tree | ef91dc508eaf48211a24a4992c85cd7df929906a | |
parent | 874a80c8d437c85b84d389a1f89391fd75f4d105 (diff) | |
download | gitlab-ce-f99b699af1d5b5b462d432838483eff0fa7f941e.tar.gz |
Push error handling into the service
Otherwise we will have to handle the same Kubeclient::HttpError
everytime we invoke this service.
4 files changed, 23 insertions, 17 deletions
diff --git a/app/services/clusters/gcp/kubernetes/create_or_update_namespace_service.rb b/app/services/clusters/gcp/kubernetes/create_or_update_namespace_service.rb index b31426556f6..b21d9baf3a9 100644 --- a/app/services/clusters/gcp/kubernetes/create_or_update_namespace_service.rb +++ b/app/services/clusters/gcp/kubernetes/create_or_update_namespace_service.rb @@ -16,6 +16,10 @@ module Clusters configure_kubernetes_token kubernetes_namespace.save! + rescue ::Kubeclient::HttpError => err + Rails.logger.error "Failed to create/update Kubernetes namespace for cluster_id: #{cluster.id} with error: #{err.message}" + + # no-op end private diff --git a/app/workers/cluster_platform_configure_worker.rb b/app/workers/cluster_platform_configure_worker.rb index 24755ef1b1c..1cb48170989 100644 --- a/app/workers/cluster_platform_configure_worker.rb +++ b/app/workers/cluster_platform_configure_worker.rb @@ -12,9 +12,6 @@ class ClusterPlatformConfigureWorker configure_for_group_projects(cluster, cluster.group) end end - - rescue ::Kubeclient::HttpError => err - Rails.logger.error "Failed to create/update Kubernetes namespace for cluster_id: #{cluster_id} with error: #{err.message}" end private diff --git a/spec/services/clusters/gcp/kubernetes/create_or_update_namespace_service_spec.rb b/spec/services/clusters/gcp/kubernetes/create_or_update_namespace_service_spec.rb index 9220d154a98..1046dc7a25e 100644 --- a/spec/services/clusters/gcp/kubernetes/create_or_update_namespace_service_spec.rb +++ b/spec/services/clusters/gcp/kubernetes/create_or_update_namespace_service_spec.rb @@ -127,4 +127,23 @@ describe Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService, '#execute' d end end end + + context 'when kubeclient raises error' do + let(:kubernetes_namespace) do + create(:cluster_kubernetes_namespace, + cluster: cluster, + project: cluster_project.project, + cluster_project: cluster_project) + end + + it 'rescues and logs the error' do + allow_any_instance_of(Clusters::Gcp::Kubernetes::CreateServiceAccountService).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") + + subject + end + end end diff --git a/spec/workers/cluster_platform_configure_worker_spec.rb b/spec/workers/cluster_platform_configure_worker_spec.rb index 6e0c196c66e..0eead0ab13d 100644 --- a/spec/workers/cluster_platform_configure_worker_spec.rb +++ b/spec/workers/cluster_platform_configure_worker_spec.rb @@ -66,18 +66,4 @@ describe ClusterPlatformConfigureWorker, '#perform' 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 |