Improved handling of empty or disabled kubernetes configuration

This commit is contained in:
James Wynn 2022-10-27 16:53:54 -05:00
parent 0c6f7dbee1
commit 056e26dfd3
5 changed files with 24 additions and 1 deletions

View File

@ -21,6 +21,12 @@ export default async function handler(req, res) {
try { try {
const kc = getKubeConfig(); const kc = getKubeConfig();
if (!kc) {
res.status(500).send({
error: "No kubernetes configuration"
});
return;
}
const coreApi = kc.makeApiClient(CoreV1Api); const coreApi = kc.makeApiClient(CoreV1Api);
const metricsApi = new Metrics(kc); const metricsApi = new Metrics(kc);
const podsResponse = await coreApi.listNamespacedPod(namespace, null, null, null, null, labelSelector) const podsResponse = await coreApi.listNamespacedPod(namespace, null, null, null, null, labelSelector)

View File

@ -20,6 +20,12 @@ export default async function handler(req, res) {
try { try {
const kc = getKubeConfig(); const kc = getKubeConfig();
if (!kc) {
res.status(500).send({
error: "No kubernetes configuration"
});
return;
}
const coreApi = kc.makeApiClient(CoreV1Api); const coreApi = kc.makeApiClient(CoreV1Api);
const podsResponse = await coreApi.listNamespacedPod(namespace, null, null, null, null, labelSelector) const podsResponse = await coreApi.listNamespacedPod(namespace, null, null, null, null, labelSelector)
.then((response) => response.body) .then((response) => response.body)

View File

@ -11,6 +11,11 @@ export default async function handler(req, res) {
try { try {
const kc = getKubeConfig(); const kc = getKubeConfig();
if (!kc) {
return res.status(500).send({
error: "No kubernetes configuration"
});
}
const coreApi = kc.makeApiClient(CoreV1Api); const coreApi = kc.makeApiClient(CoreV1Api);
const metricsApi = new Metrics(kc); const metricsApi = new Metrics(kc);

View File

@ -19,8 +19,11 @@ export default function getKubeConfig() {
kc.loadFromCluster(); kc.loadFromCluster();
break; break;
case 'default': case 'default':
default:
kc.loadFromDefault(); kc.loadFromDefault();
break;
case 'disabled':
default:
return null;
} }
return kc; return kc;

View File

@ -125,6 +125,9 @@ export async function servicesFromKubernetes() {
try { try {
const kc = getKubeConfig(); const kc = getKubeConfig();
if (!kc) {
return [];
}
const networking = kc.makeApiClient(NetworkingV1Api); const networking = kc.makeApiClient(NetworkingV1Api);
const ingressList = await networking.listIngressForAllNamespaces(null, null, null, "homepage/enabled=true") const ingressList = await networking.listIngressForAllNamespaces(null, null, null, "homepage/enabled=true")