Skip to content

Commit

Permalink
Improved handling of empty or disabled kubernetes configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswynn committed Nov 6, 2022
1 parent 0c6f7db commit 056e26d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/pages/api/kubernetes/stats/[...service].js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export default async function handler(req, res) {

try {
const kc = getKubeConfig();
if (!kc) {
res.status(500).send({
error: "No kubernetes configuration"
});
return;
}
const coreApi = kc.makeApiClient(CoreV1Api);
const metricsApi = new Metrics(kc);
const podsResponse = await coreApi.listNamespacedPod(namespace, null, null, null, null, labelSelector)
Expand Down
6 changes: 6 additions & 0 deletions src/pages/api/kubernetes/status/[...service].js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export default async function handler(req, res) {

try {
const kc = getKubeConfig();
if (!kc) {
res.status(500).send({
error: "No kubernetes configuration"
});
return;
}
const coreApi = kc.makeApiClient(CoreV1Api);
const podsResponse = await coreApi.listNamespacedPod(namespace, null, null, null, null, labelSelector)
.then((response) => response.body)
Expand Down
5 changes: 5 additions & 0 deletions src/pages/api/widgets/kubernetes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default async function handler(req, res) {

try {
const kc = getKubeConfig();
if (!kc) {
return res.status(500).send({
error: "No kubernetes configuration"
});
}
const coreApi = kc.makeApiClient(CoreV1Api);
const metricsApi = new Metrics(kc);

Expand Down
5 changes: 4 additions & 1 deletion src/utils/config/kubernetes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ export default function getKubeConfig() {
kc.loadFromCluster();
break;
case 'default':
default:
kc.loadFromDefault();
break;
case 'disabled':
default:
return null;
}

return kc;
Expand Down
3 changes: 3 additions & 0 deletions src/utils/config/service-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export async function servicesFromKubernetes() {

try {
const kc = getKubeConfig();
if (!kc) {
return [];
}
const networking = kc.makeApiClient(NetworkingV1Api);

const ingressList = await networking.listIngressForAllNamespaces(null, null, null, "homepage/enabled=true")
Expand Down

0 comments on commit 056e26d

Please sign in to comment.