-
Notifications
You must be signed in to change notification settings - Fork 16.4k
KubernetesPodOperator: add base_container_name to the templated fields #47864
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
Merged
jscheffl
merged 1 commit into
apache:main
from
brouberol:k8spodoperator-base-container-name-tpl
Mar 22, 2025
Merged
KubernetesPodOperator: add base_container_name to the templated fields #47864
jscheffl
merged 1 commit into
apache:main
from
brouberol:k8spodoperator-base-container-name-tpl
Mar 22, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a1202cd to
8d56835
Compare
I would like to propose adding `base_container_name` to the
`KubernetesPodOperator` templated fields.
The rationale is that the base container name is part of the log lines
emitted by the KubernetesPodManager, which is a good opportunity to have
it give as much context as possible.
For example, in a Wikimedia DAG, we defined the following operators:
```python
class WikimediaDumpOperator(KubernetesPodOperator):
"""
Base class for all types of wiki dumps run as Kubernetes Pods.
"""
dump_type = "generic"
def __init__(self, wiki: str, *args, **kwargs):
super().__init__(*args, **kwargs)
self.wiki = wiki
# Name of the "dumps" container (default is base, which isn't super telling)
self.base_container_name = f"mediawiki-{self.dump_type}-dump"
# name of the pod itself
# made templated in apache#46268
self.name = f"{self.base_container_name}-{wiki}"
class WikimediaSqlXmlDumpsOperator(WikimediaDumpOperator):
"""Operator class running the sql/xml wiki dumps as Kubernetes Pods"""
dump_type = "sql-xml"
class WikimediaWikidataDumpsOperator(WikimediaDumpOperator):
"""Operator class running the wikidata dumps as Kubernetes Pods"""
dump_type = "wikidata"
```
Adding `base_container_name` to the templated fields would allow us to
rewrite the `WikimediaDumpOperator` to the following:
```python
class WikimediaDumpOperator(KubernetesPodOperator):
"""
Base class for all types of wiki dumps run as Kubernetes Pods.
"""
dump_type = "generic"
def __init__(self, wiki: str, *args, **kwargs):
super().__init__(*args, **kwargs)
self.wiki = wiki
```
and we could invoke the operator as such:
```python
WikimediaSqlXmlOperator(
...,
base_container_name='mediawiki-{{ task.dump_type }}-dump',
name='{{ task.base_container_name }}-{{ task.wiki }}'
...
)
```
The endgame would be to have our logs contain as much context as
possible while avoiding mixing passing both keyword args to the
conttructor _and_ infering some attributes _within_ the `__init__`
method itself.
65b1e44 to
4238034
Compare
jscheffl
approved these changes
Mar 22, 2025
Contributor
jscheffl
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.
Sounds reasonable for me.
shubham-pyc
pushed a commit
to shubham-pyc/airflow
that referenced
this pull request
Apr 2, 2025
apache#47864) I would like to propose adding `base_container_name` to the `KubernetesPodOperator` templated fields. The rationale is that the base container name is part of the log lines emitted by the KubernetesPodManager, which is a good opportunity to have it give as much context as possible. For example, in a Wikimedia DAG, we defined the following operators: ```python class WikimediaDumpOperator(KubernetesPodOperator): """ Base class for all types of wiki dumps run as Kubernetes Pods. """ dump_type = "generic" def __init__(self, wiki: str, *args, **kwargs): super().__init__(*args, **kwargs) self.wiki = wiki # Name of the "dumps" container (default is base, which isn't super telling) self.base_container_name = f"mediawiki-{self.dump_type}-dump" # name of the pod itself # made templated in apache#46268 self.name = f"{self.base_container_name}-{wiki}" class WikimediaSqlXmlDumpsOperator(WikimediaDumpOperator): """Operator class running the sql/xml wiki dumps as Kubernetes Pods""" dump_type = "sql-xml" class WikimediaWikidataDumpsOperator(WikimediaDumpOperator): """Operator class running the wikidata dumps as Kubernetes Pods""" dump_type = "wikidata" ``` Adding `base_container_name` to the templated fields would allow us to rewrite the `WikimediaDumpOperator` to the following: ```python class WikimediaDumpOperator(KubernetesPodOperator): """ Base class for all types of wiki dumps run as Kubernetes Pods. """ dump_type = "generic" def __init__(self, wiki: str, *args, **kwargs): super().__init__(*args, **kwargs) self.wiki = wiki ``` and we could invoke the operator as such: ```python WikimediaSqlXmlOperator( ..., base_container_name='mediawiki-{{ task.dump_type }}-dump', name='{{ task.base_container_name }}-{{ task.wiki }}' ... ) ``` The endgame would be to have our logs contain as much context as possible while avoiding mixing passing both keyword args to the conttructor _and_ infering some attributes _within_ the `__init__` method itself.
nailo2c
pushed a commit
to nailo2c/airflow
that referenced
this pull request
Apr 4, 2025
apache#47864) I would like to propose adding `base_container_name` to the `KubernetesPodOperator` templated fields. The rationale is that the base container name is part of the log lines emitted by the KubernetesPodManager, which is a good opportunity to have it give as much context as possible. For example, in a Wikimedia DAG, we defined the following operators: ```python class WikimediaDumpOperator(KubernetesPodOperator): """ Base class for all types of wiki dumps run as Kubernetes Pods. """ dump_type = "generic" def __init__(self, wiki: str, *args, **kwargs): super().__init__(*args, **kwargs) self.wiki = wiki # Name of the "dumps" container (default is base, which isn't super telling) self.base_container_name = f"mediawiki-{self.dump_type}-dump" # name of the pod itself # made templated in apache#46268 self.name = f"{self.base_container_name}-{wiki}" class WikimediaSqlXmlDumpsOperator(WikimediaDumpOperator): """Operator class running the sql/xml wiki dumps as Kubernetes Pods""" dump_type = "sql-xml" class WikimediaWikidataDumpsOperator(WikimediaDumpOperator): """Operator class running the wikidata dumps as Kubernetes Pods""" dump_type = "wikidata" ``` Adding `base_container_name` to the templated fields would allow us to rewrite the `WikimediaDumpOperator` to the following: ```python class WikimediaDumpOperator(KubernetesPodOperator): """ Base class for all types of wiki dumps run as Kubernetes Pods. """ dump_type = "generic" def __init__(self, wiki: str, *args, **kwargs): super().__init__(*args, **kwargs) self.wiki = wiki ``` and we could invoke the operator as such: ```python WikimediaSqlXmlOperator( ..., base_container_name='mediawiki-{{ task.dump_type }}-dump', name='{{ task.base_container_name }}-{{ task.wiki }}' ... ) ``` The endgame would be to have our logs contain as much context as possible while avoiding mixing passing both keyword args to the conttructor _and_ infering some attributes _within_ the `__init__` method itself.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I would like to propose adding
base_container_nameto theKubernetesPodOperatortemplated fields.The rationale is that the base container name is part of the log lines emitted by the KubernetesPodManager, which is a good opportunity to have it give as much context as possible. It can also makes searching logs in observability tooling easier.
For example, in a Wikimedia DAG, we defined the following operators:
Adding
base_container_nameto the templated fields would allow us to rewrite theWikimediaDumpOperatorto the following:and we could invoke the operator as such:
The endgame would be to have our logs contain as much context as possible while avoiding mixing passing both keyword args to the conttructor and infering some attributes within the
__init__method itself.