You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "paolo-moriello (via GitHub)" <gi...@apache.org> on 2024/05/23 15:56:07 UTC

[PR] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

paolo-moriello opened a new pull request, #39789:
URL: https://github.com/apache/airflow/pull/39789

   <!--
    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/
   -->
   
   This is a follow-up on this pr: https://github.com/apache/airflow/pull/39325.
   
   The above PR addressed [an issue](https://github.com/apache/airflow/issues/32718) for which `KubernetesPodOperator` properties were refreshed on auth-token expiration.
   
   This PR covers also the `get_logs=True` case, which was not covered by the previous change.
   
   <!-- 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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

Posted by "paolo-moriello (via GitHub)" <gi...@apache.org>.
paolo-moriello commented on code in PR #39789:
URL: https://github.com/apache/airflow/pull/39789#discussion_r1612847856


##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -611,16 +611,7 @@ def execute_sync(self, context: Context):
                     mode=ExecutionMode.SYNC,
                 )
 
-            if self.get_logs:
-                self.pod_manager.fetch_requested_container_logs(
-                    pod=self.pod,
-                    containers=self.container_logs,
-                    follow_logs=True,
-                )
-            if not self.get_logs or (
-                self.container_logs is not True and self.base_container_name not in self.container_logs
-            ):
-                self.await_container_completion(pod=self.pod, container_name=self.base_container_name)
+            self.await_container_completion(pod=self.pod)

Review Comment:
   > We were calling a function based on flag, avoid a call if not set.
   
   @amoghrajesh The `await_container_completion` was a one-liner, that I created in my previous PR. I've now just moved this entire if-else logic inside the function itself. I feel this also makes the whole "await completion" logic a bit more readable, since it is all in single place. To avoid changing the signature we'd have to instead duplicate the tenacy-retry logic. Since this function is used only in this place, it is safe to make the change. wdyt? I'm of course also happy to create a separate function if you disagree :)



-- 
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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

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


##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -611,16 +611,7 @@ def execute_sync(self, context: Context):
                     mode=ExecutionMode.SYNC,
                 )
 
-            if self.get_logs:
-                self.pod_manager.fetch_requested_container_logs(
-                    pod=self.pod,
-                    containers=self.container_logs,
-                    follow_logs=True,
-                )
-            if not self.get_logs or (
-                self.container_logs is not True and self.base_container_name not in self.container_logs
-            ):
-                self.await_container_completion(pod=self.pod, container_name=self.base_container_name)
+            self.await_container_completion(pod=self.pod)

Review Comment:
   Lets not modify the signature here. We were calling a function based on flag, avoid a call if not set. 
   
   Now we enter irrespective of the flag here. Lets keep it as it was earlier.



-- 
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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

Posted by "paolo-moriello (via GitHub)" <gi...@apache.org>.
paolo-moriello commented on code in PR #39789:
URL: https://github.com/apache/airflow/pull/39789#discussion_r1612847856


##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -611,16 +611,7 @@ def execute_sync(self, context: Context):
                     mode=ExecutionMode.SYNC,
                 )
 
-            if self.get_logs:
-                self.pod_manager.fetch_requested_container_logs(
-                    pod=self.pod,
-                    containers=self.container_logs,
-                    follow_logs=True,
-                )
-            if not self.get_logs or (
-                self.container_logs is not True and self.base_container_name not in self.container_logs
-            ):
-                self.await_container_completion(pod=self.pod, container_name=self.base_container_name)
+            self.await_container_completion(pod=self.pod)

Review Comment:
   > We were calling a function based on flag, avoid a call if not set.
   
   @amoghrajesh The `await_container_completion` was a one-liner, that I created in my previous PR, and is currently used only in a single place.
   With this change I moved the entire if-else logic inside the function itself. I feel this also makes the whole "await completion" logic a bit more readable, since it happens all in single place instead of in two places as it was before. To avoid changing the signature we'd have to duplicate the tenacy-retry logic. wdyt? I'm of course also happy to create a separate function if you disagree :)



-- 
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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

Posted by "paolo-moriello (via GitHub)" <gi...@apache.org>.
paolo-moriello commented on code in PR #39789:
URL: https://github.com/apache/airflow/pull/39789#discussion_r1612847856


##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -611,16 +611,7 @@ def execute_sync(self, context: Context):
                     mode=ExecutionMode.SYNC,
                 )
 
-            if self.get_logs:
-                self.pod_manager.fetch_requested_container_logs(
-                    pod=self.pod,
-                    containers=self.container_logs,
-                    follow_logs=True,
-                )
-            if not self.get_logs or (
-                self.container_logs is not True and self.base_container_name not in self.container_logs
-            ):
-                self.await_container_completion(pod=self.pod, container_name=self.base_container_name)
+            self.await_container_completion(pod=self.pod)

Review Comment:
   > We were calling a function based on flag, avoid a call if not set.
   
   @amoghrajesh The `await_container_completion` was a one-liner, that I created in my previous PR. I've now just moved this entire if-else logic inside the function itself; to avoid changing the signature we'd have to instead duplicate the tenacy-retry logic. Since this function is used only in this place, it is safe to make the change. wdyt? I'm of course also happy to create a separate function if you disagree :)



-- 
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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

Posted by "paolo-moriello (via GitHub)" <gi...@apache.org>.
paolo-moriello commented on code in PR #39789:
URL: https://github.com/apache/airflow/pull/39789#discussion_r1612855202


##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -611,16 +611,7 @@ def execute_sync(self, context: Context):
                     mode=ExecutionMode.SYNC,
                 )
 
