You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "nyirit (via GitHub)" <gi...@apache.org> on 2024/04/19 13:52:23 UTC

[PR] Fix/helm chart: workers.command for KubernetesExecutor [airflow]

nyirit opened a new pull request, #39132:
URL: https://github.com/apache/airflow/pull/39132

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   **Helm-chart version used:** 1.13.1 (latest)
   **Airflow version used:** 2.8.4
   
   The `workers.command` value override is ignored if `KubernetesExecutor` is used.
   
   I wanted to add a custom `command` parameter to the base container in the pods that are created to execute the tasks, but I failed to do so with the following values.yaml override:
   
   ```yaml
   airflow:
     executor: KubernetesExecutor
   
     workers:
       command: ['my-test-command']
   ```
   
   I have found that this value is only used in the `worker-deployment.yaml`, but not in the `pod-template-file.kubernetes-helm-yaml` which seems to be used for `KubernetesExecutor`.
   
   Based on the `workers.command` [documentation](https://airflow.apache.org/docs/helm-chart/stable/parameters-ref.html#workers) this does seem to be a bug.
   
   ### Potential workaround
   
   To make this work and prove that this is actually needed in my case, I have used the following override in the dag definition:
   
   ```python
   from datetime import datetime
   from airflow import DAG
   from kubernetes.client import models as k8s
   
   default_args = {
       'executor_config': {
           'pod_override': k8s.V1Pod(
               spec=k8s.V1PodSpec(
                   containers=[
                       k8s.V1Container(
                           name='base',
                           command=['my', 'command', 'to', 'run'],
                       )
                   ],
               )
           ),
       }
   }
   
   with DAG(dag_id='test', default_args=default_args, start_date=datetime(2024, 1, 1), schedule=None) as dag:
       ....
   ```
   
   This gets the job done, but it would be a lot nicer to be able to do this from the helm-chart, especially as this should be the default behaviour in my case for each dag.
   
   ---
   
   I have checked open issues, but did not find one that mentions this problem. Also, this is my first PR here, so even against my best intentions, I might have missed something in the contributing guidelines, so all feedback and help is welcome :)
   
   Branch is freshly rebased! :)
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/helm chart: workers.command for KubernetesExecutor [airflow]

Posted by "nyirit (via GitHub)" <gi...@apache.org>.
nyirit commented on code in PR #39132:
URL: https://github.com/apache/airflow/pull/39132#discussion_r1575951958


