66from kubesys .common import getLastIndex , dictToJsonString , jsonStringToBytes , getParams , formatURL
77from kubesys .http_request import createRequest ,doCreateRequest
88from kubesys .analyzer import KubernetesAnalyzer
9- from kubesys .exceptions import WatchException
9+ from kubesys .exceptions import WatchException , HTTPError
1010import requests
11- from requests .models import HTTPError ,Response
1211import json
1312from kubesys .common import jsonBytesToDict
1413import threading
@@ -75,7 +74,7 @@ def getRealKind(self, kind, apiVersion) -> str:
7574 else :
7675 return apiVersion [:index ] + "." + kind
7776
78- def createResource (self , jsonStr , ** kwargs ) -> Response :
77+ def createResource (self , jsonStr , ** kwargs ) -> dict :
7978 jsonObj = jsonStr
8079 if type (jsonObj ) is str :
8180 jsonObj = json .loads (jsonObj )
@@ -91,7 +90,7 @@ def createResource(self, jsonStr, **kwargs) -> Response:
9190 url += self .analyzer .FullKindToNameDict [kind ]
9291 return createRequest (url = url , token = self .token , method = "POST" , body = jsonStr ,keep_json = False , config = self .config , ** kwargs )
9392
94- def updateResource (self , jsonStr :Union [str ,dict ], ** kwargs ) -> Response :
93+ def updateResource (self , jsonStr :Union [str ,dict ], ** kwargs ) -> dict :
9594 jsonObj = jsonStr
9695 if type (jsonObj ) is str :
9796 jsonObj = json .loads (jsonObj )
@@ -128,15 +127,15 @@ def updateResource(self, jsonStr:Union[str,dict], **kwargs) -> Response:
128127 #
129128 # return kind
130129
131- def deleteResource (self , kind , namespace , name , ** kwargs ) -> Response :
130+ def deleteResource (self , kind , namespace , name , ** kwargs ) -> dict :
132131 fullKind = self .analyzer .checkAndReturnRealKind (kind )
133132 url = self .analyzer .FullKindToApiPrefixDict [fullKind ] + "/"
134133 url += self .getNamespace (self .analyzer .FullKindToNamespaceDict [fullKind ], namespace )
135134 url += self .analyzer .FullKindToNameDict [fullKind ] + "/" + name
136135
137136 return createRequest (url = url , token = self .token , method = "DELETE" , keep_json = False ,config = self .config , ** kwargs )
138137
139- def getResource (self , kind , name , namespace = "" , ** kwargs ) -> Response :
138+ def getResource (self , kind , name , namespace = "" , ** kwargs ) -> dict :
140139 fullKind = self .analyzer .checkAndReturnRealKind (kind )
141140
142141 url = self .analyzer .FullKindToApiPrefixDict [fullKind ] + "/"
@@ -145,7 +144,7 @@ def getResource(self, kind, name, namespace="", **kwargs) -> Response:
145144
146145 return createRequest (url = url , token = self .token , method = "GET" , keep_json = False , config = self .config ,** kwargs )
147146
148- def listResources (self , kind , namespace = "" , ** kwargs ) -> Response :
147+ def listResources (self , kind , namespace = "" , ** kwargs ) -> dict :
149148 fullKind = self .analyzer .checkAndReturnRealKind (kind )
150149
151150 url = self .analyzer .FullKindToApiPrefixDict [fullKind ] + "/"
@@ -154,7 +153,7 @@ def listResources(self, kind, namespace="", **kwargs) -> Response:
154153
155154 return createRequest (url = url , token = self .token , method = "GET" , keep_json = False , config = self .config ,** kwargs )
156155
157- def bindResource (self , pod , host , ** kwargs ) -> Response :
156+ def bindResource (self , pod , host , ** kwargs ) -> dict :
158157 jsonObj = {}
159158 jsonObj ["apiVersion" ] = "v1"
160159 jsonObj ["kind" ] = "Binding"
@@ -213,7 +212,7 @@ def watchResources(self, kind, namespace, watcherhandler, thread_name=None, is_d
213212 isDaemon = is_daemon , ** kwargs )
214213
215214 def watchResourceBase (self , kind , namespace , handlerFunction , name = None , thread_name = None , is_daemon = True ,
216- ** kwargs ) -> Union [ KubernetesWatcher , Response ] :
215+ ** kwargs ) -> KubernetesWatcher :
217216 '''
218217 if is_daemon is True, when the main thread leave, this thead will leave automatically.
219218 '''
@@ -288,7 +287,7 @@ def watchingBase(url, token, handlerFunction, kwargs):
288287
289288 del KubernetesClient .watcher_threads [threading .currentThread ().getName ()]
290289
291- def updateResourceStatus (self , jsonStr , ** kwargs ) -> Response :
290+ def updateResourceStatus (self , jsonStr , ** kwargs ) -> dict :
292291 jsonObj = jsonStr
293292 if type (jsonObj ) is str :
294293 jsonObj = json .loads (jsonObj )
@@ -305,7 +304,7 @@ def updateResourceStatus(self, jsonStr, **kwargs) -> Response:
305304
306305 return createRequest (url = url , token = self .token , method = "PUT" , body = jsonObj , keep_json = False ,config = self .config , ** kwargs )
307306
308- def listResourcesWithLabelSelector (self , kind , namespace , labels ) -> Response :
307+ def listResourcesWithLabelSelector (self , kind , namespace , labels ) -> dict :
309308 fullKind = self .analyzer .checkAndReturnRealKind (kind )
310309
311310 url = self .analyzer .FullKindToApiPrefixDict [fullKind ] + "/"
@@ -317,7 +316,7 @@ def listResourcesWithLabelSelector(self, kind, namespace, labels) -> Response:
317316 url = url [:len (url ) - 1 ]
318317 return createRequest (url = url , token = self .token , method = "GET" , keep_json = False ,config = self .config )
319318
320- def listResourcesWithFieldSelector (self , kind , namespace , fields ) -> Response :
319+ def listResourcesWithFieldSelector (self , kind , namespace , fields ) -> dict :
321320 fullKind = self .analyzer .checkAndReturnRealKind (kind )
322321
323322 url = self .analyzer .FullKindToApiPrefixDict [fullKind ] + "/"
0 commit comments