52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/fluent/plugin/kubernetes_metadata_common.rb', line 52
def parse_pod_metadata(pod_object)
labels = String.new
labels = syms_to_strs(pod_object['metadata']['labels'].to_h) unless @skip_labels
annotations = match_annotations(syms_to_strs(pod_object['metadata']['annotations'].to_h))
if @de_dot
self.de_dot!(labels) unless @skip_labels
self.de_dot!(annotations)
end
container_meta = {}
begin
pod_object['status']['containerStatuses'].each do|container_status|
container_id = container_status['containerID'].sub /^[-_a-zA-Z0-9]+:\/\//, ''
unless @skip_container_metadata
container_meta[container_id] = {
'name' => container_status['name'],
'image' => container_status['image'],
'image_id' => container_status['imageID']
}
else
container_meta[container_id] = {
'name' => container_status['name']
}
end
end
rescue
log.debug("parsing container meta information failed for: #{pod_object['metadata']['namespace']}/#{pod_object['metadata']['name']} ")
end
kubernetes_metadata = {
'namespace_name' => pod_object['metadata']['namespace'],
'pod_id' => pod_object['metadata']['uid'],
'pod_name' => pod_object['metadata']['name'],
'containers' => syms_to_strs(container_meta),
'host' => pod_object['spec']['nodeName']
}
kubernetes_metadata['annotations'] = annotations unless annotations.empty?
kubernetes_metadata['labels'] = labels unless labels.empty?
kubernetes_metadata['master_url'] = @kubernetes_url unless @skip_master_url
log.debug("parsing container ownerReferences metadata: #{pod_object['metadata']['ownerReferences']}")
owner_kind = String.new
owner_name = String.new
begin
pod_object['metadata']['ownerReferences'].each do|owner_reference|
owner_kind = owner_reference['kind']
if owner_kind == "ReplicaSet"
name_length = owner_reference['name'].length - 11
owner_name = owner_reference['name'][0, name_length]
else
owner_name = owner_reference['name']
end
end
rescue
log.debug("failed parsing container ownerReferences metadata: #{pod_object['metadata']['ownerReferences']}")
end
kubernetes_metadata['owner_kind'] = owner_kind
kubernetes_metadata['owner_name'] = owner_name
kubernetes_metadata['ksc_owner_filter'] = "#{kubernetes_metadata['namespace_name']}_#{owner_name}_#{owner_kind}"
return kubernetes_metadata
end
|