@@ -66,6 +66,7 @@ def __init__(
66
66
auto_reconnect : bool = False ,
67
67
auto_reconnect_max_attempts : int = DEFAULT_AUTO_RECONNECT_MAX_ATTEMPTS ,
68
68
auto_reconnect_wait_between_attempts : float = DEFAULT_AUTO_RECONNECT_WAIT_BETWEEN_ATTEMPTS ,
69
+ always_throw_on_first_api_call : bool = True ,
69
70
):
70
71
assert use_asyncio is not True , NotImplementedError ("AsyncIO not yet implemented." )
71
72
super ().__init__ (
@@ -87,6 +88,7 @@ def __init__(
87
88
self .auto_reconnect = auto_reconnect
88
89
self .auto_reconnect_max_attempts = auto_reconnect_max_attempts
89
90
self .auto_reconnect_wait_between_attempts = auto_reconnect_wait_between_attempts
91
+ self .always_throw_on_first_api_call = always_throw_on_first_api_call
90
92
91
93
# these event are object specific
92
94
self .query_started_event_name = f"{ self .query_started_event_name } { id (self )} "
@@ -257,9 +259,10 @@ def can_reconnect(message=None):
257
259
exception_message = (
258
260
f"{ ex .reason } , { exception_details .get ('reason' )} : { exception_details .get ('message' )} "
259
261
)
260
- if can_reconnect (True , exception_message ):
262
+ force_throw = self .always_throw_on_first_api_call and total_reconnects == 0
263
+ if not force_throw and can_reconnect (exception_message ):
261
264
continue
262
- if self .query_running and not self ._is_being_stopped :
265
+ if force_throw or self .query_running and not self ._is_being_stopped :
263
266
raise KubeApiClientException (exception_message , inner_exception = ex )
264
267
else :
265
268
raise ex
@@ -405,7 +408,7 @@ def load_kubernetes_configuration_from_file(
405
408
)
406
409
407
410
configuration = kube_config .Configuration ()
408
-
411
+ configuration . filepath = None
409
412
if is_in_cluster and config_file is None :
410
413
# load from cluster.
411
414
loader = incluster_config .InClusterConfigLoader (
@@ -423,7 +426,8 @@ def load_kubernetes_configuration_from_file(
423
426
DEFAULT_KUBE_CONFIG_LOCATIONS ,
424
427
)
425
428
for loc in config_possible_locations :
426
- if os .path .isfile (expanduser (loc )):
429
+ loc = expanduser (loc )
430
+ if os .path .isfile (loc ):
427
431
config_file = loc
428
432
429
433
assert config_file is not None , "Kubernetes config file not provided and default config could not be found."
0 commit comments