mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-07 09:35:54 -08:00
Code style lint
This commit is contained in:
@@ -25,15 +25,16 @@ To configure Kubernetes gateway-api, ingress or ingressRoute service discovery,
|
||||
Example settings:
|
||||
|
||||
```yaml
|
||||
ingress: true # enable ingress only
|
||||
```
|
||||
or
|
||||
```yaml
|
||||
ingress: true # enable ingress
|
||||
traefik: true # enable traefik ingressRoute
|
||||
gateway: true # enable gateway-api
|
||||
ingress: true # enable ingress only
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```yaml
|
||||
ingress: true # enable ingress
|
||||
traefik: true # enable traefik ingressRoute
|
||||
gateway: true # enable gateway-api
|
||||
```
|
||||
|
||||
## Services
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CoreV1Api, Metrics } from "@kubernetes/client-node";
|
||||
|
||||
import {getKubeConfig} from "../../../../utils/config/kubernetes";
|
||||
import { getKubeConfig } from "../../../../utils/config/kubernetes";
|
||||
import { parseCpu, parseMemory } from "../../../../utils/kubernetes/utils";
|
||||
import createLogger from "../../../../utils/logger";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CoreV1Api } from "@kubernetes/client-node";
|
||||
|
||||
import {getKubeConfig} from "../../../../utils/config/kubernetes";
|
||||
import { getKubeConfig } from "../../../../utils/config/kubernetes";
|
||||
import createLogger from "../../../../utils/logger";
|
||||
|
||||
const logger = createLogger("kubernetesStatusService");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CoreV1Api, Metrics } from "@kubernetes/client-node";
|
||||
|
||||
import {getKubeConfig} from "../../../utils/config/kubernetes";
|
||||
import { getKubeConfig } from "../../../utils/config/kubernetes";
|
||||
import { parseCpu, parseMemory } from "../../../utils/kubernetes/utils";
|
||||
import createLogger from "../../../utils/logger";
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import path from "path";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
import yaml from "js-yaml";
|
||||
import { KubeConfig,ApiextensionsV1Api } from "@kubernetes/client-node";
|
||||
import { KubeConfig, ApiextensionsV1Api } from "@kubernetes/client-node";
|
||||
|
||||
import checkAndCopyConfig, { CONF_DIR, substituteEnvironmentVars } from "utils/config/config";
|
||||
|
||||
@@ -16,7 +16,7 @@ export default function getKubernetes() {
|
||||
|
||||
export const getKubeConfig = () => {
|
||||
const kc = new KubeConfig();
|
||||
const config = getKubernetes()
|
||||
const config = getKubernetes();
|
||||
|
||||
switch (config?.mode) {
|
||||
case "cluster":
|
||||
@@ -30,10 +30,10 @@ export const getKubeConfig = () => {
|
||||
return null;
|
||||
}
|
||||
|
||||
return kc
|
||||
return kc;
|
||||
};
|
||||
|
||||
export async function checkCRD(name,kc,logger) {
|
||||
export async function checkCRD(name, kc, logger) {
|
||||
const apiExtensions = kc.makeApiClient(ApiextensionsV1Api);
|
||||
const exist = await apiExtensions
|
||||
.readCustomResourceDefinitionStatus(name)
|
||||
@@ -56,4 +56,4 @@ export async function checkCRD(name,kc,logger) {
|
||||
export const ANNOTATION_BASE = "gethomepage.dev";
|
||||
export const ANNOTATION_WIDGET_BASE = `${ANNOTATION_BASE}/widget.`;
|
||||
export const HTTPROUTE_API_GROUP = "gateway.networking.k8s.io";
|
||||
export const HTTPROUTE_API_VERSION = "v1";
|
||||
export const HTTPROUTE_API_VERSION = "v1";
|
||||
|
||||
@@ -8,7 +8,7 @@ import createLogger from "utils/logger";
|
||||
import checkAndCopyConfig, { CONF_DIR, getSettings, substituteEnvironmentVars } from "utils/config/config";
|
||||
import getDockerArguments from "utils/config/docker";
|
||||
import kubernetes from "utils/kubernetes/export";
|
||||
import {getKubeConfig} from "utils/config/kubernetes";
|
||||
import { getKubeConfig } from "utils/config/kubernetes";
|
||||
import * as shvl from "utils/config/shvl";
|
||||
|
||||
const logger = createLogger("service-helpers");
|
||||
@@ -177,42 +177,44 @@ export async function servicesFromKubernetes() {
|
||||
if (!kc) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
// resource lists
|
||||
const [ingressList, traefikIngressList, httpRouteList] = await Promise.all([
|
||||
kubernetes.listIngress(),
|
||||
kubernetes.listTraefikIngress(),
|
||||
kubernetes.listHttpRoute()
|
||||
kubernetes.listHttpRoute(),
|
||||
]);
|
||||
|
||||
const resources = [ ...ingressList, ...traefikIngressList, ...httpRouteList ];
|
||||
|
||||
const resources = [...ingressList, ...traefikIngressList, ...httpRouteList];
|
||||
|
||||
if (!resources) {
|
||||
return [];
|
||||
}
|
||||
const services = await Promise.all( resources
|
||||
.filter(resource => kubernetes.isDiscoverable(resource, instanceName))
|
||||
.map(async (resource) => kubernetes.constructedServiceFromResource(resource)));
|
||||
const services = await Promise.all(
|
||||
resources
|
||||
.filter((resource) => kubernetes.isDiscoverable(resource, instanceName))
|
||||
.map(async (resource) => kubernetes.constructedServiceFromResource(resource)),
|
||||
);
|
||||
|
||||
// map service groups
|
||||
const mappedServiceGroups = services.reduce((groups, serverService) => {
|
||||
let serverGroup = groups.find(group => group.name === serverService.group);
|
||||
|
||||
let serverGroup = groups.find((group) => group.name === serverService.group);
|
||||
|
||||
if (!serverGroup) {
|
||||
serverGroup = {
|
||||
name: serverService.group,
|
||||
services: []
|
||||
services: [],
|
||||
};
|
||||
groups.push(serverGroup);
|
||||
}
|
||||
|
||||
|
||||
const { name: serviceName, group: _, ...pushedService } = serverService;
|
||||
|
||||
|
||||
serverGroup.services.push({
|
||||
name: serviceName,
|
||||
...pushedService
|
||||
...pushedService,
|
||||
});
|
||||
|
||||
|
||||
return groups;
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import listIngress from "utils/kubernetes/ingress-list";
|
||||
import listTraefikIngress from "utils/kubernetes/traefik-list";
|
||||
import listHttpRoute from "utils/kubernetes/httproute-list";
|
||||
import { isDiscoverable,constructedServiceFromResource } from "utils/kubernetes/resource-helpers";
|
||||
import { isDiscoverable, constructedServiceFromResource } from "utils/kubernetes/resource-helpers";
|
||||
|
||||
const kubernetes = {
|
||||
listIngress,
|
||||
listTraefikIngress,
|
||||
listHttpRoute,
|
||||
isDiscoverable,
|
||||
constructedServiceFromResource
|
||||
listIngress,
|
||||
listTraefikIngress,
|
||||
listHttpRoute,
|
||||
isDiscoverable,
|
||||
constructedServiceFromResource,
|
||||
};
|
||||
|
||||
export default kubernetes;
|
||||
export default kubernetes;
|
||||
|
||||
@@ -1,54 +1,52 @@
|
||||
|
||||
import { CustomObjectsApi, CoreV1Api } from "@kubernetes/client-node";
|
||||
|
||||
import getKubernetes, {getKubeConfig,HTTPROUTE_API_GROUP,HTTPROUTE_API_VERSION} from "utils/config/kubernetes";
|
||||
import getKubernetes, { getKubeConfig, HTTPROUTE_API_GROUP, HTTPROUTE_API_VERSION } from "utils/config/kubernetes";
|
||||
import createLogger from "utils/logger";
|
||||
|
||||
const logger = createLogger("httproute-list");
|
||||
const kc = getKubeConfig();
|
||||
|
||||
export default async function listHttpRoute() {
|
||||
|
||||
const crd = kc.makeApiClient(CustomObjectsApi);
|
||||
const core = kc.makeApiClient(CoreV1Api);
|
||||
const { gateway } = getKubernetes();
|
||||
let httpRouteList = [];
|
||||
const crd = kc.makeApiClient(CustomObjectsApi);
|
||||
const core = kc.makeApiClient(CoreV1Api);
|
||||
const { gateway } = getKubernetes();
|
||||
let httpRouteList = [];
|
||||
|
||||
if (!!gateway) {
|
||||
// httproutes
|
||||
const getHttpRoute = async (namespace) =>
|
||||
crd
|
||||
.listNamespacedCustomObject(HTTPROUTE_API_GROUP, HTTPROUTE_API_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
|
||||
.listNamespace()
|
||||
.then((response) => response.body.items.map((ns) => ns.metadata.name))
|
||||
if (!!gateway) {
|
||||
// httproutes
|
||||
const getHttpRoute = async (namespace) =>
|
||||
crd
|
||||
.listNamespacedCustomObject(HTTPROUTE_API_GROUP, HTTPROUTE_API_VERSION, namespace, "httproutes")
|
||||
.then((response) => {
|
||||
const [httpRoute] = response.body.items;
|
||||
return httpRoute;
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error("Error getting namespaces: %d %s %s", error.statusCode, error.body, error.response);
|
||||
logger.error("Error getting httproutes: %d %s %s", error.statusCode, error.body, error.response);
|
||||
logger.debug(error);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (namespaces) {
|
||||
const httpRouteListUnfiltered = await Promise.all(
|
||||
namespaces.map(async (namespace) => {
|
||||
const httpRoute = await getHttpRoute(namespace);
|
||||
return httpRoute;
|
||||
}),
|
||||
);
|
||||
|
||||
httpRouteList = httpRouteListUnfiltered.filter((httpRoute) => httpRoute !== undefined);
|
||||
}
|
||||
|
||||
// namespaces
|
||||
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) {
|
||||
const httpRouteListUnfiltered = await Promise.all(
|
||||
namespaces.map(async (namespace) => {
|
||||
const httpRoute = await getHttpRoute(namespace);
|
||||
return httpRoute;
|
||||
}),
|
||||
);
|
||||
|
||||
httpRouteList = httpRouteListUnfiltered.filter((httpRoute) => httpRoute !== undefined);
|
||||
}
|
||||
}
|
||||
return httpRouteList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,26 @@
|
||||
import {NetworkingV1Api} from "@kubernetes/client-node";
|
||||
import { NetworkingV1Api } from "@kubernetes/client-node";
|
||||
|
||||
import getKubernetes, {getKubeConfig} from "utils/config/kubernetes";
|
||||
import getKubernetes, { getKubeConfig } from "utils/config/kubernetes";
|
||||
import createLogger from "utils/logger";
|
||||
|
||||
const logger = createLogger("ingress-list");
|
||||
const kc = getKubeConfig();
|
||||
|
||||
|
||||
export default async function listIngress() {
|
||||
const networking = kc.makeApiClient(NetworkingV1Api);
|
||||
const { ingress } = getKubernetes();
|
||||
let ingressList = [];
|
||||
|
||||
const networking = kc.makeApiClient(NetworkingV1Api);
|
||||
const { ingress } = getKubernetes();
|
||||
let ingressList = []
|
||||
|
||||
if (!!ingress){
|
||||
|
||||
const ingressData = await networking
|
||||
.listIngressForAllNamespaces(null, null, null, null)
|
||||
.then((response) => response.body)
|
||||
.catch((error) => {
|
||||
logger.error("Error getting ingresses: %d %s %s", error.statusCode, error.body, error.response);
|
||||
logger.debug(error);
|
||||
return null;
|
||||
});
|
||||
ingressList = ingressData.items;
|
||||
}
|
||||
return ingressList;
|
||||
}
|
||||
if (!!ingress) {
|
||||
const ingressData = await networking
|
||||
.listIngressForAllNamespaces(null, null, null, null)
|
||||
.then((response) => response.body)
|
||||
.catch((error) => {
|
||||
logger.error("Error getting ingresses: %d %s %s", error.statusCode, error.body, error.response);
|
||||
logger.debug(error);
|
||||
return null;
|
||||
});
|
||||
ingressList = ingressData.items;
|
||||
}
|
||||
return ingressList;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { CustomObjectsApi } from "@kubernetes/client-node";
|
||||
|
||||
import { getKubeConfig,ANNOTATION_BASE,ANNOTATION_WIDGET_BASE,HTTPROUTE_API_GROUP,HTTPROUTE_API_VERSION } from "utils/config/kubernetes";
|
||||
import {
|
||||
getKubeConfig,
|
||||
ANNOTATION_BASE,
|
||||
ANNOTATION_WIDGET_BASE,
|
||||
HTTPROUTE_API_GROUP,
|
||||
HTTPROUTE_API_VERSION,
|
||||
} from "utils/config/kubernetes";
|
||||
import { substituteEnvironmentVars } from "utils/config/config";
|
||||
import createLogger from "utils/logger";
|
||||
import * as shvl from "utils/config/shvl";
|
||||
@@ -9,110 +15,116 @@ const logger = createLogger("resource-helpers");
|
||||
const kc = getKubeConfig();
|
||||
|
||||
const getSchemaFromGateway = async (gatewayRef) => {
|
||||
const crd = kc.makeApiClient(CustomObjectsApi);
|
||||
const schema = await crd
|
||||
.getNamespacedCustomObject(HTTPROUTE_API_GROUP, HTTPROUTE_API_VERSION, gatewayRef.namespace, "gateways", gatewayRef.name)
|
||||
.then((response) => {
|
||||
const listner = response.body.spec.listeners.filter((listener) => listener.name === gatewayRef.sectionName)[0];
|
||||
return listner.protocol.toLowerCase();
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error("Error getting gateways: %d %s %s", error.statusCode, error.body, error.response);
|
||||
logger.debug(error);
|
||||
return "";
|
||||
});
|
||||
return schema;
|
||||
};
|
||||
|
||||
async function getUrlFromHttpRoute(resource) {
|
||||
let url = null;
|
||||
const hasHostName = resource.spec?.hostnames;
|
||||
|
||||
if (hasHostName) {
|
||||
if (resource.spec.rules[0].matches[0].path.type!=="RegularExpression"){
|
||||
const urlHost = resource.spec.hostnames[0];
|
||||
const urlPath = resource.spec.rules[0].matches[0].path.value;
|
||||
const urlSchema = (await getSchemaFromGateway(resource.spec.parentRefs[0])) ? "https" : "http";
|
||||
url = `${urlSchema}://${urlHost}${urlPath}`;
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
function getUrlFromIngress(resource) {
|
||||
const urlHost = resource.spec.rules[0].host;
|
||||
const urlPath = resource.spec.rules[0].http.paths[0].path;
|
||||
const urlSchema = resource.spec.tls ? "https" : "http";
|
||||
return `${urlSchema}://${urlHost}${urlPath}`;
|
||||
}
|
||||
|
||||
async function getUrlSchema(resource) {
|
||||
const isHttpRoute = resource.kind === "HTTPRoute";
|
||||
let urlSchema;
|
||||
if (isHttpRoute){
|
||||
urlSchema = getUrlFromHttpRoute(resource);
|
||||
}else{
|
||||
urlSchema = getUrlFromIngress(resource);
|
||||
}
|
||||
return urlSchema;
|
||||
}
|
||||
|
||||
export function isDiscoverable(resource,instanceName) {
|
||||
return resource.metadata.annotations &&
|
||||
resource.metadata.annotations[`${ANNOTATION_BASE}/enabled`] === "true" &&
|
||||
(!resource.metadata.annotations[`${ANNOTATION_BASE}/instance`] ||
|
||||
resource.metadata.annotations[`${ANNOTATION_BASE}/instance`] === instanceName ||
|
||||
`${ANNOTATION_BASE}/instance.${instanceName}` in resource.metadata.annotations)
|
||||
const crd = kc.makeApiClient(CustomObjectsApi);
|
||||
const schema = await crd
|
||||
.getNamespacedCustomObject(
|
||||
HTTPROUTE_API_GROUP,
|
||||
HTTPROUTE_API_VERSION,
|
||||
gatewayRef.namespace,
|
||||
"gateways",
|
||||
gatewayRef.name,
|
||||
)
|
||||
.then((response) => {
|
||||
const listner = response.body.spec.listeners.filter((listener) => listener.name === gatewayRef.sectionName)[0];
|
||||
return listner.protocol.toLowerCase();
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error("Error getting gateways: %d %s %s", error.statusCode, error.body, error.response);
|
||||
logger.debug(error);
|
||||
return "";
|
||||
});
|
||||
return schema;
|
||||
};
|
||||
|
||||
export async function constructedServiceFromResource (resource){
|
||||
let constructedService = {
|
||||
app: resource.metadata.annotations[`${ANNOTATION_BASE}/app`] || resource.metadata.name,
|
||||
namespace: resource.metadata.namespace,
|
||||
href: resource.metadata.annotations[`${ANNOTATION_BASE}/href`] || (await getUrlSchema(resource)),
|
||||
name: resource.metadata.annotations[`${ANNOTATION_BASE}/name`] || resource.metadata.name,
|
||||
group: resource.metadata.annotations[`${ANNOTATION_BASE}/group`] || "Kubernetes",
|
||||
weight: resource.metadata.annotations[`${ANNOTATION_BASE}/weight`] || "0",
|
||||
icon: resource.metadata.annotations[`${ANNOTATION_BASE}/icon`] || "",
|
||||
description: resource.metadata.annotations[`${ANNOTATION_BASE}/description`] || "",
|
||||
external: false,
|
||||
type: "service",
|
||||
};
|
||||
if (resource.metadata.annotations[`${ANNOTATION_BASE}/external`]) {
|
||||
constructedService.external =
|
||||
String(resource.metadata.annotations[`${ANNOTATION_BASE}/external`]).toLowerCase() === "true";
|
||||
}
|
||||
if (resource.metadata.annotations[`${ANNOTATION_BASE}/pod-selector`] !== undefined) {
|
||||
constructedService.podSelector = resource.metadata.annotations[`${ANNOTATION_BASE}/pod-selector`];
|
||||
}
|
||||
if (resource.metadata.annotations[`${ANNOTATION_BASE}/ping`]) {
|
||||
constructedService.ping = resource.metadata.annotations[`${ANNOTATION_BASE}/ping`];
|
||||
}
|
||||
if (resource.metadata.annotations[`${ANNOTATION_BASE}/siteMonitor`]) {
|
||||
constructedService.siteMonitor = resource.metadata.annotations[`${ANNOTATION_BASE}/siteMonitor`];
|
||||
}
|
||||
if (resource.metadata.annotations[`${ANNOTATION_BASE}/statusStyle`]) {
|
||||
constructedService.statusStyle = resource.metadata.annotations[`${ANNOTATION_BASE}/statusStyle`];
|
||||
}
|
||||
async function getUrlFromHttpRoute(resource) {
|
||||
let url = null;
|
||||
const hasHostName = resource.spec?.hostnames;
|
||||
|
||||
Object
|
||||
.keys(resource.metadata.annotations)
|
||||
.forEach((annotation) => {
|
||||
if (annotation.startsWith(ANNOTATION_WIDGET_BASE)) {
|
||||
shvl.set(
|
||||
constructedService,
|
||||
annotation.replace(`${ANNOTATION_BASE}/`, ""),
|
||||
resource.metadata.annotations[annotation],
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
constructedService = JSON.parse(substituteEnvironmentVars(JSON.stringify(constructedService)));
|
||||
} catch (e) {
|
||||
logger.error("Error attempting k8s environment variable substitution.");
|
||||
logger.debug(e);
|
||||
if (hasHostName) {
|
||||
if (resource.spec.rules[0].matches[0].path.type !== "RegularExpression") {
|
||||
const urlHost = resource.spec.hostnames[0];
|
||||
const urlPath = resource.spec.rules[0].matches[0].path.value;
|
||||
const urlSchema = (await getSchemaFromGateway(resource.spec.parentRefs[0])) ? "https" : "http";
|
||||
url = `${urlSchema}://${urlHost}${urlPath}`;
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
return constructedService;
|
||||
}
|
||||
function getUrlFromIngress(resource) {
|
||||
const urlHost = resource.spec.rules[0].host;
|
||||
const urlPath = resource.spec.rules[0].http.paths[0].path;
|
||||
const urlSchema = resource.spec.tls ? "https" : "http";
|
||||
return `${urlSchema}://${urlHost}${urlPath}`;
|
||||
}
|
||||
|
||||
async function getUrlSchema(resource) {
|
||||
const isHttpRoute = resource.kind === "HTTPRoute";
|
||||
let urlSchema;
|
||||
if (isHttpRoute) {
|
||||
urlSchema = getUrlFromHttpRoute(resource);
|
||||
} else {
|
||||
urlSchema = getUrlFromIngress(resource);
|
||||
}
|
||||
return urlSchema;
|
||||
}
|
||||
|
||||
export function isDiscoverable(resource, instanceName) {
|
||||
return (
|
||||
resource.metadata.annotations &&
|
||||
resource.metadata.annotations[`${ANNOTATION_BASE}/enabled`] === "true" &&
|
||||
(!resource.metadata.annotations[`${ANNOTATION_BASE}/instance`] ||
|
||||
resource.metadata.annotations[`${ANNOTATION_BASE}/instance`] === instanceName ||
|
||||
`${ANNOTATION_BASE}/instance.${instanceName}` in resource.metadata.annotations)
|
||||
);
|
||||
}
|
||||
|
||||
export async function constructedServiceFromResource(resource) {
|
||||
let constructedService = {
|
||||
app: resource.metadata.annotations[`${ANNOTATION_BASE}/app`] || resource.metadata.name,
|
||||
namespace: resource.metadata.namespace,
|
||||
href: resource.metadata.annotations[`${ANNOTATION_BASE}/href`] || (await getUrlSchema(resource)),
|
||||
name: resource.metadata.annotations[`${ANNOTATION_BASE}/name`] || resource.metadata.name,
|
||||
group: resource.metadata.annotations[`${ANNOTATION_BASE}/group`] || "Kubernetes",
|
||||
weight: resource.metadata.annotations[`${ANNOTATION_BASE}/weight`] || "0",
|
||||
icon: resource.metadata.annotations[`${ANNOTATION_BASE}/icon`] || "",
|
||||
description: resource.metadata.annotations[`${ANNOTATION_BASE}/description`] || "",
|
||||
external: false,
|
||||
type: "service",
|
||||
};
|
||||
if (resource.metadata.annotations[`${ANNOTATION_BASE}/external`]) {
|
||||
constructedService.external =
|
||||
String(resource.metadata.annotations[`${ANNOTATION_BASE}/external`]).toLowerCase() === "true";
|
||||
}
|
||||
if (resource.metadata.annotations[`${ANNOTATION_BASE}/pod-selector`] !== undefined) {
|
||||
constructedService.podSelector = resource.metadata.annotations[`${ANNOTATION_BASE}/pod-selector`];
|
||||
}
|
||||
if (resource.metadata.annotations[`${ANNOTATION_BASE}/ping`]) {
|
||||
constructedService.ping = resource.metadata.annotations[`${ANNOTATION_BASE}/ping`];
|
||||
}
|
||||
if (resource.metadata.annotations[`${ANNOTATION_BASE}/siteMonitor`]) {
|
||||
constructedService.siteMonitor = resource.metadata.annotations[`${ANNOTATION_BASE}/siteMonitor`];
|
||||
}
|
||||
if (resource.metadata.annotations[`${ANNOTATION_BASE}/statusStyle`]) {
|
||||
constructedService.statusStyle = resource.metadata.annotations[`${ANNOTATION_BASE}/statusStyle`];
|
||||
}
|
||||
|
||||
Object.keys(resource.metadata.annotations).forEach((annotation) => {
|
||||
if (annotation.startsWith(ANNOTATION_WIDGET_BASE)) {
|
||||
shvl.set(
|
||||
constructedService,
|
||||
annotation.replace(`${ANNOTATION_BASE}/`, ""),
|
||||
resource.metadata.annotations[annotation],
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
constructedService = JSON.parse(substituteEnvironmentVars(JSON.stringify(constructedService)));
|
||||
} catch (e) {
|
||||
logger.error("Error attempting k8s environment variable substitution.");
|
||||
logger.debug(e);
|
||||
}
|
||||
|
||||
return constructedService;
|
||||
}
|
||||
|
||||
@@ -1,63 +1,62 @@
|
||||
import CustomObjectsApi from "@kubernetes/client-node";
|
||||
|
||||
import getKubernetes,{ getKubeConfig,checkCRD,ANNOTATION_BASE } from "utils/config/kubernetes";
|
||||
import getKubernetes, { getKubeConfig, checkCRD, ANNOTATION_BASE } from "utils/config/kubernetes";
|
||||
import createLogger from "utils/logger";
|
||||
|
||||
const logger = createLogger("traefik-list");
|
||||
const kc = getKubeConfig();
|
||||
|
||||
export default async function listTraefikIngress() {
|
||||
|
||||
const { traefik } = getKubernetes();
|
||||
const traefikList = [];
|
||||
const { traefik } = getKubernetes();
|
||||
const traefikList = [];
|
||||
|
||||
if (!!traefik) {
|
||||
const crd = kc.makeApiClient(CustomObjectsApi);
|
||||
const traefikContainoExists = await checkCRD("ingressroutes.traefik.containo.us",kc,logger);
|
||||
const traefikExists = await checkCRD("ingressroutes.traefik.io",kc,logger);
|
||||
if (!!traefik) {
|
||||
const crd = kc.makeApiClient(CustomObjectsApi);
|
||||
const traefikContainoExists = await checkCRD("ingressroutes.traefik.containo.us", kc, logger);
|
||||
const traefikExists = await checkCRD("ingressroutes.traefik.io", kc, logger);
|
||||
|
||||
const traefikIngressListContaino = await crd
|
||||
.listClusterCustomObject("traefik.containo.us", "v1alpha1", "ingressroutes")
|
||||
.then((response) => response.body)
|
||||
.catch(async (error) => {
|
||||
if (traefikContainoExists) {
|
||||
logger.error(
|
||||
"Error getting traefik ingresses from traefik.containo.us: %d %s %s",
|
||||
error.statusCode,
|
||||
error.body,
|
||||
error.response,
|
||||
);
|
||||
logger.debug(error);
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
|
||||
const traefikIngressListIo = await crd
|
||||
.listClusterCustomObject("traefik.io", "v1alpha1", "ingressroutes")
|
||||
.then((response) => response.body)
|
||||
.catch(async (error) => {
|
||||
if (traefikExists) {
|
||||
logger.error(
|
||||
"Error getting traefik ingresses from traefik.io: %d %s %s",
|
||||
error.statusCode,
|
||||
error.body,
|
||||
error.response,
|
||||
);
|
||||
logger.debug(error);
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
|
||||
const traefikIngressList = [...(traefikIngressListContaino?.items ?? []), ...(traefikIngressListIo?.items ?? [])];
|
||||
|
||||
if (traefikIngressList.length > 0) {
|
||||
const traefikServices = traefikIngressList.filter(
|
||||
(ingress) => ingress.metadata.annotations && ingress.metadata.annotations[`${ANNOTATION_BASE}/href`],
|
||||
);
|
||||
traefikList.push(...traefikServices);
|
||||
const traefikIngressListContaino = await crd
|
||||
.listClusterCustomObject("traefik.containo.us", "v1alpha1", "ingressroutes")
|
||||
.then((response) => response.body)
|
||||
.catch(async (error) => {
|
||||
if (traefikContainoExists) {
|
||||
logger.error(
|
||||
"Error getting traefik ingresses from traefik.containo.us: %d %s %s",
|
||||
error.statusCode,
|
||||
error.body,
|
||||
error.response,
|
||||
);
|
||||
logger.debug(error);
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
|
||||
const traefikIngressListIo = await crd
|
||||
.listClusterCustomObject("traefik.io", "v1alpha1", "ingressroutes")
|
||||
.then((response) => response.body)
|
||||
.catch(async (error) => {
|
||||
if (traefikExists) {
|
||||
logger.error(
|
||||
"Error getting traefik ingresses from traefik.io: %d %s %s",
|
||||
error.statusCode,
|
||||
error.body,
|
||||
error.response,
|
||||
);
|
||||
logger.debug(error);
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
|
||||
const traefikIngressList = [...(traefikIngressListContaino?.items ?? []), ...(traefikIngressListIo?.items ?? [])];
|
||||
|
||||
if (traefikIngressList.length > 0) {
|
||||
const traefikServices = traefikIngressList.filter(
|
||||
(ingress) => ingress.metadata.annotations && ingress.metadata.annotations[`${ANNOTATION_BASE}/href`],
|
||||
);
|
||||
traefikList.push(...traefikServices);
|
||||
}
|
||||
return traefikList;
|
||||
}
|
||||
}
|
||||
return traefikList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user