amoghrajesh opened a new pull request, #46860:
URL: https://github.com/apache/airflow/pull/46860
<!--
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/
-->
closes: #45427
## Why?
- As part of porting all executors to use task SDK and cut down on the tasks
from using DB access, KubernetesExecutor is the last one.
- We want the K8s workers (pods) to use the new supervisor task runner
machinery instead of running "airflow tasks run..."
- The workers will now communicate with the api server which can be deployed
anywhere instead of talking to the DB directly.
## Approach
### Changes to base executor
The interface for "CommandType" has been changed to accept either a sequence
string or workloads.ExecuteTask which will be useful for KubernetesExecutor.
### Changes to K8sExecutor
- Every "task" is recognised as a workload and not a command for airflow 3.
So, the queued tasks list now contains mapping of [TI KEY, workload].
- We override `queue_workload` and `_process_workloads` in lieu of what was
done for celery executor: https://github.com/apache/airflow/pull/46265
The queue_workload is simple, it just enqueues the "workload"
`_process_workloads` calls `execute_async` for every workload present. And
it also pops it from `queued_tasks` and adds it to `running`
- `execute_async` does the usual as it did earlier.
### Changes to K8sExecutor utils
- We have a utility: `run_next` which is supposed to run the "next" task in
the queue in a pod.
- We continue to do that, but now we have a workload and we need to run it
in a pod.
```
token='dummy-token'
ti=TaskInstance(id=UUID('0195178d-1863-7be6-b504-6563a746c9e5'),
task_id='print_date', dag_id='tutorial',
run_id='manual__2025-02-18T05:34:37.633253+00:00_Uvod17gj', try_number=1,
map_index=-1, pool_slots=1, queue='default', priority_weight=3)
dag_rel_path=PurePosixPath('tutorial.py')
bundle_info=BundleInfo(name='dags-folder', version=None)
log_path='dag_id=tutorial/run_id=manual__2025-02-18T05:34:37.633253+00:00_Uvod17gj/task_id=print_date/attempt=1.log'
kind='ExecuteTask'
```
- We need to send this down to a pod and then it needs to run it using the
new task sdk machinery using supervisor.
- Writing this to CLI is not a great option, as it has a token in it which
is not the best option to write to CLI.
- Instead, we serialise the input and mount it in the filesystem of the
created pod. And run something like:
```
command = [
"python",
"-m",
"airflow.sdk.execution_time.execute_workload",
"/tmp/execute/input.json",
]
```
Where `execute_workload` is a new module (discussed later)
### Changes to the pod generator
- We now accept an input: `content_json_for_volume`
- If populated, we create:
EmptyDir volume
A volume mount at: `/tmp/execute/input.json`
Dump the content into this file as received from the K8sExecutor utils
- We also modify the entrypoint now not to run the `/entrypoint`
### New module: `airflow.sdk.execution_time.execute_workload`
- Simple new module that executes an Airflow task using the workload json
provided by a input file.
- It deserialises the json mount, converts to python json object
- Passes it down to supervise function:
```
supervise(
# This is the "wrong" ti type, but it duck types the same. TODO:
Create a protocol for this.
ti=workload.ti, # type: ignore[arg-type]
dag_rel_path=workload.dag_rel_path,
bundle_info=workload.bundle_info,
token=workload.token,
# fallback to internal cluster service for api server
server=conf.get(
"workers",
"execution_api_server_url",
fallback="http://airflow-api-server.airflow.svc.cluster.local:9091/execution/",
),
log_path=workload.log_path,
)
```
## TODO
- [ ] Update the description with more details about testing etc
- [ ] Discuss populating: `server` in supervisor
- [ ] Testing details
- [ ] Check with Jed for logging solution for K8s pod logs currently used.
<!-- 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]