I am trying to send kubernetes pod logs using socketio
websocket to client, I can see the print(line_str)
but socket cannot connect and cannot recieve anything under log_line
event
@socketio.on('connect', namespace='/ws-connect')
def handle_connect():
# Access the query parameters using the `request` object
namespace = request.args.get('namespace')
pod = request.args.get('pod')
print('Following this pod -> ', namespace, pod)
# Get the Kubernetes client and stream the pod logs
v1 = client.CoreV1Api()
stream = v1.read_namespaced_pod_log(name=pod, namespace=namespace, follow=True, _preload_content=False, tail_lines=20)
# Send the log lines to the client
for line in stream:
# Decode the line from bytes to string
line_str = line.decode('utf-8').strip()
print(line_str)
# Send the line to the client
socketio.emit('log_line', {'line': line_str}, namespace='/ws-connect',broadcast=True)
request -> ws://localhost:5005/ws-connect?namespace=<ns>&pod=<pod_name>
Thread is not blocked I can still use flask for other endpoints, I just cannot connect through websocket. Any help is appreciated