<p dir="auto"><strong>Apache Airflow version</strong>: 1.10.x, 2.0</p>
<p dir="auto"><strong>Kubernetes version (if you are using kubernetes)</strong> (use <code class="notranslate">kubectl version</code>): 1.18.8</p>
<p dir="auto"><strong>Environment</strong>: Azure - AKS - ContainerD CRI-O</p>
<ul dir="auto">
<li><strong>Cloud provider or hardware configuration</strong>: Azure AKS</li>
<li><strong>OS</strong> (e.g. from /etc/os-release): Ubuntu 18.04.5 LTS</li>
<li><strong>Kernel</strong> (e.g. <code class="notranslate">uname -a</code>): 5.4.0-1031-azure</li>
<li><strong>Install tools</strong>: Docker runtime  - 19.3.12</li>
<li><strong>Others</strong>: ContainerD CRI-O</li>
</ul>
<p dir="auto"><strong>What happened</strong>: Worker pod stuck in 'ContainerCreating' state - no error propagated to Airflow K8s executor for a DAG containing a longer workflow-name and task-name get specified.</p>

<p dir="auto"><strong>What you expected to happen</strong>: Worker-pod to success run OR task failure notification received due to K8s error</p>

<p dir="auto"><strong>How to reproduce it</strong>: Run any dag/task with longer names - combined number of alphanumeric characters in dag/task name should be more than 214</p>

<p dir="auto"><strong>Anything else we need to know</strong>: The error seems to occur due to pod sandbox creation failure. Each K8s pod gets a specific sandbox (directory). If the pod-id generated by Airflow Kubernetes executor is more than 214 characters, K8s also add suffix/prefix to generate a specific sandbox directory (prefix the K8s namespace and suffix a 36 character UUID using '_' as delimiter). This results in the sandbox directory name to cross '255' characters which is the maximum character (bytes) limit in most of the EXT FS based filesystem.</p>
<p dir="auto"><strong>Apache Airflow version</strong>: master</p>
<p dir="auto"><strong>Kubernetes version</strong>: v1.19.3</p>
<p dir="auto"><strong>Environment</strong>: Ubuntu 18.04 Server</p>
<p dir="auto">Using task IDs <strong>longer than 253 characters</strong> seems to cause problems in multiple areas. Considering we can now use <strong>nested task groups</strong> (which are basically prefixes for the task ID afaik) the final task ID can be pretty long.</p>
<ul dir="auto">
<li>
<p dir="auto"><code class="notranslate">pod_generator.py</code> does not use <code class="notranslate">make_safe_label_value</code> and writes the task ID directly as label. For k8s labels the limit is <strong>only 63 characters</strong>. This causes k8s not being able to schedule the task pod. </p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/apache/airflow/blob/4ad1accd3f6600ff398500e03c35eda8e3a6ec4a/airflow/kubernetes/pod_generator.py#L386">airflow/airflow/kubernetes/pod_generator.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 386
      in
      <a data-pjax="true" class="commit-tease-sha" href="/apache/airflow/commit/4ad1accd3f6600ff398500e03c35eda8e3a6ec4a">4ad1acc</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L386" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="386"></td>
          <td id="LC386" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-s">'task_id'</span>: <span class="pl-s1">task_id</span>, </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
</li>
<li>
<p dir="auto"><em>kubernetes_executor.py</em> uses <code class="notranslate">create_pod_id</code> to create a preliminary <em>pod_id</em> (not yet launched to k8s) and later uses <code class="notranslate">make_unique_pod_id</code> to trim the <em>pod_id</em> to 253 characters - though in my test I hit the max. filename length limit of Linux (<em>or rather ext4 filesystem</em>), which is 255 characters. So it seems some code is appending additional characters?<br>
</p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/apache/airflow/blob/4ad1accd3f6600ff398500e03c35eda8e3a6ec4a/airflow/executors/kubernetes_executor.py#L294">airflow/airflow/executors/kubernetes_executor.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 294
      in
      <a data-pjax="true" class="commit-tease-sha" href="/apache/airflow/commit/4ad1accd3f6600ff398500e03c35eda8e3a6ec4a">4ad1acc</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L294" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="294"></td>
          <td id="LC294" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-s1">pod_id</span><span class="pl-c1">=</span><span class="pl-en">create_pod_id</span>(<span class="pl-s1">dag_id</span>, <span class="pl-s1">task_id</span>), </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
