mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-07 09:35:54 -08:00
Updated to new kubernetes/client-node ObjectApi
This commit is contained in:
@@ -30,7 +30,12 @@ export default async function handler(req, res) {
|
||||
const coreApi = kc.makeApiClient(CoreV1Api);
|
||||
const metricsApi = new Metrics(kc);
|
||||
const podsResponse = await coreApi
|
||||
.listNamespacedPod(namespace, null, null, null, null, labelSelector)
|
||||
.listNamespacedPod(
|
||||
{
|
||||
namespace: namespace,
|
||||
labelSelector:labelSelector
|
||||
}
|
||||
)
|
||||
.then((response) => response.body)
|
||||
.catch((err) => {
|
||||
logger.error("Error getting pods: %d %s %s", err.statusCode, err.body, err.response);
|
||||
|
||||
@@ -27,8 +27,13 @@ export default async function handler(req, res) {
|
||||
}
|
||||
const coreApi = kc.makeApiClient(CoreV1Api);
|
||||
const podsResponse = await coreApi
|
||||
.listNamespacedPod(namespace, null, null, null, null, labelSelector)
|
||||
.then((response) => response.body)
|
||||
.listNamespacedPod(
|
||||
{
|
||||
namespace: namespace,
|
||||
labelSelector:labelSelector
|
||||
}
|
||||
)
|
||||
.then((response) => response)
|
||||
.catch((err) => {
|
||||
logger.error("Error getting pods: %d %s %s", err.statusCode, err.body, err.response);
|
||||
return null;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { KubeConfig, ApiextensionsV1Api } from "@kubernetes/client-node";
|
||||
|
||||
import checkAndCopyConfig, { CONF_DIR, substituteEnvironmentVars } from "utils/config/config";
|
||||
|
||||
export default function getKubernetes() {
|
||||
export function getKubernetes() {
|
||||
checkAndCopyConfig("kubernetes.yaml");
|
||||
const configFile = path.join(CONF_DIR, "kubernetes.yaml");
|
||||
const rawConfigData = readFileSync(configFile, "utf8");
|
||||
@@ -36,7 +36,7 @@ export const getKubeConfig = () => {
|
||||
export async function checkCRD(name, kc, logger) {
|
||||
const apiExtensions = kc.makeApiClient(ApiextensionsV1Api);
|
||||
const exist = await apiExtensions
|
||||
.readCustomResourceDefinitionStatus(name)
|
||||
.readCustomResourceDefinitionStatus({name:name})
|
||||
.then(() => true)
|
||||
.catch(async (error) => {
|
||||
if (error.statusCode === 403) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { CustomObjectsApi, CoreV1Api } from "@kubernetes/client-node";
|
||||
import { CustomObjectsApi, CoreV1Api, CustomObjectsApiListNamespacedCustomObjectRequest } from "@kubernetes/client-node";
|
||||
import { parseAppSegmentConfig } from "next/dist/build/segment-config/app/app-segment-config";
|
||||
|
||||
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");
|
||||
@@ -14,23 +15,22 @@ export default async function listHttpRoute() {
|
||||
|
||||
if (gateway) {
|
||||
// httproutes
|
||||
const getHttpRoute = async (namespace) =>
|
||||
crd
|
||||
.listNamespacedCustomObject(HTTPROUTE_API_GROUP, HTTPROUTE_API_VERSION, namespace, "httproutes")
|
||||
const getHttpRoute = async (namespace) => {
|
||||
return crd
|
||||
.listNamespacedCustomObject({ group: HTTPROUTE_API_GROUP, version: HTTPROUTE_API_VERSION, namespace: namespace, plural: "httproutes" })
|
||||
.then((response) => {
|
||||
const [httpRoute] = response.body.items;
|
||||
const [httpRoute] = response.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))
|
||||
.then((response) => response.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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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");
|
||||
@@ -13,8 +13,8 @@ export default async function listIngress() {
|
||||
|
||||
if (ingress) {
|
||||
const ingressData = await networking
|
||||
.listIngressForAllNamespaces(null, null, null, null)
|
||||
.then((response) => response.body)
|
||||
.listIngressForAllNamespaces()
|
||||
.then((response) => response)
|
||||
.catch((error) => {
|
||||
logger.error("Error getting ingresses: %d %s %s", error.statusCode, error.body, error.response);
|
||||
logger.debug(error);
|
||||
|
||||
@@ -18,14 +18,16 @@ 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,
|
||||
{
|
||||
group: HTTPROUTE_API_GROUP,
|
||||
version: HTTPROUTE_API_VERSION,
|
||||
namespace: gatewayRef.namespace,
|
||||
plural: "gateways",
|
||||
name: gatewayRef.name
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const listner = response.body.spec.listeners.filter((listener) => listener.name === gatewayRef.sectionName)[0];
|
||||
const listner = response.spec.listeners.filter((listener) => listener.name === gatewayRef.sectionName)[0];
|
||||
return listner.protocol.toLowerCase();
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import CustomObjectsApi from "@kubernetes/client-node";
|
||||
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");
|
||||
@@ -16,8 +16,14 @@ export default async function listTraefikIngress() {
|
||||
const traefikExists = await checkCRD("ingressroutes.traefik.io", kc, logger);
|
||||
|
||||
const traefikIngressListContaino = await crd
|
||||
.listClusterCustomObject("traefik.containo.us", "v1alpha1", "ingressroutes")
|
||||
.then((response) => response.body)
|
||||
.listClusterCustomObject(
|
||||
{
|
||||
group: "traefik.containo.us",
|
||||
version: "v1alpha1",
|
||||
plural: "ingressroutes"
|
||||
}
|
||||
)
|
||||
.then((response) => response)
|
||||
.catch(async (error) => {
|
||||
if (traefikContainoExists) {
|
||||
logger.error(
|
||||
@@ -33,7 +39,13 @@ export default async function listTraefikIngress() {
|
||||
});
|
||||
|
||||
const traefikIngressListIo = await crd
|
||||
.listClusterCustomObject("traefik.io", "v1alpha1", "ingressroutes")
|
||||
.listClusterCustomObject(
|
||||
{
|
||||
group: "traefik.io",
|
||||
version: "v1alpha1",
|
||||
plural:"ingressroutes"
|
||||
}
|
||||
)
|
||||
.then((response) => response.body)
|
||||
.catch(async (error) => {
|
||||
if (traefikExists) {
|
||||
|
||||
Reference in New Issue
Block a user