-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Change default executor in pod template to support executor parameter in task (re-uploaded) #49433
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
Change default executor in pod template to support executor parameter in task (re-uploaded) #49433
Conversation
ef2edfa to
f00caa2
Compare
|
@kaxil @jedcunningham -> this one should be included in the future chart with 3.0.0 support as well. |
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.
This is intentionally LocalExecutor, it is local to that pod -- it has been like that since forever (probably since KE became a thing)!
|
@potiuk 's comment on the issue is still accurate:
|
potiuk
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.
Yeah. That one needs to be looked at - the verifiication of the executor should be fixed in order to make things work - not the executor configured in POD
|
I'd push back on this, perhaps I need to hear more about how Helm is operating differently than a normal airflow deployment. But in normal cases Airlfow expects to operate with the same configuration on all hosts (until multi-team of course). If a pod is being started as a result of an executor triggering a pod to run a task, the core.executor field will not do anything. In AF2 the If the context is something else than the above, I'd need to hear more. |
f00caa2 to
904c245
Compare
|
@kaxil @potiuk I respect your opinions, but I believe this might add to the confusion for Helm chart users. According to what you’re saying, setting the Personally, as @o-nikolas mentioned, I believe that configuration values managed by Airflow should be applied consistently across all components. As noted in issue #48667 and confirmed through testing, even when a pod is launched using the KubernetesExecutor, the task still behaves as if it's executed with the LocalExecutor, regardless of what value is passed to To summarize: updating this PR to follow the global configuration instead of using a hardcoded value doesn't break actual task execution. It simply ensures that the validation logic behaves as expected. Even after this PR is merged, Helm chart users can still freely override If your intention is to prevent users from modifying this value at all, I can update the pod template to remove the environment variable entirely. (+ fixing validation part) |
|
If the value provided to it is meaningless in the pod, why set it at all? |
|
And if we are certainly sure to delete it or change it, we should do the same for the Lines 26 to 30 in e7d384d
Lines 27 to 30 in e7d384d
Lines 48 to 51 in e7d384d
-- We should also add some test |
|
I think the initial intention with this was just to run
which may have changed somewhere; I am still digging into the code and history. This change might break the Helm chart with KE on <Airflow 3. |
|
OK, I see what's going on. That From a test with the Helm Chart with KE and 2.10.5. But the UI shows
Tested it with
executor: KubernetesExecutor
env:
- name: AIRFLOW__CORE__LOAD_EXAMPLES
value: "True"
- name: AIRFLOW__CORE__EXECUTOR
value: "KubernetesExecutor"
podTemplate: |-
apiVersion: v1
kind: Pod
metadata:
name: placeholder-name
labels:
tier: airflow
component: worker
release: example-release
annotations:
cluster-autoscaler.kubernetes.io/safe-to-evict: "false"
spec:
initContainers:
containers:
- envFrom:
[]
env:
- name: AIRFLOW__CORE__FERNET_KEY
valueFrom:
secretKeyRef:
name: example-release-fernet-key
key: fernet-key
- name: AIRFLOW_HOME
value: /opt/airflow
# For Airflow <2.3, backward compatibility; moved to [database] in 2.3
- name: AIRFLOW__CORE__SQL_ALCHEMY_CONN
valueFrom:
secretKeyRef:
name: example-release-metadata
key: connection
- name: AIRFLOW__DATABASE__SQL_ALCHEMY_CONN
valueFrom:
secretKeyRef:
name: example-release-metadata
key: connection
- name: AIRFLOW_CONN_AIRFLOW_DB
valueFrom:
secretKeyRef:
name: example-release-metadata
key: connection
- name: AIRFLOW__WEBSERVER__SECRET_KEY
valueFrom:
secretKeyRef:
name: example-release-webserver-secret-key
key: webserver-secret-key
image: apache/airflow:2.10.5
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
name: base
volumeMounts:
- mountPath: "/opt/airflow/logs"
name: logs
- name: config
mountPath: "/opt/airflow/airflow.cfg"
subPath: airflow.cfg
readOnly: true
- name: config
mountPath: "/opt/airflow/config/airflow_local_settings.py"
subPath: airflow_local_settings.py
readOnly: true
restartPolicy: Never
securityContext:
runAsUser: 50000
fsGroup: 0
terminationGracePeriodSeconds: 600
serviceAccountName: "example-release-airflow-worker"
volumes:
- emptyDir:
{}
name: logs
- configMap:
name: example-release-config
name: configThat https://github.com/apache/airflow/blob/2.10.5/airflow/jobs/scheduler_job_runner.py#L685C13-L688 command = ti.command_as_list(
local=True,
pickle_id=ti.dag_model.pickle_id,
)airflow/airflow-core/src/airflow/executors/base_executor.py Lines 195 to 205 in 1b27c3b
and used by KE here which then generates pod spec here: Line 429 in 1b27c3b
But the UI code is generated directly using airflow/providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/template_rendering.py Line 52 in 1b27c3b
|
|
That said, the error reported in the GH issue around validation, does not need to happen when the task is already in the pod i.e. there is no needed to load or create a Executor: |
|
@kaxil Oh, thank you for thoroughly reviewing the history and carefully analyzing the original intention behind the code. Based on your insights, I believe the following changes would be appropriate—could you please confirm if this approach makes sense?
P.S. This is my first contribution to this project, so I hope you'll excuse my rough edges. Regarding the scope of testing—do you have any guidance on what would be expected? I think I can follow the guidelines for unit and K8s tests, but I'm a bit unfamiliar with how to write tests for the UI part. Would providing a screenshot to demonstrate that the mismatch issue has been resolved be acceptable? |
|
Yeah that sounds about right. The UI thing is no longer an issue in Airflow 3 as we don't use the
Yeah, feel free to create separate PRs for them. One for Helm Chart and one for K8s provider.
I am glad that you are contributing, definitely here to help wherever needed. Some test in Helm Chart gives a good idea: Example https://github.com/apache/airflow/blob/main/helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py
|
|
Sorry folks I've been out sick since Wednesday! Glad you did a deep dive @kaxil and you are now convinced 😀 I was absolutely certain it was not needed for Airflow Executor workflow, which I've worked quite a bit on!
I still think Airflow configuration should be as consistent as possible across all nodes/workers/pods executing it, personally. But happy to commit if I'm out voted on that.
To me the code is nice and simple as is, with no branching logic, and we also get one last check that we're not launching a task for which there is no executor configured to take it, which is a critical piece of multi exec config (so tasks don't get stranded in scheduled state). As long as the config is the same (as we expect) everything functions correctly. Which to me is the real fix, But again, happy to commit if I'm out voted on that one.
|
|
I am fine with that, no strong opinion :)
|
e2cc84f to
8cf45bc
Compare
potiuk
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.
Hey @kaxil FYI I saw that you enabled auto merge on this one (assuming you were happy with it once it went green) but you also have changes requested which is blocking it's merge (same as well @potiuk).
Yeah. I read the explanation and now it's a;ll clear - I guess we need to re-learn some of the things that we took for granted in Airflow 2 :) .... And yeah I am fine either way - but consistency is likely more important than not having the executor information at all.
That said - I just I have another question, however..
Our helm chart supports still both Airlfow 2 and Airflow 3 .. Is not that change handling only Airflow 3 case? Should we make it:
- if Airflow 2 -> LocalExecutor
- else > executor
?
Or am I missing something ?
8cf45bc to
9f2efc5
Compare
Under Airflow 2 you should not need to specifically set core.executor=LocalExecutor either, the tasks will run on the local task runner either way because the |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
|
Hey folks, still interested in seeing this one merged. @potiuk does the answer above satisfy your question? Looks like everyone is approved and ready to merge if we can get the request for changes removed. |
Ah sure - dismissed my review. I missed it. Sorry |
9f2efc5 to
6b8667e
Compare
|
I rebased it now - just in case. |
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
|
Thank you so much for your thoughtful and patient reviews — especially while I was away on vacation and not as responsive as I would have liked. I'm incredibly grateful for the opportunity to make my very first contribution to Airflow, a project I truly love. Your guidance made that possible. This has been such a meaningful experience for me, and I’m more motivated than ever to keep learning and continue contributing to the Airflow community. Looking forward to many more! |
|
Glad to hear that @ihnokim ! Sorry it took so long to get this one merged and welcome to the community |
|
Thanks for your contribution @ihnokim . Hope you had a good vacation 🏖️ |

closes: #48667
related: #48667
Changes
AIRFLOW__CORE__EXECUTORvalue, previously hardcoded to LocalExecutor, now respects the setting fromvalues.yaml.Why we need?
There is an issue when using multiple executors: if a specific executor is explicitly defined in a task parameter, the pod created by the pod_template may fail to run properly. This happens because the default pod_template generated by the Helm chart hardcodes the executor to
LocalExecutorvia theAIRFLOW__CORE__EXECUTORenvironment variable.For example, in an environment where
KubernetesExecutoris used, if a task is defined in the DAG with theexecutor="KubernetesExecutor"parameter, the pod will still haveAIRFLOW__CORE__EXECUTOR=LocalExecutorin its environment variables. This leads to the following error:To resolve this and improve the user experience for Helm chart users, I’ve updated the default pod_template so that the
AIRFLOW__CORE__EXECUTORvalue matches the executor defined invalues.yaml.After this change, I confirmed that tasks using
KubernetesExecutorrun successfully with the following DAG:Let me know if any additional clarification is needed!
^ 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.