Module: KubernetesMetadata::Common

Included in:
Fluent::KubernetesMetadataFilter, WatchNamespaces, WatchPods
Defined in:
lib/fluent/plugin/kubernetes_metadata_common.rb

Instance Method Summary collapse

Instance Method Details

#match_annotations(annotations) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fluent/plugin/kubernetes_metadata_common.rb', line 22

def match_annotations(annotations)
  result = {}
  @annotations_regexps.each do |regexp|
    annotations.each do |key, value|
      if ::Fluent::StringUtil.match_regexp(regexp, key.to_s)
        result[key] = value
      end
    end
  end
  result
end

#parse_namespace_metadata(namespace_object) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fluent/plugin/kubernetes_metadata_common.rb', line 34

def (namespace_object)
  labels = syms_to_strs(namespace_object['metadata']['labels'].to_h)
  annotations = match_annotations(syms_to_strs(namespace_object['metadata']['annotations'].to_h))
  if @de_dot
    self.de_dot!(labels)
    self.de_dot!(annotations)
  end
   = {
    'namespace_id' => namespace_object['metadata']['uid'],
    'creation_timestamp' => namespace_object['metadata']['creationTimestamp']
  }
  ['namespace_labels'] = labels unless labels.empty?
  ['namespace_annotations'] = annotations unless annotations.empty?
  return 
end

#parse_pod_metadata(pod_object) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fluent/plugin/kubernetes_metadata_common.rb', line 50

def (pod_object)
  labels = syms_to_strs(pod_object['metadata']['labels'].to_h)
  annotations = match_annotations(syms_to_strs(pod_object['metadata']['annotations'].to_h))
  if @de_dot
    self.de_dot!(labels)
    self.de_dot!(annotations)
  end
   = {
      'namespace_name' => pod_object['metadata']['namespace'],
      'pod_id'         => pod_object['metadata']['uid'],
      'pod_name'       => pod_object['metadata']['name'],
      'labels'         => labels,
      'host'           => pod_object['spec']['nodeName'],
      'master_url'     => @kubernetes_url
  }
  ['annotations'] = annotations unless annotations.empty?
  return 
end

#syms_to_strs(hsh) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/fluent/plugin/kubernetes_metadata_common.rb', line 69

def syms_to_strs(hsh)
  newhsh = {}
  hsh.each_pair do |kk,vv|
    if vv.is_a?(Hash)
      vv = syms_to_strs(vv)
    end
    if kk.is_a?(Symbol)
      newhsh[kk.to_s] = vv
    else
      newhsh[kk] = vv
    end
  end
  newhsh
end