Skip to content

Commit

Permalink
fix: Returns all HTTPRoute of a namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur-leclerc authored Mar 2, 2025
1 parent d55a5e5 commit 038c0d7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/utils/kubernetes/httproute-list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CustomObjectsApi, CoreV1Api } from "@kubernetes/client-node";
import { CoreV1Api, CustomObjectsApi } from "@kubernetes/client-node";

import { getKubernetes, getKubeConfig, HTTPROUTE_API_GROUP, HTTPROUTE_API_VERSION } from "utils/config/kubernetes";
import { getKubeConfig, getKubernetes, HTTPROUTE_API_GROUP, HTTPROUTE_API_VERSION } from "utils/config/kubernetes";
import createLogger from "utils/logger";

const logger = createLogger("httproute-list");
Expand All @@ -14,7 +14,7 @@ export default async function listHttpRoute() {

if (gateway) {
// httproutes
const getHttpRoute = async (namespace) =>
const getHttpRoutes = async (namespace) =>
crd
.listNamespacedCustomObject({
group: HTTPROUTE_API_GROUP,
Expand All @@ -23,8 +23,7 @@ export default async function listHttpRoute() {
plural: "httproutes",
})
.then((response) => {
const [httpRoute] = response.items;
return httpRoute;
return response.items;
})
.catch((error) => {
logger.error("Error getting httproutes: %d %s %s", error.statusCode, error.body, error.response);
Expand All @@ -44,12 +43,14 @@ export default async function listHttpRoute() {
if (namespaces) {
const httpRouteListUnfiltered = await Promise.all(
namespaces.map(async (namespace) => {
const httpRoute = await getHttpRoute(namespace);
return httpRoute;
const httpRoutes = await getHttpRoutes(namespace);
return httpRoutes;
}),
);

httpRouteList = httpRouteListUnfiltered.filter((httpRoute) => httpRoute !== undefined);
httpRouteList = httpRouteListUnfiltered
.flat()
.filter((httpRoute) => httpRoute !== undefined);
}
}
return httpRouteList;
Expand Down

0 comments on commit 038c0d7

Please sign in to comment.