Skip to content
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

Replace blocking IO with async IO in AsyncKubernetesHook #35162

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions airflow/providers/cncf/kubernetes/hooks/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from functools import cached_property
from typing import TYPE_CHECKING, Any, Generator

import aiofiles
from asgiref.sync import sync_to_async
from kubernetes import client, config, watch
from kubernetes.config import ConfigException
Expand Down Expand Up @@ -502,13 +503,13 @@ async def _load_config(self):
return async_client.ApiClient()

if kubeconfig is not None:
with tempfile.NamedTemporaryFile() as temp_config:
async with aiofiles.tempfile.NamedTemporaryFile() as temp_config:
self.log.debug(
"Reading kubernetes configuration file from connection "
"object and writing temporary config file with its content",
)
temp_config.write(kubeconfig.encode())
temp_config.flush()
await temp_config.write(kubeconfig.encode())
await temp_config.flush()
self._is_in_cluster = False
await async_config.load_kube_config(
config_file=temp_config.name,
Expand Down
1 change: 1 addition & 0 deletions airflow/providers/cncf/kubernetes/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ versions:
- 1.0.0

dependencies:
- aiofiles>=23.2.0
- apache-airflow>=2.5.0
- asgiref>=3.5.2
- cryptography>=2.0.0
Expand Down
1 change: 1 addition & 0 deletions generated/provider_dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
},
"cncf.kubernetes": {
"deps": [
"aiofiles>=23.2.0",
"apache-airflow>=2.5.0",
"asgiref>=3.5.2",
"cryptography>=2.0.0",
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def write_version(filename: str = str(AIRFLOW_SOURCES_ROOT / "airflow" / "git_ve
# Make sure to upgrade the mypy version in update-common-sql-api-stubs in .pre-commit-config.yaml
# when you upgrade it here !!!!
"mypy==1.2.0",
"types-aiofiles",
"types-certifi",
"types-croniter",
"types-Deprecated",
Expand Down
Loading