atrbgithub opened a new pull request, #61839: URL: https://github.com/apache/airflow/pull/61839
Closes: https://github.com/apache/airflow/issues/57553 This commit ensures that completed pods are eventually cleaned up. <!-- 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/ --> <!-- Please keep an empty line above the dashes. --> --- Previously, in say `2.9.3`, `self.job.executor.try_adopt_task_instances` was always called here: https://github.com/apache/airflow/blob/81845de9d95a733b4eb7826aaabe23ba9813eba3/airflow/jobs/scheduler_job_runner.py#L1641 It was called unconditionally, even if it found no TaskInstances to adopt. This meant that in the kubernetes executor, we would always call this line: https://github.com/apache/airflow/blob/81845de9d95a733b4eb7826aaabe23ba9813eba3/airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py#L601 This was triggered at startup by calling `adopt_or_reset_orphaned_tasks`, here: https://github.com/apache/airflow/blob/81845de9d95a733b4eb7826aaabe23ba9813eba3/airflow/jobs/scheduler_job_runner.py#L928 It was also then called frequently, configurable with `orphaned_tasks_check_interval`. The result of this is that if the query that is run to detect adoptable tasks does not find any tasks to adopt, we no longer make a call to `_adopt_completed_pods`, and as a result completed pods are left hanging around. This happens when an old scheduler instance is stopped and a new one takes its place. This PR partially restores the old behaviour (frequent calls to `_adopt_completed_pods`). Tests pass with: ``` breeze run pytest providers/cncf/kubernetes/tests/unit -v ``` The issue can be replicated in the following way using Aiflow 3.1.7: 1. Spin up a 3.1.7 cluster locally with unmodified code. 2. Spin up tasks via the executor 3. Stop the scheduler before they finished. 4. Pods go to a completed state 5. Start the scheduler 6. Pods are never cleaned up With this patch, shortly after starting up the scheduler the completed pods will be cleaned up. -- 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]
