Module: KubernetesMetadata::WatchPods
- Includes:
- Common
- Included in:
- Fluent::Plugin::KubernetesMetadataFilter
- Defined in:
- lib/fluent/plugin/kubernetes_metadata_watch_pods.rb
Instance Method Summary collapse
Methods included from Common
#match_annotations, #parse_namespace_metadata, #parse_pod_metadata, #syms_to_strs
Instance Method Details
#start_pod_watch ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fluent/plugin/kubernetes_metadata_watch_pods.rb', line 26 def start_pod_watch begin resource_version = @client.get_pods.resourceVersion watcher = @client.watch_pods(resource_version) rescue Exception => e = "Exception encountered fetching metadata from Kubernetes API endpoint: #{e.}" += " (#{e.response})" if e.respond_to?(:response) raise Fluent::ConfigError, end watcher.each do |notice| case notice.type when 'MODIFIED' cache_key = notice.object['metadata']['uid'] cached = @cache[cache_key] if cached @cache[cache_key] = (notice.object) @stats.bump(:pod_cache_watch_updates) elsif ENV['K8S_NODE_NAME'] == notice.object['spec']['nodeName'] then @cache[cache_key] = (notice.object) @stats.bump(:pod_cache_host_updates) else @stats.bump(:pod_cache_watch_misses) end when 'DELETED' # ignore and let age out for cases where pods # deleted but still processing logs @stats.bump(:pod_cache_watch_delete_ignored) else # Don't pay attention to creations, since the created pod may not # end up on this node. @stats.bump(:pod_cache_watch_ignored) end end end |