summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-18 03:09:43 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-18 03:09:43 +0000
commitb4b9b3854eddd2a4829113ebfc1812c3a332a7d9 (patch)
tree6a21e491917e1606d81329af710459b0217eb1a4 /app/services
parent2e31c85a97183814ffa7ba5cc58f7bbad668fb2b (diff)
downloadgitlab-ce-b4b9b3854eddd2a4829113ebfc1812c3a332a7d9.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r--app/services/pod_logs/base_service.rb52
-rw-r--r--app/services/pod_logs/elasticsearch_service.rb5
-rw-r--r--app/services/pod_logs/kubernetes_service.rb48
3 files changed, 50 insertions, 55 deletions
diff --git a/app/services/pod_logs/base_service.rb b/app/services/pod_logs/base_service.rb
index d94d4e92eb6..8cc8fb913a2 100644
--- a/app/services/pod_logs/base_service.rb
+++ b/app/services/pod_logs/base_service.rb
@@ -55,22 +55,10 @@ module PodLogs
return error(_('Cluster does not exist')) if cluster.nil?
return error(_('Namespace is empty')) if namespace.blank?
- success(result)
- end
-
- def check_param_lengths(_result)
- pod_name = params['pod_name'].presence
- container_name = params['container_name'].presence
+ result[:pod_name] = params['pod_name'].presence
+ result[:container_name] = params['container_name'].presence
- if pod_name&.length.to_i > K8S_NAME_MAX_LENGTH
- return error(_('pod_name cannot be larger than %{max_length}'\
- ' chars' % { max_length: K8S_NAME_MAX_LENGTH }))
- elsif container_name&.length.to_i > K8S_NAME_MAX_LENGTH
- return error(_('container_name cannot be larger than'\
- ' %{max_length} chars' % { max_length: K8S_NAME_MAX_LENGTH }))
- end
-
- success(pod_name: pod_name, container_name: container_name)
+ success(result)
end
def get_raw_pods(result)
@@ -85,40 +73,6 @@ module PodLogs
success(result)
end
- def check_pod_name(result)
- # If pod_name is not received as parameter, get the pod logs of the first
- # pod of this namespace.
- result[:pod_name] ||= result[:pods].first
-
- unless result[:pod_name]
- return error(_('No pods available'))
- end
-
- unless result[:pods].include?(result[:pod_name])
- return error(_('Pod does not exist'))
- end
-
- success(result)
- end
-
- def check_container_name(result)
- pod_details = result[:raw_pods].first { |p| p.metadata.name == result[:pod_name] }
- containers = pod_details.spec.containers.map(&:name)
-
- # select first container if not specified
- result[:container_name] ||= containers.first
-
- unless result[:container_name]
- return error(_('No containers available'))
- end
-
- unless containers.include?(result[:container_name])
- return error(_('Container does not exist'))
- end
-
- success(result)
- end
-
def pod_logs(result)
raise NotImplementedError
end
diff --git a/app/services/pod_logs/elasticsearch_service.rb b/app/services/pod_logs/elasticsearch_service.rb
index 3bb6e2bd846..11862de4ade 100644
--- a/app/services/pod_logs/elasticsearch_service.rb
+++ b/app/services/pod_logs/elasticsearch_service.rb
@@ -3,11 +3,8 @@
module PodLogs
class ElasticsearchService < PodLogs::BaseService
steps :check_arguments,
- :check_param_lengths,
:get_raw_pods,
:get_pod_names,
- :check_pod_name,
- :check_container_name,
:check_times,
:check_search,
:check_cursor,
@@ -53,7 +50,7 @@ module PodLogs
response = ::Gitlab::Elasticsearch::Logs.new(client).pod_logs(
namespace,
- result[:pod_name],
+ pod_name: result[:pod_name],
container_name: result[:container_name],
search: result[:search],
start_time: result[:start],
diff --git a/app/services/pod_logs/kubernetes_service.rb b/app/services/pod_logs/kubernetes_service.rb
index 6c8ed74f8e1..92ebb84b877 100644
--- a/app/services/pod_logs/kubernetes_service.rb
+++ b/app/services/pod_logs/kubernetes_service.rb
@@ -8,7 +8,6 @@ module PodLogs
EncodingHelperError = Class.new(StandardError)
steps :check_arguments,
- :check_param_lengths,
:get_raw_pods,
:get_pod_names,
:check_pod_name,
@@ -22,6 +21,50 @@ module PodLogs
private
+ def check_pod_name(result)
+ # If pod_name is not received as parameter, get the pod logs of the first
+ # pod of this namespace.
+ result[:pod_name] ||= result[:pods].first
+
+ unless result[:pod_name]
+ return error(_('No pods available'))
+ end
+
+ unless result[:pod_name].length.to_i <= K8S_NAME_MAX_LENGTH
+ return error(_('pod_name cannot be larger than %{max_length}'\
+ ' chars' % { max_length: K8S_NAME_MAX_LENGTH }))
+ end
+
+ unless result[:pods].include?(result[:pod_name])
+ return error(_('Pod does not exist'))
+ end
+
+ success(result)
+ end
+
+ def check_container_name(result)
+ pod_details = result[:raw_pods].first { |p| p.metadata.name == result[:pod_name] }
+ containers = pod_details.spec.containers.map(&:name)
+
+ # select first container if not specified
+ result[:container_name] ||= containers.first
+
+ unless result[:container_name]
+ return error(_('No containers available'))
+ end
+
+ unless result[:container_name].length.to_i <= K8S_NAME_MAX_LENGTH
+ return error(_('container_name cannot be larger than'\
+ ' %{max_length} chars' % { max_length: K8S_NAME_MAX_LENGTH }))
+ end
+
+ unless containers.include?(result[:container_name])
+ return error(_('Container does not exist'))
+ end
+
+ success(result)
+ end
+
def pod_logs(result)
result[:logs] = cluster.kubeclient.get_pod_log(
result[:pod_name],
@@ -62,7 +105,8 @@ module PodLogs
values = line.split(' ', 2)
{
timestamp: values[0],
- message: values[1]
+ message: values[1],
+ pod: result[:pod_name]
}
end