summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMayra Cabrera <mcabrera@gitlab.com>2018-12-10 14:52:38 -0800
committerMayra Cabrera <mcabrera@gitlab.com>2018-12-10 15:11:01 -0800
commit45ebdf82154aa27c4004c65e782e35eccb60dc02 (patch)
treeeffd7f2358808b28dfced02ccce19871380f07f7
parent8d3e96acfb8d378bbc83be079ae2df159a080c63 (diff)
downloadgitlab-ce-45ebdf82154aa27c4004c65e782e35eccb60dc02.tar.gz
Minor refactor to GCP service classes
- Split logger call for readibility - Reduce code duplication by adding new method
-rw-r--r--app/services/clusters/gcp/fetch_operation_service.rb8
-rw-r--r--app/services/clusters/gcp/finalize_creation_service.rb23
2 files changed, 23 insertions, 8 deletions
diff --git a/app/services/clusters/gcp/fetch_operation_service.rb b/app/services/clusters/gcp/fetch_operation_service.rb
index 90afb1cee8e..6c648b443a0 100644
--- a/app/services/clusters/gcp/fetch_operation_service.rb
+++ b/app/services/clusters/gcp/fetch_operation_service.rb
@@ -11,7 +11,13 @@ module Clusters
yield(operation) if block_given?
rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e
- logger.error(exception: e.class.name, service: self.class.name, provider_id: provider.id, message: e.message)
+ logger.error(
+ exception: e.class.name,
+ service: self.class.name,
+ provider_id: provider.id,
+ message: e.message
+ )
+
provider.make_errored!("Failed to request to CloudPlatform; #{e.message}")
end
diff --git a/app/services/clusters/gcp/finalize_creation_service.rb b/app/services/clusters/gcp/finalize_creation_service.rb
index b94552c30fd..301059f0326 100644
--- a/app/services/clusters/gcp/finalize_creation_service.rb
+++ b/app/services/clusters/gcp/finalize_creation_service.rb
@@ -16,22 +16,18 @@ module Clusters
ClusterPlatformConfigureWorker.perform_async(cluster.id)
rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e
- logger.error(exception: e.class.name, service: self.class.name, provider_id: provider.id, message: e.message)
+ log_service_error(e.class.name, provider.id, e.message)
provider.make_errored!("Failed to request to CloudPlatform; #{e.message}")
rescue Kubeclient::HttpError => e
- logger.error(exception: e.class.name, service: self.class.name, provider_id: provider.id, message: e.message)
+ log_service_error(e.class.name, provider.id, e.message)
provider.make_errored!("Failed to run Kubeclient: #{e.message}")
rescue ActiveRecord::RecordInvalid => e
- logger.error(exception: e.class.name, service: self.class.name, provider_id: provider.id, message: e.message)
+ log_service_error(e.class.name, provider.id, e.message)
provider.make_errored!("Failed to configure Google Kubernetes Engine Cluster: #{e.message}")
end
private
- def logger
- @logger ||= Gitlab::Kubernetes::Logger.build
- end
-
def create_gitlab_service_account!
Clusters::Gcp::Kubernetes::CreateOrUpdateServiceAccountService.gitlab_creator(
kube_client,
@@ -112,6 +108,19 @@ module Clusters
def cluster
@cluster ||= provider.cluster
end
+
+ def logger
+ @logger ||= Gitlab::Kubernetes::Logger.build
+ end
+
+ def log_service_error(exception, provider_id, message)
+ logger.error(
+ exception: exception.class.name,
+ service: self.class.name,
+ provider_id: provider_id,
+ message: message
+ )
+ end
end
end
end