new status format, new podSelector field, more accurate pod stats

* renamed pod label prefix from "homepage" to "gethomepage.dev"
  which is more inline with typical kubernetes practices
This commit is contained in:
James Wynn 2022-12-08 16:03:29 -06:00
parent 174cb651b4
commit 09eb172079
8 changed files with 65 additions and 40 deletions

View file

@ -7,7 +7,7 @@ const logger = createLogger("kubernetesStatusService");
export default async function handler(req, res) {
const APP_LABEL = "app.kubernetes.io/name";
const { service } = req.query;
const { service, podSelector } = req.query;
const [namespace, appName] = service;
if (!namespace && !appName) {
@ -16,8 +16,8 @@ export default async function handler(req, res) {
});
return;
}
const labelSelector = `${APP_LABEL}=${appName}`;
const labelSelector = podSelector !== undefined ? podSelector : `${APP_LABEL}=${appName}`;
logger.info("labelSelector %s/%s = %s", namespace, appName, labelSelector);
try {
const kc = getKubeConfig();
if (!kc) {
@ -47,10 +47,14 @@ export default async function handler(req, res) {
});
return;
}
// at least one pod must be in the "Running" phase, otherwise its "down"
const runningPod = pods.find(pod => pod.status.phase === "Running");
const status = runningPod ? "running" : "down";
const someReady = pods.find(pod => pod.status.phase === "Running");
const allReady = pods.every((pod) => pod.status.phase === "Running");
let status = "down";
if (allReady) {
status = "running";
} else if (someReady) {
status = "partial";
}
res.status(200).json({
status
});