Skip to content

Commit 34df7c9

Browse files
committed
add json transform stuff
1 parent 079633f commit 34df7c9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

kubesys/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def createResource(self, jsonStr, **kwargs) -> dict:
9090
jsonObj = jsonStr
9191
if type(jsonObj) is str:
9292
jsonObj = json.loads(jsonObj)
93+
elif type(jsonObj) is dict:
94+
jsonStr=dictToJsonString(jsonStr)
9395

9496
kind = self.getRealKind(str(jsonObj["kind"]), str(jsonObj["apiVersion"]))
9597

@@ -106,6 +108,8 @@ def updateResource(self, jsonStr:Union[str,dict], **kwargs) -> dict:
106108
jsonObj = jsonStr
107109
if type(jsonObj) is str:
108110
jsonObj = json.loads(jsonObj)
111+
elif type(jsonObj) is dict:
112+
jsonStr=dictToJsonString(jsonStr)
109113

110114
kind = self.getRealKind(str(jsonObj["kind"]), str(jsonObj["apiVersion"]))
111115

@@ -303,6 +307,8 @@ def updateResourceStatus(self, jsonStr, **kwargs) -> dict:
303307
jsonObj = jsonStr
304308
if type(jsonObj) is str:
305309
jsonObj = json.loads(jsonObj)
310+
elif type(jsonObj) is dict:
311+
jsonStr=dictToJsonString(jsonStr)
306312

307313
kind = self.getRealKind(jsonObj["kind"], jsonObj["apiVersion"])
308314
namespace = ""
@@ -314,7 +320,7 @@ def updateResourceStatus(self, jsonStr, **kwargs) -> dict:
314320
url += self.analyzer.FullKindToNameDict[kind] + "/" + jsonObj["metadata"]["name"]
315321
url += "/status"
316322

317-
return createRequest(url=url, token=self.token, method="PUT", body=jsonObj, keep_json=False,config=self.config, **kwargs)
323+
return createRequest(url=url, token=self.token, method="PUT", body=jsonStr, keep_json=False,config=self.config, **kwargs)
318324

319325
def getResourceStatus(self,kind, name, namespace="", **kwargs)->dict:
320326
fullKind = self.analyzer.checkAndReturnRealKind(kind)

kubesys/http_request.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def createRequest(url, token, method="GET", body=None, verify=False,
3232
formatURL(url, getParams(kwargs)), token, method, body, config)
3333
try:
3434
result = response.json()
35+
if result.get('kind') == 'Status':
36+
raise HTTPError(result.get('code'),result.get('reason')+' '+result.get('message'))
3537
if keep_json:
3638
result=dictToJsonString(result)
3739
return result

0 commit comments

Comments
 (0)