Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0b1bb3d
Adding configuration to control retry parameters for k8s api client
Feb 28, 2023
ed5d40d
Handling review comments
Mar 1, 2023
56db0f6
Fixing code bug
Mar 1, 2023
b789b60
Fixing failing tests
Mar 1, 2023
c667363
Merge branch 'main' into k8sApiServerRetry
amoghrajesh Mar 1, 2023
ca46239
Merge branch 'main' into k8sApiServerRetry
amoghrajesh Mar 1, 2023
03ab949
Merge branch 'main' into k8sApiServerRetry
amoghrajesh Mar 2, 2023
8709dff
Temporary commit with UT wip
Mar 3, 2023
d55c256
Fixing unit test
Mar 5, 2023
1ce30c9
Merge branch 'main' into k8sApiServerRetry
amoghrajesh Mar 5, 2023
22c53e3
Fixing the strict checks
Mar 5, 2023
fa3bc26
Handling review comments from Hussein
Mar 5, 2023
0ff1e34
Merge branch 'main' into k8sApiServerRetry
amoghrajesh Mar 7, 2023
2d6a218
Revert "Handling review comments from Hussein"
Mar 7, 2023
e8eb0be
Fixing failing ut
Mar 7, 2023
2166299
Reverting bad hack
Mar 12, 2023
fbfb091
Updating logic in kube_client.py
amoghrajesh Mar 14, 2023
d5afb50
Merge branch 'main' into k8sApiServerRetry
amoghrajesh Mar 14, 2023
31b228a
Fixing unit tests
Mar 17, 2023
7c83542
Merge branch 'main' into k8sApiServerRetry
Mar 17, 2023
c889ab6
Fixing unit tests
Mar 20, 2023
2434b36
Merge branch 'main' into k8sApiServerRetry
amoghrajesh Mar 20, 2023
260b333
Handling review comments from Ash
Mar 20, 2023
ea3cdd2
Merge branch 'k8sApiServerRetry' of github.com:amoghrajesh/airflow in…
Mar 20, 2023
c8d23e2
Merge branch 'main' into k8sApiServerRetry
Mar 22, 2023
a59c024
Merge branch 'main' into k8sApiServerRetry
amoghrajesh Mar 23, 2023
0b4efca
Fix loading mock call args for python3.7
hussein-awala Apr 13, 2023
6d2c543
Apply suggestions from code review
hussein-awala Apr 13, 2023
7d824a8
fix static check
hussein-awala Apr 13, 2023
fb2deed
add in 2.6.0
hussein-awala Apr 14, 2023
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: 7 additions & 0 deletions airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,13 @@ kubernetes_executor:
previous_name: kubernetes
version: 2.5.0
options:
api_client_retry_configuration:
description: |
Kwargs to override the default urllib3 Retry used in the kubernetes API client
version_added: 2.6.0
type: string
example: '{ "total": 3, "backoff_factor": 0.5 }'
default: ""
pod_template_file:
description: |
Path to the YAML pod file that forms the basis for KubernetesExecutor workers.
Expand Down
4 changes: 4 additions & 0 deletions airflow/config_templates/default_airflow.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,10 @@ use_ssl = False
verify_certs = True

[kubernetes_executor]
# Kwargs to override the default urllib3 Retry used in the kubernetes API client
# Example: api_client_retry_configuration = {{ "total": 3, "backoff_factor": 0.5 }}
api_client_retry_configuration =

# Path to the YAML pod file that forms the basis for KubernetesExecutor workers.
pod_template_file =

Expand Down
21 changes: 17 additions & 4 deletions airflow/kubernetes/kube_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import logging

import urllib3.util

from airflow.configuration import conf

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -107,16 +109,27 @@ def get_kube_client(
if conf.getboolean("kubernetes_executor", "enable_tcp_keepalive"):
_enable_tcp_keepalive()

configuration = _get_default_configuration()
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):
configuration.retries = urllib3.util.Retry(**api_client_retry_configuration)
else:
raise ValueError("api_client_retry_configuration should be a dictionary")
Comment thread
amoghrajesh marked this conversation as resolved.

if in_cluster:
config.load_incluster_config()
config.load_incluster_config(client_configuration=configuration)
else:
if cluster_context is None:
cluster_context = conf.get("kubernetes_executor", "cluster_context", fallback=None)
if config_file is None:
config_file = conf.get("kubernetes_executor", "config_file", fallback=None)
config.load_kube_config(config_file=config_file, context=cluster_context)

configuration = _get_default_configuration()
config.load_kube_config(
config_file=config_file, context=cluster_context, client_configuration=configuration
)

if not conf.getboolean("kubernetes_executor", "verify_ssl"):
configuration.verify_ssl = False
Expand Down
11 changes: 11 additions & 0 deletions tests/kubernetes/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from urllib3.connection import HTTPConnection, HTTPSConnection

from airflow.kubernetes.kube_client import _disable_verify_ssl, _enable_tcp_keepalive, get_kube_client
from tests.test_utils.config import conf_vars


class TestClient:
Expand All @@ -42,6 +43,7 @@ def test_load_file_config(self, config):
@mock.patch("airflow.kubernetes.kube_client.conf")
def test_load_config_disable_ssl(self, conf, config):
conf.getboolean.return_value = False
conf.getjson.return_value = {"total": 3, "backoff_factor": 0.5}
client = get_kube_client(in_cluster=False)
conf.getboolean.assert_called_with("kubernetes_executor", "verify_ssl")
assert not client.api_client.configuration.verify_ssl
Expand All @@ -50,6 +52,7 @@ def test_load_config_disable_ssl(self, conf, config):
@mock.patch("airflow.kubernetes.kube_client.conf")
def test_load_config_ssl_ca_cert(self, conf, config):
conf.get.return_value = "/path/to/ca.crt"
conf.getjson.return_value = {"total": 3, "backoff_factor": 0.5}
client = get_kube_client(in_cluster=False)
conf.get.assert_called_with("kubernetes_executor", "ssl_ca_cert")
assert client.api_client.configuration.ssl_ca_cert == "/path/to/ca.crt"
Expand Down Expand Up @@ -81,3 +84,11 @@ def test_disable_verify_ssl(self):
else:
configuration = Configuration()
assert not configuration.verify_ssl

@mock.patch("kubernetes.config.incluster_config.InClusterConfigLoader")
@conf_vars({("kubernetes", "api_client_retry_configuration"): '{"total": 3, "backoff_factor": 0.5}'})
def test_api_client_retry_configuration_correct_values(self, mock_in_cluster_loader):
get_kube_client(in_cluster=True)
client_configuration = mock_in_cluster_loader().load_and_set.call_args[0][0]
assert client_configuration.retries.total == 3
assert client_configuration.retries.backoff_factor == 0.5