blob: 821f91271e3a1623411114d0669347d1d73d1f9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
|
# Copyright (c) Authors of Clover
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
from kubernetes import client, config
from kubernetes.stream import stream
import sh
import re
FLUENTD_NAMESPACE = 'logging'
FLUENTD_PATTERN = 'fluentd-.*'
FLUENTD_LABELS = 'app=fluentd-es'
FLUENTD_INPUT = """<source>
type forward
</source>"""
def main():
# Load config from default location.
config.load_kube_config()
v1 = client.CoreV1Api()
fluentd_pod_name = None
# find by name
print("Find fluentd pod by name '{}'".format(FLUENTD_PATTERN))
fluentd_regex = re.compile(FLUENTD_PATTERN)
resp = v1.list_namespaced_pod(FLUENTD_NAMESPACE)
for i in resp.items:
if fluentd_regex.search(i.metadata.name) is not None:
print(i.metadata.name)
# find by label selector
print("Find fluentd pod by label selector '{}'".format(FLUENTD_LABELS))
resp = v1.list_namespaced_pod(FLUENTD_NAMESPACE, label_selector=FLUENTD_LABELS)
for i in resp.items:
print(i.metadata.name)
fluentd_pod_name = i.metadata.name
# check fluentd configuration
# NOTE: exec in Python librarry does not work well, use shell command as a workaround
# See https://github.com/kubernetes-client/python/issues/485
result = sh.kubectl((
'exec -n logging ' +
fluentd_pod_name +
' cat /etc/fluent/config.d/forward.input.conf').split())
if FLUENTD_INPUT in result:
print("fluentd input configured correctly")
else:
print("fluentd input not configured\n{}".format(FLUENTD_INPUT))
if __name__ == '__main__':
main()
|