getUrlSchema now uses async call

This commit is contained in:
djeinstine 2024-11-08 14:23:57 +00:00
parent 29993dad3a
commit 9367fd761b
2 changed files with 10 additions and 11 deletions

View File

@ -185,7 +185,7 @@ export async function servicesFromKubernetes() {
return []; return [];
} }
const services = routeList const services = await Promise.all(routeList
.filter( .filter(
(route) => (route) =>
route.metadata.annotations && route.metadata.annotations &&
@ -194,11 +194,11 @@ export async function servicesFromKubernetes() {
route.metadata.annotations[`${ANNOTATION_BASE}/instance`] === instanceName || route.metadata.annotations[`${ANNOTATION_BASE}/instance`] === instanceName ||
`${ANNOTATION_BASE}/instance.${instanceName}` in route.metadata.annotations), `${ANNOTATION_BASE}/instance.${instanceName}` in route.metadata.annotations),
) )
.map((route) => { .map( async (route) => {
let constructedService = { let constructedService = {
app: route.metadata.annotations[`${ANNOTATION_BASE}/app`] || route.metadata.name, app: route.metadata.annotations[`${ANNOTATION_BASE}/app`] || route.metadata.name,
namespace: route.metadata.namespace, namespace: route.metadata.namespace,
href: route.metadata.annotations[`${ANNOTATION_BASE}/href`] || getUrlSchema(route), href: route.metadata.annotations[`${ANNOTATION_BASE}/href`] || await getUrlSchema(route),
name: route.metadata.annotations[`${ANNOTATION_BASE}/name`] || route.metadata.name, name: route.metadata.annotations[`${ANNOTATION_BASE}/name`] || route.metadata.name,
group: route.metadata.annotations[`${ANNOTATION_BASE}/group`] || "Kubernetes", group: route.metadata.annotations[`${ANNOTATION_BASE}/group`] || "Kubernetes",
weight: route.metadata.annotations[`${ANNOTATION_BASE}/weight`] || "0", weight: route.metadata.annotations[`${ANNOTATION_BASE}/weight`] || "0",
@ -207,7 +207,6 @@ export async function servicesFromKubernetes() {
external: false, external: false,
type: "service", type: "service",
}; };
console.log("href is ",constructedService.href);
if (route.metadata.annotations[`${ANNOTATION_BASE}/external`]) { if (route.metadata.annotations[`${ANNOTATION_BASE}/external`]) {
constructedService.external = constructedService.external =
String(route.metadata.annotations[`${ANNOTATION_BASE}/external`]).toLowerCase() === "true"; String(route.metadata.annotations[`${ANNOTATION_BASE}/external`]).toLowerCase() === "true";
@ -240,9 +239,9 @@ export async function servicesFromKubernetes() {
logger.error("Error attempting k8s environment variable substitution."); logger.error("Error attempting k8s environment variable substitution.");
logger.debug(e); logger.debug(e);
} }
console.log(constructedService)
return constructedService; return constructedService;
}); })
);
const mappedServiceGroups = []; const mappedServiceGroups = [];

View File

@ -25,11 +25,11 @@ const getSchemaFromGateway = async (gatewayRef) => {
} }
}; };
function getUrlFromHttpRoute(ingress) { async function getUrlFromHttpRoute(ingress) {
const urlHost = ingress.spec.hostnames[0]; const urlHost = ingress.spec.hostnames[0];
const urlPath = ingress.spec.rules[0].matches[0].path.value; const urlPath = ingress.spec.rules[0].matches[0].path.value;
//const urlSchema = await getSchemaFromGateway(ingress.spec.parentRefs[0]) ? "https" : "http"; const urlSchema = await getSchemaFromGateway(ingress.spec.parentRefs[0]) ? "https" : "http";
const urlSchema = "https" // const urlSchema = "https"
return `${urlSchema}://${urlHost}${urlPath}`; return `${urlSchema}://${urlHost}${urlPath}`;
} }
@ -162,7 +162,7 @@ export async function getRouteList(){
return routeList; return routeList;
} }
export function getUrlSchema(route) { export async function getUrlSchema(route) {
let urlSchema; let urlSchema;
switch (routingType) { switch (routingType) {
@ -170,7 +170,7 @@ export function getUrlSchema(route) {
urlSchema = getUrlFromIngress(route); urlSchema = getUrlFromIngress(route);
break; break;
case "gateway": case "gateway":
urlSchema = getUrlFromHttpRoute(route); urlSchema = await getUrlFromHttpRoute(route);
break; break;
default: default:
urlSchema = getUrlFromIngress(route); urlSchema = getUrlFromIngress(route);