This is an automated email from the ASF dual-hosted git repository.

dimberman pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v1-10-test by this push:
     new 333278b  Fix Kubernetes Executor logs for long dag names (#10942)
333278b is described below

commit 333278b600b2cf7b7f5cf5e668243c1da102c344
Author: Jonathan Stacks <[email protected]>
AuthorDate: Tue Sep 15 10:51:35 2020 -0500

    Fix Kubernetes Executor logs for long dag names (#10942)
    
    See #10292
    
    (cherry picked from commit e4e316ab9ef77d7a84f213db5de841c2a27eae17)
---
 airflow/utils/log/file_task_handler.py | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/airflow/utils/log/file_task_handler.py 
b/airflow/utils/log/file_task_handler.py
index d424ac2..16849d1 100644
--- a/airflow/utils/log/file_task_handler.py
+++ b/airflow/utils/log/file_task_handler.py
@@ -108,14 +108,26 @@ class FileTaskHandler(logging.Handler):
             except Exception as e:
                 log = "*** Failed to load local log file: 
{}\n".format(location)
                 log += "*** {}\n".format(str(e))
-        elif conf.get('core', 'executor') == 'KubernetesExecutor':
-            log += '*** Trying to get logs (last 100 lines) from worker pod {} 
***\n\n'\
-                .format(ti.hostname)
-
+        elif conf.get('core', 'executor') == 'KubernetesExecutor':   # pylint: 
disable=too-many-nested-blocks
             try:
                 from airflow.kubernetes.kube_client import get_kube_client
 
                 kube_client = get_kube_client()
+
+                if len(ti.hostname) >= 63:
+                    # Kubernetes takes the pod name and truncates it for the 
hostname. This trucated hostname
+                    # is returned for the fqdn to comply with the 63 character 
limit imposed by DNS standards
+                    # on any label of a FQDN.
+                    pod_list = 
kube_client.list_namespaced_pod(conf.get('kubernetes', 'namespace'))
+                    matches = [pod.metadata.name for pod in pod_list.items
+                               if pod.metadata.name.startswith(ti.hostname)]
+                    if len(matches) == 1:
+                        if len(matches[0]) > len(ti.hostname):
+                            ti.hostname = matches[0]
+
+                log += '*** Trying to get logs (last 100 lines) from worker 
pod {} ***\n\n'\
+                    .format(ti.hostname)
+
                 res = kube_client.read_namespaced_pod_log(
                     name=ti.hostname,
                     namespace=conf.get('kubernetes', 'namespace'),

Reply via email to