</li>
</ul>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Events:
  Type     Reason                  Age               From               Message
  ----     ------                  ----              ----               -------
  Normal   Scheduled               3m3s              default-scheduler  Successfully assigned airflow/processairflowtesttgsurvey00000tgincrementaladjustmentsurvey00000f608c63d9btgmsac10survey000001c1a34cf10tgbundleadjuster786931747dtgcolor0521cd0b3f7tbundleadjusterfinalize5b57782bb2-aad4395c77ba400e9ee24c04d2cdbb72 to xxx.lan
  Warning  FailedCreatePodSandBox  7s (x14 over 3m)  kubelet            Failed to create pod sandbox: mkdir /var/log/pods/airflow_processairflowtesttgsurvey00000tgincrementaladjustmentsurvey00000f608c63d9btgmsac10survey000001c1a34cf10tgbundleadjuster786931747dtgcolor0521cd0b3f7tbundleadjusterfinalize5b57782bb2-aad4395c77ba400e9ee24c04d2cdbb72_8138b684-e7ce-41bc-8b31-4bbf9774e56a: file name too long"><pre class="notranslate">Events:
  Type     Reason                  Age               From               Message
  ----     ------                  ----              ----               -------
  Normal   Scheduled               3m3s              default-scheduler  Successfully assigned airflow/processairflowtesttgsurvey00000tgincrementaladjustmentsurvey00000f608c63d9btgmsac10survey000001c1a34cf10tgbundleadjuster786931747dtgcolor0521cd0b3f7tbundleadjusterfinalize5b57782bb2-aad4395c77ba400e9ee24c04d2cdbb72 to xxx.lan
  Warning  FailedCreatePodSandBox  7s (x14 over 3m)  kubelet            Failed to create pod sandbox: mkdir /var/log/pods/airflow_processairflowtesttgsurvey00000tgincrementaladjustmentsurvey00000f608c63d9btgmsac10survey000001c1a34cf10tgbundleadjuster786931747dtgcolor0521cd0b3f7tbundleadjusterfinalize5b57782bb2-aad4395c77ba400e9ee24c04d2cdbb72_8138b684-e7ce-41bc-8b31-4bbf9774e56a: file name too long</pre></div>
<ul dir="auto">
<li>As far as I understood <em>kubernetes_executor.py</em>  <code class="notranslate">adopt_launched_task</code> uses the pod labels to "reconstruct" the <em>pod_id</em> - considering  the pod was created by additionally applying <code class="notranslate">make_unique_pod_id</code> and the k8s label limit of 63 characters we will never reconstruct the original pod_id?<br>
<div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/apache/airflow/blob/4ad1accd3f6600ff398500e03c35eda8e3a6ec4a/airflow/executors/kubernetes_executor.py#L628">airflow/airflow/executors/kubernetes_executor.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 628
      in
      <a data-pjax="true" class="commit-tease-sha" href="/apache/airflow/commit/4ad1accd3f6600ff398500e03c35eda8e3a6ec4a">4ad1acc</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L628" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="628"></td>
          <td id="LC628" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-s1">dag_id</span> <span class="pl-c1">=</span> <span class="pl-s1">pod</span>.<span class="pl-s1">metadata</span>.<span class="pl-s1">labels</span>[<span class="pl-s">'dag_id'</span>] </td>
        </tr>
    </tbody></table>
  </div>
</div>
</li>
</ul>