@@ -41,9 +41,14 @@ def __init__(self, token_filename,
41
41
self ._cert_filename = cert_filename
42
42
self ._environ = environ
43
43
44
- def load_and_set (self ):
44
+ def load_and_set (self , client_configuration = None ):
45
45
self ._load_config ()
46
- self ._set_config ()
46
+ if client_configuration :
47
+ self ._set_config (client_configuration )
48
+ else :
49
+ configuration = Configuration ()
50
+ self ._set_config (configuration )
51
+ Configuration .set_default (configuration )
47
52
48
53
def _load_config (self ):
49
54
if (SERVICE_HOST_ENV_NAME not in self ._environ or
@@ -76,18 +81,20 @@ def _load_config(self):
76
81
77
82
self .ssl_ca_cert = self ._cert_filename
78
83
79
- def _set_config (self ):
80
- configuration = Configuration ()
84
+ def _set_config (self , configuration ):
81
85
configuration .host = self .host
82
86
configuration .ssl_ca_cert = self .ssl_ca_cert
83
87
configuration .api_key ['BearerToken' ] = "Bearer " + self .token
84
- Configuration .set_default (configuration )
85
88
86
89
87
- def load_incluster_config ():
90
+ def load_incluster_config (client_configuration = None ):
88
91
"""Use the service account kubernetes gives to pods to connect to kubernetes
89
92
cluster. It's intended for clients that expect to be running inside a pod
90
93
running on kubernetes. It will raise an exception if called from a process
91
- not running in a kubernetes environment."""
94
+ not running in a kubernetes environment.
95
+
96
+ :param client_configuration: The kubernetes.client.Configuration to
97
+ set configs to.
98
+ """
92
99
InClusterConfigLoader (token_filename = SERVICE_TOKEN_FILENAME ,
93
- cert_filename = SERVICE_CERT_FILENAME ).load_and_set ()
100
+ cert_filename = SERVICE_CERT_FILENAME ).load_and_set (client_configuration )
0 commit comments