-            if self.get_logs:
-                self.pod_manager.fetch_requested_container_logs(
-                    pod=self.pod,
-                    containers=self.container_logs,
-                    follow_logs=True,
-                )
-            if not self.get_logs or (
-                self.container_logs is not True and self.base_container_name not in self.container_logs
-            ):
-                self.await_container_completion(pod=self.pod, container_name=self.base_container_name)
+            self.await_container_completion(pod=self.pod)

Review Comment:
   > is there any way to refresh the tokens automatically on the Kubernetes client side when they expire instead of we add explicit exception handling?
   
   @dirrao currently the token is already refreshed on the client, the problem here is that this class caches the whole client property



-- 
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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

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


##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -611,16 +611,7 @@ def execute_sync(self, context: Context):
                     mode=ExecutionMode.SYNC,
                 )
 
-            if self.get_logs:
-                self.pod_manager.fetch_requested_container_logs(
-                    pod=self.pod,
-                    containers=self.container_logs,
-                    follow_logs=True,
-                )
-            if not self.get_logs or (
-                self.container_logs is not True and self.base_container_name not in self.container_logs
-            ):
-                self.await_container_completion(pod=self.pod, container_name=self.base_container_name)
+            self.await_container_completion(pod=self.pod)

Review Comment:
   is there any way to refresh the tokens automatically on the Kubernetes client side when they expire instead of we add explicit exception handling? 



-- 
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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

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


-- 
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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

Posted by "paolo-moriello (via GitHub)" <gi...@apache.org>.
paolo-moriello commented on code in PR #39789:
URL: https://github.com/apache/airflow/pull/39789#discussion_r1613103878


##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -611,16 +611,7 @@ def execute_sync(self, context: Context):
                     mode=ExecutionMode.SYNC,
                 )
 
-            if self.get_logs:
-                self.pod_manager.fetch_requested_container_logs(
-                    pod=self.pod,
-                    containers=self.container_logs,
-                    follow_logs=True,
-                )
-            if not self.get_logs or (
-                self.container_logs is not True and self.base_container_name not in self.container_logs
-            ):
-                self.await_container_completion(pod=self.pod, container_name=self.base_container_name)
+            self.await_container_completion(pod=self.pod)

Review Comment:
   @amoghrajesh I've updated the function to make the separation more clear



##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -611,16 +611,7 @@ def execute_sync(self, context: Context):
                     mode=ExecutionMode.SYNC,
                 )
 
-            if self.get_logs:
-                self.pod_manager.fetch_requested_container_logs(
-                    pod=self.pod,
-                    containers=self.container_logs,
-                    follow_logs=True,
-                )
-            if not self.get_logs or (
-                self.container_logs is not True and self.base_container_name not in self.container_logs
-            ):
-                self.await_container_completion(pod=self.pod, container_name=self.base_container_name)
+            self.await_container_completion(pod=self.pod)

Review Comment:
   @amoghrajesh I've updated the function to make the distinction more clear



-- 
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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

Posted by "paolo-moriello (via GitHub)" <gi...@apache.org>.
paolo-moriello commented on code in PR #39789:
URL: https://github.com/apache/airflow/pull/39789#discussion_r1612847856


##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -611,16 +611,7 @@ def execute_sync(self, context: Context):
                     mode=ExecutionMode.SYNC,
                 )
 
-            if self.get_logs:
-                self.pod_manager.fetch_requested_container_logs(
-                    pod=self.pod,
-                    containers=self.container_logs,
-                    follow_logs=True,
-                )
-            if not self.get_logs or (
-                self.container_logs is not True and self.base_container_name not in self.container_logs
-            ):
-                self.await_container_completion(pod=self.pod, container_name=self.base_container_name)
+            self.await_container_completion(pod=self.pod)

Review Comment:
   > We were calling a function based on flag, avoid a call if not set.
   
   @amoghrajesh The `await_container_completion` was a one-liner, that I created in my previous PR, and is currently used only in a single place.
   With this change I moved the entire if-else logic inside the function itself. I feel this also makes the whole "await completion" logic a bit more readable, since it happens all in single place instead of in two places as it. wdyt?



-- 
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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

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

   hey, this is a bug in the `8.2.0` for the `get_logs=True` case, which is unexpected as it doesn't happen if logs is `False`. could we prioritize this so to fix this in the next release? 🙏 
   
   @amoghrajesh @romsharon98 


-- 
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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

Posted by "paolo-moriello (via GitHub)" <gi...@apache.org>.
paolo-moriello commented on code in PR #39789:
URL: https://github.com/apache/airflow/pull/39789#discussion_r1612847856


##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -611,16 +611,7 @@ def execute_sync(self, context: Context):
                     mode=ExecutionMode.SYNC,
                 )
 
-            if self.get_logs:
-                self.pod_manager.fetch_requested_container_logs(
-                    pod=self.pod,
-                    containers=self.container_logs,
-                    follow_logs=True,
-                )
-            if not self.get_logs or (
-                self.container_logs is not True and self.base_container_name not in self.container_logs
-            ):
-                self.await_container_completion(pod=self.pod, container_name=self.base_container_name)
+            self.await_container_completion(pod=self.pod)

Review Comment:
   > We were calling a function based on flag, avoid a call if not set.
   
   The `await_container_completion` was a one-liner, that I created in my previous PR. I've now just moved this entire if-else logic inside the function itself; to avoid changing the signature we'd have to instead duplicate the tenacy-retry logic. Since this function is used only in this place, it is safe to make the change. wdyt? I'm of course also happy to create a separate function if you disagree :)



-- 
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] Refresh properties on KubernetesPodOperator on token expiration also when logging [airflow]

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

   @amoghrajesh could you please have another look?


-- 
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