@@ -101,15 +101,22 @@ def get_client(
101
101
Returns:
102
102
DynamicClient: a kubernetes client.
103
103
"""
104
+ client_configuration = kwargs .get ("client_configuration" , kubernetes .client .Configuration ())
105
+
106
+ # If the proxy is not set, set it from the environment
107
+ if not client_configuration .proxy :
108
+ proxy = os .environ .get ("HTTPS_PROXY" ) or os .environ .get ("HTTP_PROXY" )
109
+ if proxy :
110
+ client_configuration .proxy = proxy
111
+
112
+ kwargs ["client_configuration" ] = client_configuration
113
+
104
114
# Ref: https://github.com/kubernetes-client/python/blob/v26.1.0/kubernetes/base/config/kube_config.py
105
115
if config_dict :
106
- return kubernetes .dynamic .DynamicClient (
107
- client = kubernetes .config .new_client_from_config_dict (
108
- config_dict = config_dict , context = context or None , ** kwargs
109
- )
116
+ _client = kubernetes .config .new_client_from_config_dict (
117
+ config_dict = config_dict , context = context or None , ** kwargs
110
118
)
111
- client_configuration = kwargs .get ("client_configuration" , kubernetes .client .Configuration ())
112
- try :
119
+ else :
113
120
# Ref: https://github.com/kubernetes-client/python/blob/v26.1.0/kubernetes/base/config/__init__.py
114
121
LOGGER .info ("Trying to get client via new_client_from_config" )
115
122
@@ -118,28 +125,14 @@ def get_client(
118
125
# is populated during import which comes before setting the variable in code.
119
126
config_file = config_file or os .environ .get ("KUBECONFIG" , "~/.kube/config" )
120
127
121
- if os .environ .get ("OPENSHIFT_PYTHON_WRAPPER_CLIENT_USE_PROXY" ):
122
- proxy = os .environ .get ("HTTPS_PROXY" ) or os .environ .get ("HTTP_PROXY" )
123
- if not proxy :
124
- raise ValueError (
125
- "Proxy configuration is enabled but neither HTTPS_PROXY nor HTTP_PROXY environment variables are set."
126
- )
127
- if client_configuration .proxy and client_configuration .proxy != proxy :
128
- raise ValueError (
129
- f"Conflicting proxy settings: client_configuration.proxy={ client_configuration .proxy } , "
130
- f"but the environment variable 'HTTPS_PROXY/HTTP_PROXY' defines proxy as { proxy } ."
131
- )
132
- client_configuration .proxy = proxy
133
-
134
- kwargs ["client_configuration" ] = client_configuration
135
-
136
- return kubernetes .dynamic .DynamicClient (
137
- client = kubernetes .config .new_client_from_config (
138
- config_file = config_file ,
139
- context = context or None ,
140
- ** kwargs ,
141
- )
128
+ _client = kubernetes .config .new_client_from_config (
129
+ config_file = config_file ,
130
+ context = context or None ,
131
+ ** kwargs ,
142
132
)
133
+
134
+ try :
135
+ return kubernetes .dynamic .DynamicClient (client = _client )
143
136
except MaxRetryError :
144
137
# Ref: https://github.com/kubernetes-client/python/blob/v26.1.0/kubernetes/base/config/incluster_config.py
145
138
LOGGER .info ("Trying to get client via incluster_config" )
0 commit comments