Skip to content
Closed
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
4 changes: 3 additions & 1 deletion kubernetes/base/config/kube_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ def _load_cluster_info(self):
self.verify_ssl = not self._cluster['insecure-skip-tls-verify']
if 'tls-server-name' in self._cluster:
self.tls_server_name = self._cluster['tls-server-name']
if 'proxy-url' in self._cluster:
self.proxy = self._cluster['proxy-url']

def _set_config(self, client_configuration):
if 'token' in self.__dict__:
Expand All @@ -580,7 +582,7 @@ def _refresh_api_key(client_configuration):
self._set_config(client_configuration)
client_configuration.refresh_api_key_hook = _refresh_api_key
# copy these keys directly from self to configuration object
keys = ['host', 'ssl_ca_cert', 'cert_file', 'key_file', 'verify_ssl','tls_server_name']
keys = ['host', 'ssl_ca_cert', 'cert_file', 'key_file', 'verify_ssl', 'tls_server_name', 'proxy']
for key in keys:
if key in self.__dict__:
setattr(client_configuration, key, getattr(self, key))
Expand Down
24 changes: 24 additions & 0 deletions kubernetes/base/config/kube_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def _raise_exception(st):
TEST_CLIENT_CERT_BASE64 = _base64(TEST_CLIENT_CERT)
TEST_TLS_SERVER_NAME = "kubernetes.io"

TEST_PROXY_URL = "http://localhost:8888"

TEST_OIDC_TOKEN = "test-oidc-token"
TEST_OIDC_INFO = "{\"name\": \"test\"}"
TEST_OIDC_BASE = ".".join([
Expand Down Expand Up @@ -551,6 +553,12 @@ class TestKubeConfigLoader(BaseTestCase):
"user": "ssl-local-file"
}
},
{
"name": "proxy",
"context": {
"cluster": "proxy",
}
},
{
"name": "non_existing_user",
"context": {
Expand Down Expand Up @@ -652,6 +660,12 @@ class TestKubeConfigLoader(BaseTestCase):
"tls-server-name": TEST_TLS_SERVER_NAME,
}
},
{
"name": "proxy",
"cluster": {
"proxy-url": TEST_PROXY_URL,
}
},
],
"users": [
{
Expand Down Expand Up @@ -1284,6 +1298,16 @@ def test_tls_server_name(self):
active_context="tls-server-name").load_and_set(actual)
self.assertEqual(expected, actual)

def test_proxy_server(self):
expected = FakeConfig(
proxy=TEST_PROXY_URL
)
actual = FakeConfig()
KubeConfigLoader(
config_dict=self.TEST_KUBE_CONFIG,
active_context="proxy").load_and_set(actual)
self.assertEqual(expected, actual)

def test_list_contexts(self):
loader = KubeConfigLoader(
config_dict=self.TEST_KUBE_CONFIG,
Expand Down