amoghrajesh commented on code in PR #29809:
URL: https://github.com/apache/airflow/pull/29809#discussion_r1135721266
##########
airflow/kubernetes/kube_client.py:
##########
@@ -105,16 +107,26 @@ def get_kube_client(
if conf.getboolean("kubernetes_executor", "enable_tcp_keepalive"):
_enable_tcp_keepalive()
+ new_client_config = Configuration.get_default_copy()
+ api_client_retry_configuration = conf.getjson("kubernetes",
"api_client_retry_configuration", fallback={})
+
+ if not conf.getboolean("kubernetes_executor", "verify_ssl"):
+ _disable_verify_ssl()
+
+ if isinstance(api_client_retry_configuration, dict) and
api_client_retry_configuration != {}:
+ new_client_config.retries =
urllib3.util.Retry(**api_client_retry_configuration)
+ else:
+ raise ValueError("api_client_retry_configuration should be a
dictionary")
Review Comment:
@hterik If I make the code to have an exception (state before the last
commit), the tests look like this
```
/Users/adesai/.pyenv/versions/airflow-env/bin/python
"/Users/adesai/Library/Application
Support/JetBrains/GoLand2021.3/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py"
--target test_client.py::TestClient
Testing started at 8:45 PM ...
Launching pytest with arguments test_client.py::TestClient --no-header
--no-summary -q in
/Users/adesai/Documents/OpenSource/Airflow/airflow/tests/kubernetes
============================= test session starts
==============================
collecting ... collected 7 items
test_client.py::TestClient::test_load_cluster_config
========================= AIRFLOW ==========================
Home of the user: /Users/adesai
Airflow home /Users/adesai/airflow
Skipping initializing of the DB as it was initialized already.
You can re-initialize the database by adding --with-db-init flag when
running tests.
FAILED [ 14%]
tests/kubernetes/test_client.py:30 (TestClient.test_load_cluster_config)
self = <tests.kubernetes.test_client.TestClient object at 0x112250df0>
config = <MagicMock name='config' id='4602299968'>
@mock.patch("airflow.kubernetes.kube_client.config")
def test_load_cluster_config(self, config):
> get_kube_client(in_cluster=True)
test_client.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _
in_cluster = True, cluster_context = None, config_file = None
def get_kube_client(
in_cluster: bool = conf.getboolean("kubernetes_executor",
"in_cluster"),
cluster_context: str | None = None,
config_file: str | None = None,
) -> client.CoreV1Api:
"""
Retrieves Kubernetes client.
:param in_cluster: whether we are in cluster
:param cluster_context: context of the cluster
:param config_file: configuration file
:return kubernetes client
:rtype client.CoreV1Api
"""
if not has_kubernetes:
raise _import_err
if conf.getboolean("kubernetes_executor", "enable_tcp_keepalive"):
_enable_tcp_keepalive()
new_client_config = Configuration.get_default_copy()
api_client_retry_configuration = conf.getjson("kubernetes",
"api_client_retry_configuration", fallback={})
if not conf.getboolean("kubernetes_executor", "verify_ssl"):
_disable_verify_ssl()
if isinstance(api_client_retry_configuration, dict) and
api_client_retry_configuration != {}:
new_client_config.retries =
urllib3.util.Retry(**api_client_retry_configuration)
else:
> raise ValueError("api_client_retry_configuration should be a
dictionary")
E ValueError: api_client_retry_configuration should be a dictionary
../../airflow/kubernetes/kube_client.py:119: ValueError
FAILED [ 28%]
tests/kubernetes/test_client.py:36 (TestClient.test_load_file_config)
self = <tests.kubernetes.test_client.TestClient object at 0x112250d00>
config = <MagicMock name='config' id='4603967328'>
@mock.patch("airflow.kubernetes.kube_client.config")
def test_load_file_config(self, config):
> get_kube_client(in_cluster=False)
test_client.py:39:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _
in_cluster = False, cluster_context = None, config_file = None
def get_kube_client(
in_cluster: bool = conf.getboolean("kubernetes_executor",
"in_cluster"),
cluster_context: str | None = None,
config_file: str | None = None,
) -> client.CoreV1Api:
"""
Retrieves Kubernetes client.
:param in_cluster: whether we are in cluster
:param cluster_context: context of the cluster
:param config_file: configuration file
:return kubernetes client
:rtype client.CoreV1Api
"""
if not has_kubernetes:
raise _import_err
if conf.getboolean("kubernetes_executor", "enable_tcp_keepalive"):
_enable_tcp_keepalive()
new_client_config = Configuration.get_default_copy()
api_client_retry_configuration = conf.getjson("kubernetes",
"api_client_retry_configuration", fallback={})
if not conf.getboolean("kubernetes_executor", "verify_ssl"):
_disable_verify_ssl()
if isinstance(api_client_retry_configuration, dict) and
api_client_retry_configuration != {}:
new_client_config.retries =
urllib3.util.Retry(**api_client_retry_configuration)
else:
> raise ValueError("api_client_retry_configuration should be a
dictionary")
E ValueError: api_client_retry_configuration should be a dictionary
../../airflow/kubernetes/kube_client.py:119: ValueError
FAILED [ 42%]
tests/kubernetes/test_client.py:42 (TestClient.test_load_config_disable_ssl)
self = <tests.kubernetes.test_client.TestClient object at 0x112250e20>
conf = <MagicMock name='conf' id='4604005248'>
config = <MagicMock name='config' id='4604090400'>
@mock.patch("airflow.kubernetes.kube_client.config")
@mock.patch("airflow.kubernetes.kube_client.conf")
def test_load_config_disable_ssl(self, conf, config):
conf.getboolean.return_value = False
> get_kube_client(in_cluster=False)
test_client.py:47:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _
in_cluster = False, cluster_context = None, config_file = None
def get_kube_client(
in_cluster: bool = conf.getboolean("kubernetes_executor",
"in_cluster"),
cluster_context: str | None = None,
config_file: str | None = None,
) -> client.CoreV1Api:
"""
Retrieves Kubernetes client.
:param in_cluster: whether we are in cluster
:param cluster_context: context of the cluster
:param config_file: configuration file
:return kubernetes client
:rtype client.CoreV1Api
"""
if not has_kubernetes:
raise _import_err
if conf.getboolean("kubernetes_executor", "enable_tcp_keepalive"):
_enable_tcp_keepalive()
new_client_config = Configuration.get_default_copy()
api_client_retry_configuration = conf.getjson("kubernetes",
"api_client_retry_configuration", fallback={})
if not conf.getboolean("kubernetes_executor", "verify_ssl"):
_disable_verify_ssl()
if isinstance(api_client_retry_configuration, dict) and
api_client_retry_configuration != {}:
new_client_config.retries =
urllib3.util.Retry(**api_client_retry_configuration)
else:
> raise ValueError("api_client_retry_configuration should be a
dictionary")
E ValueError: api_client_retry_configuration should be a dictionary
../../airflow/kubernetes/kube_client.py:119: ValueError
FAILED [ 57%]
tests/kubernetes/test_client.py:55 (TestClient.test_enable_tcp_keepalive)
self = <tests.kubernetes.test_client.TestClient object at 0x112250100>
def test_enable_tcp_keepalive(self):
socket_options = [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
> (socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 120),
(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 30),
(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 6),
]
E AttributeError: module 'socket' has no attribute 'TCP_KEEPIDLE'
test_client.py:59: AttributeError
PASSED [ 71%]PASSED [ 85%][2023-03-14T20:45:44.378+0530]
{configuration.py:1372} INFO - Reading default test configuration from
/Users/adesai/Documents/OpenSource/Airflow/airflow/airflow/config_templates/default_test.cfg
[2023-03-14T20:45:44.380+0530] {configuration.py:1375} INFO - Reading test
configuration from /Users/adesai/airflow/unittests.cfg
PASSED [100%]
test_client.py::TestClient::test_load_file_config
test_client.py::TestClient::test_load_config_disable_ssl
test_client.py::TestClient::test_enable_tcp_keepalive
test_client.py::TestClient::test_disable_verify_ssl
test_client.py::TestClient::test_api_client_retry_configuration_default
test_client.py::TestClient::test_api_client_retry_configuration_correct_values
========================= 4 failed, 3 passed in 0.89s
==========================
Process finished with exit code 1
```
--
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]