Class: Kubetailrb::Reader::K8sPodsReader
- Inherits:
-
Object
- Object
- Kubetailrb::Reader::K8sPodsReader
- Includes:
- Painter, WithK8sClient, Validated
- Defined in:
- lib/kubetailrb/reader/k8s_pods_reader.rb
Overview
Read multiple pod logs.
Instance Attribute Summary collapse
-
#container_query ⇒ Object
readonly
Returns the value of attribute container_query.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#pod_query ⇒ Object
readonly
Returns the value of attribute pod_query.
Instance Method Summary collapse
-
#initialize(pod_query:, container_query:, opts:, k8s_client: nil) ⇒ K8sPodsReader
constructor
A new instance of K8sPodsReader.
- #read ⇒ Object
Methods included from Painter
#blue, #cyan, #highlight_blue, #highlight_grey, #highlight_red, #highlight_yellow, #red
Methods included from WithK8sClient
#create_k8s_client, #k8s_client
Methods included from Validated
#raise_if_blank, #raise_if_nil, #validate_boolean, #validate_last_nb_lines
Constructor Details
#initialize(pod_query:, container_query:, opts:, k8s_client: nil) ⇒ K8sPodsReader
Returns a new instance of K8sPodsReader.
18 19 20 21 22 23 24 25 |
# File 'lib/kubetailrb/reader/k8s_pods_reader.rb', line 18 def initialize(pod_query:, container_query:, opts:, k8s_client: nil) validate(pod_query, container_query, opts) @k8s_client = k8s_client @pod_query = Regexp.new(pod_query) @container_query = Regexp.new(container_query) @opts = opts end |
Instance Attribute Details
#container_query ⇒ Object (readonly)
Returns the value of attribute container_query.
16 17 18 |
# File 'lib/kubetailrb/reader/k8s_pods_reader.rb', line 16 def container_query @container_query end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
16 17 18 |
# File 'lib/kubetailrb/reader/k8s_pods_reader.rb', line 16 def opts @opts end |
#pod_query ⇒ Object (readonly)
Returns the value of attribute pod_query.
16 17 18 |
# File 'lib/kubetailrb/reader/k8s_pods_reader.rb', line 16 def pod_query @pod_query end |
Instance Method Details
#read ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kubetailrb/reader/k8s_pods_reader.rb', line 27 def read pods = find_pods watch_for_new_pod_events if @opts.follow? threads = pods.flat_map do |pod| pod.spec.containers.select { |container| applicable_container?(container.name) }.map do |container| # NOTE: How much memory does a Ruby Thread takes? Can we spawn hundreds # to thoudsands of Threads without issue? start_reading_pod_logs(pod..name, container.name) end end # NOTE: '&:' is a shorthand way of calling 'join' method on each thread. # It's equivalent to: threads.each { |thread| thread.join } threads.each(&:join) end |