I made custom K8s scheduler using python client. This is part of code that is watching for pods without assigned node.
def main():
w = watch.Watch()
for event in w.stream(v1.list_namespaced_pod, "default"):
if event['type'] == "ADDED" and event['object'].status.phase == "Pending" and event['object'].spec.scheduler_name == schedulerName:
try:
nodes=get_nodes()
print(nodes)
res = scheduler(event['object'].metadata.name, select_node(nodes))
print("Node %s is chosen for pod %s" % (select_node(nodes), event['object'].metadata.name))
except client.rest.ApiException as e:
print (e)
There are no other errors except after 50 seconds without any activities in events, script crashes with following errors
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py", line 697, in _update_chunk_length
self.chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: b''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py", line 438, in _error_catcher
yield
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py", line 764, in read_chunked
self._update_chunk_length()
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py", line 701, in _update_chunk_length
raise InvalidChunkLength(self, line)
urllib3.exceptions.InvalidChunkLength: InvalidChunkLength(got length b'', 0 bytes read)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "scheduler.py", line 77, in <module>
main()
File "scheduler.py", line 65, in main
for event in w.stream(v1.list_namespaced_pod, "default"):
File "/usr/local/lib/python3.7/dist-packages/kubernetes/watch/watch.py", line 117, in stream
for line in iter_resp_lines(resp):
File "/usr/local/lib/python3.7/dist-packages/kubernetes/watch/watch.py", line 45, in iter_resp_lines
for seg in resp.read_chunked(decode_content=False):
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py", line 793, in read_chunked
self._original_response.close()
File "/usr/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.7/dist-packages/urllib3/response.py", line 455, in _error_catcher
raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))
I'm using Kubernetes v1.20 with multiple masters and HAProxy in front of them. Python module for K8s that I'm using is 2.0.0.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…