@@ -86,8 +86,7 @@ def createResource(self, jsonStr, **kwargs) -> Union[dict, bool, str]:
8686 url = self .analyzer .FullKindToApiPrefixDict [kind ] + "/"
8787 url += self .getNamespace (self .analyzer .FullKindToNamespaceDict [kind ], namespace )
8888 url += self .analyzer .FullKindToNameDict [kind ]
89-
90- return createRequest (url = url , token = self .token , method = "POST" , body = jsonStr , keep_json = False , ** kwargs )
89+ return createRequest (url = url , token = self .token , method = "POST" , body = jsonStr ,keep_json = False , config = self .config , ** kwargs )
9190
9291 def updateResource (self , jsonStr , ** kwargs ) -> Union [dict , bool , str ]:
9392 jsonObj = jsonStr
@@ -104,7 +103,7 @@ def updateResource(self, jsonStr, **kwargs) -> Union[dict, bool, str]:
104103 url += self .getNamespace (self .analyzer .FullKindToNamespaceDict [kind ], namespace )
105104 url += self .analyzer .FullKindToNameDict [kind ] + "/" + jsonObj ["metadata" ]["name" ]
106105
107- return createRequest (url = url , token = self .token , method = "PUT" , body = jsonStr , keep_json = False , ** kwargs )
106+ return createRequest (url = url , token = self .token , method = "PUT" , body = jsonStr , keep_json = False ,config = self . config , ** kwargs )
108107
109108 def checkAndReturnRealKind (self , kind , mapper ) -> Union [str , str ]:
110109 index = kind .find ("." )
@@ -133,7 +132,7 @@ def deleteResource(self, kind, namespace, name, **kwargs) -> Union[dict, bool, s
133132 url += self .getNamespace (self .analyzer .FullKindToNamespaceDict [fullKind ], namespace )
134133 url += self .analyzer .FullKindToNameDict [fullKind ] + "/" + name
135134
136- return createRequest (url = url , token = self .token , method = "DELETE" , keep_json = False , ** kwargs )
135+ return createRequest (url = url , token = self .token , method = "DELETE" , keep_json = False ,config = self . config , ** kwargs )
137136
138137 def getResource (self , kind , name , namespace = "" , ** kwargs ) -> Union [dict , bool , str ]:
139138 fullKind , error_str = self .checkAndReturnRealKind (kind , self .analyzer .KindToFullKindDict )
@@ -144,7 +143,7 @@ def getResource(self, kind, name, namespace="", **kwargs) -> Union[dict, bool, s
144143 url += self .getNamespace (self .analyzer .FullKindToNamespaceDict [fullKind ], namespace )
145144 url += self .analyzer .FullKindToNameDict [fullKind ] + "/" + name
146145
147- return createRequest (url = url , token = self .token , method = "GET" , keep_json = False , ** kwargs )
146+ return createRequest (url = url , token = self .token , method = "GET" , keep_json = False , config = self . config , ** kwargs )
148147
149148 def listResources (self , kind , namespace = "" , ** kwargs ) -> Union [dict , bool , str ]:
150149 fullKind , error_str = self .checkAndReturnRealKind (kind , self .analyzer .KindToFullKindDict )
@@ -155,7 +154,7 @@ def listResources(self, kind, namespace="", **kwargs) -> Union[dict, bool, str]:
155154 url += self .getNamespace (self .analyzer .FullKindToNamespaceDict [fullKind ], namespace )
156155 url += self .analyzer .FullKindToNameDict [fullKind ]
157156
158- return createRequest (url = url , token = self .token , method = "GET" , keep_json = False , ** kwargs )
157+ return createRequest (url = url , token = self .token , method = "GET" , keep_json = False , config = self . config , ** kwargs )
159158
160159 def bindResource (self , pod , host , ** kwargs ) -> Union [dict , bool , str ]:
161160 jsonObj = {}
@@ -181,7 +180,7 @@ def bindResource(self, pod, host, **kwargs) -> Union[dict, bool, str]:
181180 url += self .analyzer .FullKindToNameDict [kind ] + "/"
182181 url += pod ["metadata" ]["name" ] + "/binding"
183182
184- return createRequest (url = url , token = self .token , method = "POST" , data = jsonObj , keep_json = False , ** kwargs )
183+ return createRequest (url = url , token = self .token , method = "POST" , data = jsonObj , keep_json = False , config = self . config , ** kwargs )
185184
186185 def watchResource (self , kind , namespace , watcherhandler , name = None , thread_name = None , is_daemon = True ,
187186 ** kwargs ) -> KubernetesWatcher :
@@ -199,8 +198,8 @@ def watchResource(self, kind, namespace, watcherhandler, name=None, thread_name=
199198 url += self .analyzer .FullKindToNameDict [fullKind ] + "/" + name
200199 else :
201200 url += self .analyzer .FullKindToNameDict [fullKind ]
202-
203- thread_t = threading . Thread ( target = KubernetesClient . watching , args = (url , self .token , watcherhandler , kwargs ,),
201+ thread_t = threading . Thread ( target = KubernetesClient . watching ,
202+ args = (url , self .token , self . config , watcherhandler , kwargs ,),
204203 name = thread_name , daemon = is_daemon )
205204
206205 watcher = KubernetesWatcher (thread_t = thread_t , kind = kind , namespace = namespace , watcher_handler = watcherhandler ,
@@ -253,38 +252,25 @@ def watchResourcesBase(self, kind, namespace, handlerFunction, thread_name=None,
253252 isDaemon = is_daemon , ** kwargs )
254253
255254 @staticmethod
256- def watching (url , token , watchHandler , kwargs ):
257- if token is None :
258- header = {
259- "Accept" : "*/*" ,
260- "Accept-Encoding" : "gzip, deflate, br" ,
261- }
262- else :
263- header = {
264- "Accept" : "*/*" ,
265- "Authorization" : "Bearer " + token ,
266- "Accept-Encoding" : "gzip, deflate, br" ,
267- }
268-
269- with requests .get (url = formatURL (url , getParams (kwargs )), headers = header , verify = False , stream = True ) as response :
270- for json_bytes in response .iter_lines ():
271- if len (json_bytes ) < 1 :
272- continue
273-
274- jsonObj = jsonBytesToDict (json_bytes )
275- if "type" not in jsonObj .keys ():
276- print ("type is not found in keys while watching, dict is: " , jsonObj )
277- exit (- 3 )
278-
279- if jsonObj ["type" ] == "ADDED" :
280- watchHandler .DoAdded (jsonObj ["object" ])
281- elif jsonObj ["type" ] == "MODIFIED" :
282- watchHandler .DoModified (jsonObj ["object" ])
283- elif jsonObj ["type" ] == "DELETED" :
284- watchHandler .DoDeleted (jsonObj ["object" ])
285- else :
286- print ("unknow type while watching:" , jsonObj ["type" ])
287-
255+ def watching (url , token , config , watchHandler , kwargs ):
256+ response = createRequest (url = formatURL (url , getParams (kwargs )), token = token , method = "GET" , keep_json = False , config = config ,stream = True )[0 ]
257+ for json_bytes in response .iter_lines ():
258+ if len (json_bytes ) < 1 :
259+ continue
260+
261+ jsonObj = jsonBytesToDict (json_bytes )
262+ if "type" not in jsonObj .keys ():
263+ print ("type is not found in keys while watching, dict is: " , jsonObj )
264+ exit (- 3 )
265+
266+ if jsonObj ["type" ] == "ADDED" :
267+ watchHandler .DoAdded (jsonObj ["object" ])
268+ elif jsonObj ["type" ] == "MODIFIED" :
269+ watchHandler .DoModified (jsonObj ["object" ])
270+ elif jsonObj ["type" ] == "DELETED" :
271+ watchHandler .DoDeleted (jsonObj ["object" ])
272+ else :
273+ print ("unknow type while watching:" , jsonObj ["type" ])
288274 KubernetesClient .removeWatcher (thread_name = threading .currentThread ().getName ())
289275
290276 @staticmethod
@@ -326,7 +312,7 @@ def updateResourceStatus(self, jsonStr, **kwargs) -> Union[dict, bool, str]:
326312 url += self .analyzer .FullKindToNameDict [kind ] + "/" + jsonObj ["metadata" ]["name" ]
327313 url += "/status"
328314
329- return createRequest (url = url , token = self .token , method = "PUT" , body = jsonObj , keep_json = False , ** kwargs )
315+ return createRequest (url = url , token = self .token , method = "PUT" , body = jsonObj , keep_json = False ,config = self . config , ** kwargs )
330316
331317 def listResourcesWithLabelSelector (self , kind , namespace , labels ) -> Union [dict , bool , str ]:
332318 fullKind , error_str = self .checkAndReturnRealKind (kind , self .analyzer .KindToFullKindDict )
@@ -341,7 +327,7 @@ def listResourcesWithLabelSelector(self, kind, namespace, labels) -> Union[dict,
341327 for key , value in labels .items ():
342328 url += key + "%3D" + value + ","
343329 url = url [:len (url ) - 1 ]
344- return createRequest (url = url , token = self .token , method = "GET" , keep_json = False )
330+ return createRequest (url = url , token = self .token , method = "GET" , keep_json = False , config = self . config )
345331
346332 def listResourcesWithFieldSelector (self , kind , namespace , fields ) -> Union [dict , bool , str ]:
347333 fullKind , error_str = self .checkAndReturnRealKind (kind , self .analyzer .KindToFullKindDict )
@@ -357,7 +343,7 @@ def listResourcesWithFieldSelector(self, kind, namespace, fields) -> Union[dict,
357343 url += key + "%3D" + value + ","
358344
359345 url = url [:len (url ) - 1 ]
360- return createRequest (url = url , token = self .token , method = "GET" , keep_json = False )
346+ return createRequest (url = url , token = self .token , method = "GET" , keep_json = False , config = self . config )
361347
362348 def getKinds (self ) -> list :
363349 return list (self .analyzer .KindToFullKindDict .keys ())
0 commit comments