Skip to content

Commit b710d1b

Browse files
committed
combine similar client sdk
1 parent 0e0e063 commit b710d1b

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

kubesys/client.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -304,30 +304,23 @@ def updateResourceStatus(self, jsonStr, **kwargs) -> dict:
304304

305305
return createRequest(url=url, token=self.token, method="PUT", body=jsonObj, keep_json=False,config=self.config, **kwargs)
306306

307-
def listResourcesWithLabelSelector(self, kind, namespace, labels) -> dict:
307+
def listResourcesWithSelector(self, kind, namespace, tp,selects) -> dict:
308308
fullKind = self.analyzer.checkAndReturnRealKind(kind)
309309

310310
url = self.analyzer.FullKindToApiPrefixDict[fullKind] + "/"
311311
url += self.getNamespace(self.analyzer.FullKindToNamespaceDict[fullKind], namespace)
312312
url += self.analyzer.FullKindToNameDict[fullKind]
313-
url += "?labelSelector="
314-
for key, value in labels.items():
315-
url += key + "%3D" + value + ","
313+
if tp=='label':
314+
url += "?labelSelector="
315+
elif tp=='field':
316+
url += "?fieldSelector="
317+
else:
318+
raise HTTPError(404,f"selector type {tp} should either be label or field")
319+
for key, value in selects.items():
320+
url += key + "%3D=" + value + ","
316321
url = url[:len(url) - 1]
317322
return createRequest(url=url, token=self.token, method="GET", keep_json=False,config=self.config)
318323

319-
def listResourcesWithFieldSelector(self, kind, namespace, fields) -> dict:
320-
fullKind = self.analyzer.checkAndReturnRealKind(kind)
321-
322-
url = self.analyzer.FullKindToApiPrefixDict[fullKind] + "/"
323-
url += self.getNamespace(self.analyzer.FullKindToNamespaceDict[fullKind], namespace)
324-
url += self.analyzer.FullKindToNameDict[fullKind]
325-
url += "?fieldSelector="
326-
for key, value in fields.items():
327-
url += key + "%3D" + value + ","
328-
329-
url = url[:len(url) - 1]
330-
return createRequest(url=url, token=self.token, method="GET", keep_json=False,config=self.config)
331324

332325
def getKinds(self) -> list:
333326
return list(self.analyzer.KindToFullKindDict.keys())

0 commit comments

Comments
 (0)