Module: KubernetesMetadata::WatchNamespaces

Includes:
Common
Included in:
Fluent::Plugin::KubernetesMetadataFilter
Defined in:
lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb

Instance Method Summary collapse

Methods included from Common

#match_annotations, #parse_namespace_metadata, #parse_pod_metadata, #syms_to_strs

Instance Method Details

#start_namespace_watchObject



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
# File 'lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb', line 26

def start_namespace_watch
  begin
    resource_version = @client.get_namespaces.resourceVersion
    watcher          = @client.watch_namespaces(resource_version)
  rescue Exception=>e
    message = "start_namespace_watch: Exception encountered setting up namespace watch from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}: #{e.message}"
    message += " (#{e.response})" if e.respond_to?(:response)
    log.debug(message)
    raise Fluent::ConfigError, message
  end
  watcher.each do |notice|
    case notice.type
      when 'MODIFIED'
        cache_key = notice.object['metadata']['uid']
        cached    = @namespace_cache[cache_key]
        if cached
          @namespace_cache[cache_key] = (notice.object)
          @stats.bump(:namespace_cache_watch_updates)
        else
          @stats.bump(:namespace_cache_watch_misses)
        end
      when 'DELETED'
        # ignore and let age out for cases where 
        # deleted but still processing logs
        @stats.bump(:namespace_cache_watch_deletes_ignored)
      else
        # Don't pay attention to creations, since the created namespace may not
        # be used by any pod on this node.
        @stats.bump(:namespace_cache_watch_ignored)
    end
  end
end