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 [];
}
const services = routeList
const services = await Promise.all(routeList
.filter(
(route) =>
route.metadata.annotations &&
@ -194,11 +194,11 @@ export async function servicesFromKubernetes() {
route.metadata.annotations[`${ANNOTATION_BASE}/instance`] === instanceName ||
`${ANNOTATION_BASE}/instance.${instanceName}` in route.metadata.annotations),
)
.map((route) => {
.map( async (route) => {
let constructedService = {
app: route.metadata.annotations[`${ANNOTATION_BASE}/app`] || route.metadata.name,
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,
group: route.metadata.annotations[`${ANNOTATION_BASE}/group`] || "Kubernetes",
weight: route.metadata.annotations[`${ANNOTATION_BASE}/weight`] || "0",
@ -207,7 +207,6 @@ export async function servicesFromKubernetes() {
external: false,
type: "service",
};
console.log("href is ",constructedService.href);
if (route.metadata.annotations[`${ANNOTATION_BASE}/external`]) {
constructedService.external =
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.debug(e);
}
console.log(constructedService)
return constructedService;
});
})
);
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 urlPath = ingress.spec.rules[0].matches[0].path.value;
//const urlSchema = await getSchemaFromGateway(ingress.spec.parentRefs[0]) ? "https" : "http";
const urlSchema = "https"
const urlSchema = await getSchemaFromGateway(ingress.spec.parentRefs[0]) ? "https" : "http";
// const urlSchema = "https"
return `${urlSchema}://${urlHost}${urlPath}`;
}
@ -162,7 +162,7 @@ export async function getRouteList(){
return routeList;
}
export function getUrlSchema(route) {
export async function getUrlSchema(route) {
let urlSchema;
switch (routingType) {
@ -170,7 +170,7 @@ export function getUrlSchema(route) {
urlSchema = getUrlFromIngress(route);
break;
case "gateway":
urlSchema = getUrlFromHttpRoute(route);
urlSchema = await getUrlFromHttpRoute(route);
break;
default:
urlSchema = getUrlFromIngress(route);