Skip to content

Commit 3fb2465

Browse files
fix: logic errors - k8s api returns strings
also only show health status when out of pending
1 parent 37fa23f commit 3fb2465

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

apiconnect_net.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,37 @@ def fish(self):
4949
customResource['plural'])
5050
for item in api_response['items']:
5151
version = item['status']['versions']['reconciled']
52+
pending_state = False
5253
for condition in item['status']['conditions']:
54+
if condition['type'] == 'Pending' and condition['status'] == "True":
55+
pending_state = True
56+
5357
if condition['type'] == 'Ready':
54-
if condition['status']:
58+
if condition['status'] == "True":
5559
health = 1
5660
else:
5761
health = 0
58-
self.trawler.set_gauge(
59-
self.health_prefix,
60-
"health_status",
61-
health,
62-
labels={
63-
"component": "{}_{}".format(customResource['plural'][:-1], item['metadata']['name']),
64-
"version": version,
65-
**self.health_label
66-
})
6762

6863
self.trawler.set_gauge(
6964
'apiconnect',
7065
"{}_status".format(customResource['plural']),
71-
1 if condition['status'] else 0,
66+
1 if condition['status'] == "True" else 0,
7267
labels={
7368
"type": condition['type'],
7469
"name": item['metadata']['name'],
7570
"namespace": item['metadata']['namespace'],
7671
})
72+
if not pending_state:
73+
self.trawler.set_gauge(
74+
self.health_prefix,
75+
"health_status",
76+
health,
77+
labels={
78+
"component": "{}_{}".format(customResource['plural'][:-1], item['metadata']['name']),
79+
"version": version,
80+
**self.health_label
81+
})
82+
7783

7884
# api_response['status']['conditions']
7985
# {'lastTransitionTime': '2021-09-30T13:33:10Z', 'message': '', 'reason': 'na', 'status': 'False', 'type': 'Warning'}

0 commit comments

Comments
 (0)