-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Refactor Kubernetes Executor Types to NamedTuples #54858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Kubernetes Executor Types to NamedTuples #54858
Conversation
hterik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. 👍
LGTM
...cncf/kubernetes/src/airflow/providers/cncf/kubernetes/executors/kubernetes_executor_types.py
Outdated
Show resolved
Hide resolved
...iders/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py
Outdated
Show resolved
Hide resolved
7af7305 to
07e01a5
Compare
uranusjr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense
|
Need to fix CI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for the PR!
LGTM if CI run is successful.
Unfortunately, linting still needs to be fixed in this run. It can be automatically resolved by using prek (the alternative to pre-commit we recently switched to) with the following command.
prek ruff --all-files && prek run ruff-format --all-filesa81a4d7 to
27251fe
Compare
Replace complex tuple type aliases with NamedTuple classes for better readability and maintainability: - KubernetesResults: key, state, pod_name, namespace, resource_version, failure_details - KubernetesWatch: pod_name, namespace, state, annotations, resource_version, failure_details - KubernetesJob: key, command, kube_executor_config, pod_template_file
…adability Replace tuple type aliases with structured NamedTuple classes in Kubernetes executor to improve code maintainability and type safety.
…tesResults object - Simplify _change_state method signature from 5 parameters to 1 KubernetesResults object - Update method calls in sync() and _flush_result_queue() to pass KubernetesResults directly - Update all test cases to create KubernetesResults objects instead of passing individual parameters
…ject Update test_pod_failure_logging_with_container_terminated to create KubernetesResults object Update test_pod_failure_logging_exception_handling to use new _change_state signature Update test_pod_failure_logging_non_failed_state to use KubernetesResults object - Remove unused FailureDetails import - Format KubernetesResults constructor calls for better readability
27251fe to
bcb1a51
Compare
|
Finally pass the CI test! Thanks for all of review. |
e53394e to
bcb1a51
Compare
Description
When working on #54115, a good suggestion from @hterik that we should refactors the Kubernetes executor type to make for better readability.
This PR refactors the Kubernetes executor type system by converting simple tuple aliases to structured
NamedTupleclasses.Changes Made
Type System Improvements
KubernetesResultsType→KubernetesResults(NamedTuple)KubernetesWatchType→KubernetesWatch(NamedTuple)KubernetesJobType→KubernetesJob(NamedTuple)Code Updates
kubernetes_executor_types.py: Define new NamedTuple classes with proper typingkubernetes_executor_utils.py: Modify usage patterns to work with NamedTupleskubernetes_executor.py: Refactor result handling logic for new type structuretest_kubernetes_executor.py: Adjust test assertions to work with named fields^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.