##########
helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -900,3 +900,31 @@ def test_airflow_kerberos_init_container(
         if expected_init_containers == 1:
             assert initContainers[0]["name"] == "kerberos-init"
             assert initContainers[0]["args"] == ["kerberos", "-o"]
+
+    @pytest.mark.parametrize(
+        "cmd, expected",
+        [
+            (["test", "command", "to", "run"], ["test", "command", "to", "run"]),
+            (["cmd", "{{ .Release.Name }}"], ["cmd", "release-name"]),
+        ],
+    )
+    def test_should_add_command(self, cmd, expected):
+        docs = render_chart(
+            values={
+                "workers": {"command": cmd},
+            },
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert expected == jmespath.search("spec.containers[0].command", docs[0])
+
+    @pytest.mark.parametrize("values", [{"workers": {"command": None}}, {"workers": {"command": []}}, None])
+    def test_should_not_add_command(self, values):
+        docs = render_chart(
+            values=values,
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert None is jmespath.search("spec.containers[0].command", docs[0])

Review Comment:
   Fixed! Initially I added that to the `test_should_not_add_command`, but in case the default value in `render_chart` changes, that can actually break. So I've separated it to another test and simplified the other testin [2d7b526](https://github.com/apache/airflow/pull/39132/commits/2d7b5265b9f88630f456a288c00cd01eeaa03957)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/helm chart: workers.command for KubernetesExecutor [airflow]

Posted by "jedcunningham (via GitHub)" <gi...@apache.org>.
jedcunningham commented on code in PR #39132:
URL: https://github.com/apache/airflow/pull/39132#discussion_r1575261805


##########
helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -900,3 +900,31 @@ def test_airflow_kerberos_init_container(
         if expected_init_containers == 1:
             assert initContainers[0]["name"] == "kerberos-init"
             assert initContainers[0]["args"] == ["kerberos", "-o"]
+
+    @pytest.mark.parametrize(
+        "cmd, expected",
+        [
+            (["test", "command", "to", "run"], ["test", "command", "to", "run"]),
+            (["cmd", "{{ .Release.Name }}"], ["cmd", "release-name"]),
+        ],
+    )
+    def test_should_add_command(self, cmd, expected):
+        docs = render_chart(
+            values={
+                "workers": {"command": cmd},
+            },
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert expected == jmespath.search("spec.containers[0].command", docs[0])
+
+    @pytest.mark.parametrize("values", [{"workers": {"command": None}}, {"workers": {"command": []}}, None])
+    def test_should_not_add_command(self, values):
+        docs = render_chart(
+            values=values,
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert None is jmespath.search("spec.containers[0].command", docs[0])

Review Comment:
   ```suggestion
           assert None is jmespath.search("spec.containers[0].command", docs[0])
           
       def test_should_not_add_command_by_default(self):
           docs = render_chart(
               show_only=["templates/pod-template-file.yaml"],
               chart_dir=self.temp_chart_dir,
           )
   
           assert None is jmespath.search("spec.containers[0].command", docs[0])
   ```
   
   Oops, lost this test!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/helm chart: workers.command for KubernetesExecutor [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #39132:
URL: https://github.com/apache/airflow/pull/39132#issuecomment-2073370960

   Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/helm chart: workers.command for KubernetesExecutor [airflow]

Posted by "jedcunningham (via GitHub)" <gi...@apache.org>.
jedcunningham commented on code in PR #39132:
URL: https://github.com/apache/airflow/pull/39132#discussion_r1575137554


##########
helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -900,3 +900,41 @@ def test_airflow_kerberos_init_container(
         if expected_init_containers == 1:
             assert initContainers[0]["name"] == "kerberos-init"
             assert initContainers[0]["args"] == ["kerberos", "-o"]
+
+    def test_should_add_command(self):
+        docs = render_chart(
+            values={
+                "workers": {"command": ["test", "command", "to", "run"]},
+            },
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert ["test", "command", "to", "run"] == jmespath.search("spec.containers[0].command", docs[0])
+
+    def test_should_not_add_command_by_default(self):
+        docs = render_chart(
+            values={},
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert None is jmespath.search("spec.containers[0].command", docs[0])
+
+    def test_should_not_add_command_if_value_none(self):

Review Comment:
   These other 3 tests can use [parametrization](https://docs.pytest.org/en/7.0.x/how-to/parametrize.html). Can you refactor them?



##########
helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -900,3 +900,41 @@ def test_airflow_kerberos_init_container(
         if expected_init_containers == 1:
             assert initContainers[0]["name"] == "kerberos-init"
             assert initContainers[0]["args"] == ["kerberos", "-o"]
+
+    def test_should_add_command(self):
+        docs = render_chart(
+            values={
+                "workers": {"command": ["test", "command", "to", "run"]},
+            },
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert ["test", "command", "to", "run"] == jmespath.search("spec.containers[0].command", docs[0])
+
+    def test_should_not_add_command_by_default(self):
+        docs = render_chart(
+            values={},

Review Comment:
   ```suggestion
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/helm chart: workers.command for KubernetesExecutor [airflow]

Posted by "nyirit (via GitHub)" <gi...@apache.org>.
nyirit commented on code in PR #39132:
URL: https://github.com/apache/airflow/pull/39132#discussion_r1575247591


##########
helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -900,3 +900,41 @@ def test_airflow_kerberos_init_container(
         if expected_init_containers == 1:
             assert initContainers[0]["name"] == "kerberos-init"
             assert initContainers[0]["args"] == ["kerberos", "-o"]
+
+    def test_should_add_command(self):
+        docs = render_chart(
+            values={
+                "workers": {"command": ["test", "command", "to", "run"]},
+            },
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert ["test", "command", "to", "run"] == jmespath.search("spec.containers[0].command", docs[0])
+
+    def test_should_not_add_command_by_default(self):
+        docs = render_chart(
+            values={},
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert None is jmespath.search("spec.containers[0].command", docs[0])
+
+    def test_should_not_add_command_if_value_none(self):

Review Comment:
   Makes sense. I've refactored it and also realised a templated command test case could also be added. I'm not sure if I should use parametrization for the templated version as well or if it's cleaner without it, but went ahead with that for now. Let me know what you think.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/helm chart: workers.command for KubernetesExecutor [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #39132:
URL: https://github.com/apache/airflow/pull/39132#issuecomment-2066637133

   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (ruff, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
   - Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/helm chart: workers.command for KubernetesExecutor [airflow]

Posted by "jedcunningham (via GitHub)" <gi...@apache.org>.
jedcunningham commented on code in PR #39132:
URL: https://github.com/apache/airflow/pull/39132#discussion_r1575262403


##########
helm_tests/airflow_aux/test_pod_template_file.py:
##########
@@ -900,3 +900,41 @@ def test_airflow_kerberos_init_container(
         if expected_init_containers == 1:
             assert initContainers[0]["name"] == "kerberos-init"
             assert initContainers[0]["args"] == ["kerberos", "-o"]
+
+    def test_should_add_command(self):
+        docs = render_chart(
+            values={
+                "workers": {"command": ["test", "command", "to", "run"]},
+            },
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert ["test", "command", "to", "run"] == jmespath.search("spec.containers[0].command", docs[0])
+
+    def test_should_not_add_command_by_default(self):
+        docs = render_chart(
+            values={},
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert None is jmespath.search("spec.containers[0].command", docs[0])
+
+    def test_should_not_add_command_if_value_none(self):

Review Comment:
   Good call, looks good, thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/helm chart: workers.command for KubernetesExecutor [airflow]

Posted by "jedcunningham (via GitHub)" <gi...@apache.org>.
jedcunningham merged PR #39132:
URL: https://github.com/apache/airflow/pull/39132


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/helm chart: workers.command for KubernetesExecutor [airflow]

Posted by "jedcunningham (via GitHub)" <gi...@apache.org>.
jedcunningham commented on PR #39132:
URL: https://github.com/apache/airflow/pull/39132#issuecomment-2073372073

   Thanks @nyirit! Congrats on your first commit 🎉 !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix/helm chart: workers.command for KubernetesExecutor [airflow]

Posted by "nyirit (via GitHub)" <gi...@apache.org>.
nyirit commented on PR #39132:
URL: https://github.com/apache/airflow/pull/39132#issuecomment-2073530510

   Awesome! Thank you @jedcunningham for the help with it! :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org