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

fix: change disable_verify_ssl behaviour #25023

Merged
merged 2 commits into from
Jul 28, 2022
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
11 changes: 7 additions & 4 deletions airflow/kubernetes/kube_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
has_kubernetes = True

def _disable_verify_ssl() -> None:
configuration = Configuration()
if hasattr(Configuration, 'get_default_copy'):
configuration = Configuration.get_default_copy()
else:
configuration = Configuration()
configuration.verify_ssl = False
Configuration.set_default(configuration)

Expand Down Expand Up @@ -100,9 +103,6 @@ def get_kube_client(
if conf.getboolean('kubernetes', 'enable_tcp_keepalive'):
_enable_tcp_keepalive()

if not conf.getboolean('kubernetes', 'verify_ssl'):
_disable_verify_ssl()

if in_cluster:
config.load_incluster_config()
else:
Expand All @@ -112,4 +112,7 @@ def get_kube_client(
config_file = conf.get('kubernetes', 'config_file', fallback=None)
config.load_kube_config(config_file=config_file, context=cluster_context)

if not conf.getboolean('kubernetes', 'verify_ssl'):
_disable_verify_ssl()

return client.CoreV1Api()
13 changes: 13 additions & 0 deletions tests/kubernetes/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ def test_load_file_config(self, config):
assert config.load_incluster_config.not_called
assert config.load_kube_config.called

@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)
conf.getboolean.assert_called_with('kubernetes', 'verify_ssl')
# Support wide range of kube client libraries
if hasattr(Configuration, 'get_default_copy'):
configuration = Configuration.get_default_copy()
else:
configuration = Configuration()
self.assertFalse(configuration.verify_ssl)

def test_enable_tcp_keepalive(self):
socket_options = [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
Expand Down