Applied ESLint rules to code. Plus minor rewrite.

This commit is contained in:
djeinstine 2024-11-11 09:29:47 +00:00
parent 60eee26ac4
commit ac997ea841

View File

@ -73,8 +73,28 @@ function getUrlFromIngress(ingress) {
} }
async function getHttpRouteList() { async function getHttpRouteList() {
const httpRouteList = [];
// httproutes
const getHttpRoute = (async (namespace) =>
crd
.listNamespacedCustomObject(
apiGroup,
version,
namespace,
"httproutes"
)
.then((response) => {
const [httpRoute] = response.body.items;
return httpRoute;
})
.catch((error) => {
logger.error("Error getting httproutes: %d %s %s", error.statusCode, error.body, error.response);
logger.debug(error);
return null;
})
)
// namespaces
const namespaces = await core const namespaces = await core
.listNamespace() .listNamespace()
.then((response) => response.body.items.map((ns) => ns.metadata.name)) .then((response) => response.body.items.map((ns) => ns.metadata.name))
@ -84,19 +104,20 @@ async function getHttpRouteList() {
return null; return null;
}); });
let httpRouteList = [];
if (namespaces) { if (namespaces) {
// Iterate over each namespace
for (const namespace of namespaces) { const httpRouteListUnfiltered = await Promise.all(
try { namespaces
// Fetch the httproute from one namespaces .map( async(namespace) => {
const httpRoute = await crd.listNamespacedCustomObject(apiGroup, version, namespace, "httproutes"); const httpRoute = await getHttpRoute(namespace);
if (httpRoute.body.items.length !== 0) { return httpRoute;
httpRouteList.push(httpRoute.body.items[0]); })
} )
} catch (err) {
console.error(`Error fetching httproutes objects in namespace "${namespace}":`, err.body || err.message); httpRouteList = httpRouteListUnfiltered
} .filter((httpRoute) => httpRoute !== undefined)
}
} }
return httpRouteList; return httpRouteList;
} }