Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit 8b386bb

Browse files
committed
Change utility functions to new set_default Configuration model, preparing to use swagger-codegen HEAD
1 parent 31e13b1 commit 8b386bb

File tree

7 files changed

+25
-1302
lines changed

7 files changed

+25
-1302
lines changed

api_client.py

-657
This file was deleted.

config/incluster_config.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import os
1616

17-
from kubernetes.client import configuration
17+
from kubernetes.client import Configuration
1818

1919
from .config_exception import ConfigException
2020

@@ -77,9 +77,11 @@ def _load_config(self):
7777
self.ssl_ca_cert = self._cert_filename
7878

7979
def _set_config(self):
80+
configuration = Configuration()
8081
configuration.host = self.host
8182
configuration.ssl_ca_cert = self.ssl_ca_cert
8283
configuration.api_key['authorization'] = "bearer " + self.token
84+
Configuration.set_default(configuration)
8385

8486

8587
def load_incluster_config():

config/kube_config.py

+18-15
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import urllib3
2424
import yaml
2525

26-
from kubernetes.client import ApiClient, ConfigurationObject, configuration
26+
from kubernetes.client import ApiClient, Configuration
2727

2828
from .config_exception import ConfigException
2929
from .dateutil import UTC, format_rfc3339, parse_rfc3339
@@ -118,7 +118,6 @@ class KubeConfigLoader(object):
118118

119119
def __init__(self, config_dict, active_context=None,
120120
get_google_credentials=None,
121-
client_configuration=configuration,
122121
config_base_path="",
123122
config_persister=None):
124123
self._config = ConfigNode('kube-config', config_dict)
@@ -139,7 +138,6 @@ def _refresh_credentials():
139138
self._get_google_credentials = get_google_credentials
140139
else:
141140
self._get_google_credentials = _refresh_credentials
142-
self._client_configuration = client_configuration
143141

144142
def set_active_context(self, context_name=None):
145143
if context_name is None:
@@ -240,19 +238,19 @@ def _load_cluster_info(self):
240238
if 'insecure-skip-tls-verify' in self._cluster:
241239
self.verify_ssl = not self._cluster['insecure-skip-tls-verify']
242240

243-
def _set_config(self):
241+
def _set_config(self, client_configuration):
244242
if 'token' in self.__dict__:
245-
self._client_configuration.api_key['authorization'] = self.token
243+
client_configuration.api_key['authorization'] = self.token
246244
# copy these keys directly from self to configuration object
247245
keys = ['host', 'ssl_ca_cert', 'cert_file', 'key_file', 'verify_ssl']
248246
for key in keys:
249247
if key in self.__dict__:
250-
setattr(self._client_configuration, key, getattr(self, key))
248+
setattr(client_configuration, key, getattr(self, key))
251249

252-
def load_and_set(self):
250+
def load_and_set(self, client_configuration):
253251
self._load_authentication()
254252
self._load_cluster_info()
255-
self._set_config()
253+
self._set_config(client_configuration)
256254

257255
def list_contexts(self):
258256
return [context.value for context in self._config['contexts']]
@@ -331,15 +329,15 @@ def list_kube_config_contexts(config_file=None):
331329

332330

333331
def load_kube_config(config_file=None, context=None,
334-
client_configuration=configuration,
332+
client_configuration=None,
335333
persist_config=True):
336334
"""Loads authentication and cluster information from kube-config file
337335
and stores them in kubernetes.client.configuration.
338336
339337
:param config_file: Name of the kube-config file.
340338
:param context: set the active context. If is set to None, current_context
341339
from config file will be used.
342-
:param client_configuration: The kubernetes.client.ConfigurationObject to
340+
:param client_configuration: The kubernetes.client.Configuration to
343341
set configs to.
344342
:param persist_config: If True, config file will be updated when changed
345343
(e.g GCP token refresh).
@@ -355,10 +353,15 @@ def _save_kube_config(config_map):
355353
yaml.safe_dump(config_map, f, default_flow_style=False)
356354
config_persister = _save_kube_config
357355

358-
_get_kube_config_loader_for_yaml_file(
356+
loader = _get_kube_config_loader_for_yaml_file(
359357
config_file, active_context=context,
360-
client_configuration=client_configuration,
361-
config_persister=config_persister).load_and_set()
358+
config_persister=config_persister)
359+
if client_configuration is None:
360+
config = Configuration()
361+
loader.load_and_set(config)
362+
Configuration.set_default(config)
363+
else:
364+
loader.load_and_set(client_configuration)
362365

363366

364367
def new_client_from_config(
@@ -368,8 +371,8 @@ def new_client_from_config(
368371
"""Loads configuration the same as load_kube_config but returns an ApiClient
369372
to be used with any API object. This will allow the caller to concurrently
370373
talk with multiple clusters."""
371-
client_config = ConfigurationObject()
374+
client_config = Configuration()
372375
load_kube_config(config_file=config_file, context=context,
373376
client_configuration=client_config,
374377
persist_config=persist_config)
375-
return ApiClient(config=client_config)
378+
return ApiClient(configuration=client_config)

configuration.py

-247
This file was deleted.

0 commit comments

Comments
 (0)