Commit 45ebdf82 authored by Mayra Cabrera's avatar Mayra Cabrera

Minor refactor to GCP service classes

- Split logger call for readibility
- Reduce code duplication by adding new method
parent 8d3e96ac
......@@ -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
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment