summaryrefslogtreecommitdiff
path: root/zuul/ansible/base/callback/zuul_stream.py
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2020-02-21 15:52:44 -0800
committerJames E. Blair <jeblair@redhat.com>2020-02-27 07:49:40 -0800
commitbbe2d364959316a24a205dec037c612368ff881f (patch)
treede7a7fb0bbf0dcdfd7a9946a43e233ac250d106b /zuul/ansible/base/callback/zuul_stream.py
parent32bfbae4656acb5917f0ee20dff3a5a5a088383d (diff)
downloadzuul-bbe2d364959316a24a205dec037c612368ff881f.tar.gz
Stream output from kubectl pods
When we get a pod from nodepool, this starts a kubectl port-forward on the pod so that zuul-console and the normal method of streaming command output will work. Change-Id: Iae85347c3d8e0a74e330a7b62b513c7b41641383 Story: 2007321 Task: 38832 Depends-On: https://review.opendev.org/709259
Diffstat (limited to 'zuul/ansible/base/callback/zuul_stream.py')
-rw-r--r--zuul/ansible/base/callback/zuul_stream.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/zuul/ansible/base/callback/zuul_stream.py b/zuul/ansible/base/callback/zuul_stream.py
index 5b2206e14..ca34dc2ab 100644
--- a/zuul/ansible/base/callback/zuul_stream.py
+++ b/zuul/ansible/base/callback/zuul_stream.py
@@ -129,12 +129,12 @@ class CallbackModule(default.CallbackModule):
else:
self._display.display(msg)
- def _read_log(self, host, ip, log_id, task_name, hosts):
+ def _read_log(self, host, ip, port, log_id, task_name, hosts):
self._log("[%s] Starting to log %s for task %s"
% (host, log_id, task_name), job=False, executor=True)
while True:
try:
- s = socket.create_connection((ip, LOG_STREAM_PORT), 5)
+ s = socket.create_connection((ip, port), 5)
# Disable the socket timeout after we have successfully
# connected to accomodate the fact that jobs may not be writing
# logs continously. Without this we can easily trip the 5
@@ -144,12 +144,12 @@ class CallbackModule(default.CallbackModule):
self._log(
"Timeout exception waiting for the logger. "
"Please check connectivity to [%s:%s]"
- % (ip, LOG_STREAM_PORT), executor=True)
+ % (ip, port), executor=True)
self._log_streamline(
"localhost",
"Timeout exception waiting for the logger. "
"Please check connectivity to [%s:%s]"
- % (ip, LOG_STREAM_PORT))
+ % (ip, port))
return
except Exception:
self._log("[%s] Waiting on logger" % host,
@@ -254,6 +254,7 @@ class CallbackModule(default.CallbackModule):
hosts = self._get_task_hosts(task)
for host, inventory_hostname in hosts:
+ port = LOG_STREAM_PORT
if host in ('localhost', '127.0.0.1'):
# Don't try to stream from localhost
continue
@@ -267,14 +268,21 @@ class CallbackModule(default.CallbackModule):
# Don't try to stream from loops
continue
if play_vars[host].get('ansible_connection') in ('kubectl', ):
- # Don't try to stream from kubectl connection
- continue
+ # Stream from the forwarded port on kubectl conns
+ port = play_vars[host]['zuul']['resources'][
+ inventory_hostname].get('stream_port')
+ if port is None:
+ self._log("[Zuul] Kubectl and socat must be installed "
+ "on the Zuul executor for streaming output "
+ "from pods")
+ continue
+ ip = '127.0.0.1'
log_id = "%s-%s" % (
task._uuid, paths._sanitize_filename(inventory_hostname))
streamer = threading.Thread(
target=self._read_log, args=(
- host, ip, log_id, task_name, hosts))
+ host, ip, port, log_id, task_name, hosts))
streamer.daemon = True
streamer.start()
self._streamers.append(streamer)