Applied prettier to code
This commit is contained in:
parent
cb2c7b9147
commit
bbb1ef5a55
@ -7,10 +7,9 @@ import { KubeConfig } from "@kubernetes/client-node";
|
||||
import checkAndCopyConfig, { CONF_DIR, substituteEnvironmentVars } from "utils/config/config";
|
||||
|
||||
const extractKubeData = (config) => {
|
||||
|
||||
//kubeconfig
|
||||
const kc = new KubeConfig();
|
||||
kc.loadFromCluster()
|
||||
kc.loadFromCluster();
|
||||
|
||||
//route
|
||||
let route = "ingress";
|
||||
@ -31,12 +30,8 @@ const extractKubeData = (config) => {
|
||||
}
|
||||
|
||||
//return
|
||||
return {"config":kc,
|
||||
"route":route,
|
||||
"traefik":traefik,
|
||||
"metrics":metrics
|
||||
return { config: kc, route: route, traefik: traefik, metrics: metrics };
|
||||
};
|
||||
}
|
||||
|
||||
export default function getKubeArguments() {
|
||||
checkAndCopyConfig("kubernetes.yaml");
|
||||
|
||||
@ -165,7 +165,8 @@ export async function servicesFromKubernetes() {
|
||||
return [];
|
||||
}
|
||||
|
||||
const services = await Promise.all(routeList
|
||||
const services = await Promise.all(
|
||||
routeList
|
||||
.filter(
|
||||
(route) =>
|
||||
route.metadata.annotations &&
|
||||
@ -178,7 +179,7 @@ export async function servicesFromKubernetes() {
|
||||
let constructedService = {
|
||||
app: route.metadata.annotations[`${ANNOTATION_BASE}/app`] || route.metadata.name,
|
||||
namespace: route.metadata.namespace,
|
||||
href: route.metadata.annotations[`${ANNOTATION_BASE}/href`] || await 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",
|
||||
@ -220,7 +221,7 @@ export async function servicesFromKubernetes() {
|
||||
logger.debug(e);
|
||||
}
|
||||
return constructedService;
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
const mappedServiceGroups = [];
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
import { CustomObjectsApi, NetworkingV1Api, CoreV1Api, ApiextensionsV1Api } from "@kubernetes/client-node";
|
||||
import getKubeArguments from "utils/config/kubernetes";
|
||||
import createLogger from "utils/logger";
|
||||
@ -9,8 +7,8 @@ const logger = createLogger("service-helpers");
|
||||
const kubeArguments = getKubeArguments();
|
||||
const kc = kubeArguments.config;
|
||||
|
||||
const apiGroup = 'gateway.networking.k8s.io';
|
||||
const version = 'v1';
|
||||
const apiGroup = "gateway.networking.k8s.io";
|
||||
const version = "v1";
|
||||
|
||||
let crd;
|
||||
let core;
|
||||
@ -18,7 +16,6 @@ let networking;
|
||||
let routingType;
|
||||
let traefik;
|
||||
|
||||
|
||||
export async function checkCRD(kc, name) {
|
||||
const apiExtensions = kc.makeApiClient(ApiextensionsV1Api);
|
||||
const exist = await apiExtensions
|
||||
@ -41,7 +38,13 @@ export async function checkCRD(kc, name) {
|
||||
|
||||
const getSchemaFromGateway = async (gatewayRef) => {
|
||||
try {
|
||||
const gateway = await crd.getNamespacedCustomObject(apiGroup, version, gatewayRef.namespace,"gateways",gatewayRef.name);
|
||||
const gateway = await crd.getNamespacedCustomObject(
|
||||
apiGroup,
|
||||
version,
|
||||
gatewayRef.namespace,
|
||||
"gateways",
|
||||
gatewayRef.name,
|
||||
);
|
||||
const listener = gateway.body.spec.listeners.filter((listener) => listener.name == gatewayRef.sectionName)[0];
|
||||
return listener.protocol.toLowerCase();
|
||||
} catch (err) {
|
||||
@ -52,12 +55,11 @@ const getSchemaFromGateway = async (gatewayRef) => {
|
||||
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 = (await getSchemaFromGateway(ingress.spec.parentRefs[0])) ? "https" : "http";
|
||||
// const urlSchema = "https"
|
||||
return `${urlSchema}://${urlHost}${urlPath}`;
|
||||
}
|
||||
|
||||
|
||||
function getUrlFromIngress(ingress) {
|
||||
const urlHost = ingress.spec.rules[0].host;
|
||||
const urlPath = ingress.spec.rules[0].http.paths[0].path;
|
||||
@ -68,24 +70,24 @@ function getUrlFromIngress(ingress) {
|
||||
async function getHttpRouteList() {
|
||||
const httpRouteList = new Array();
|
||||
|
||||
const namespaces = await core.listNamespace()
|
||||
.then((response) => response.body.items.map(ns => ns.metadata.name))
|
||||
const namespaces = await core
|
||||
.listNamespace()
|
||||
.then((response) => response.body.items.map((ns) => ns.metadata.name))
|
||||
.catch((error) => {
|
||||
logger.error("Error getting namespaces: %d %s %s", error.statusCode, error.body, error.response);
|
||||
logger.debug(error);
|
||||
return null;
|
||||
})
|
||||
});
|
||||
|
||||
if (namespaces) {
|
||||
// Iterate over each namespace
|
||||
for (const namespace of namespaces) {
|
||||
try {
|
||||
// Fetch the httproute from one namespaces
|
||||
const httpRoute = await crd.listNamespacedCustomObject(apiGroup,version,namespace,'httproutes');
|
||||
const httpRoute = await crd.listNamespacedCustomObject(apiGroup, version, namespace, "httproutes");
|
||||
if (httpRoute.body.items.length !== 0) {
|
||||
httpRouteList.push(httpRoute.body.items[0]);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.error(`Error fetching httproutes objects in namespace "${namespace}":`, err.body || err.message);
|
||||
}
|
||||
@ -95,7 +97,6 @@ async function getHttpRouteList(){
|
||||
}
|
||||
|
||||
async function getIngressList() {
|
||||
|
||||
const ingressList = await networking
|
||||
.listIngressForAllNamespaces(null, null, null, null)
|
||||
.then((response) => response.body)
|
||||
@ -157,7 +158,6 @@ async function getIngressList(){
|
||||
}
|
||||
|
||||
export async function getRouteList() {
|
||||
|
||||
let routeList = new Array();
|
||||
|
||||
if (!kc) {
|
||||
@ -171,7 +171,6 @@ export async function getRouteList(){
|
||||
routingType = kubeArguments.route;
|
||||
traefik = kubeArguments.traefik;
|
||||
|
||||
|
||||
switch (routingType) {
|
||||
case "ingress":
|
||||
routeList = await getIngressList();
|
||||
@ -201,4 +200,3 @@ export async function getUrlSchema(route) {
|
||||
}
|
||||
return urlSchema;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user