fix(web-sentinel): configure apiserver endpoint for manual trigger
This commit is contained in:
@@ -2038,7 +2038,7 @@ async function triggerQuickVerifyCronJob(config: WebProbeSentinelServiceConfig,
|
||||
return { ok: false, status: "blocked", reason: "scenario-missing", namespace, cronJobName, valuesRedacted: true };
|
||||
}
|
||||
|
||||
const activeJobs = await k8sApiJson("GET", `/apis/batch/v1/namespaces/${encodeURIComponent(namespace)}/jobs?labelSelector=${encodeURIComponent(`unidesk.ai/web-probe-sentinel-id=${config.sentinelId}`)}`, null);
|
||||
const activeJobs = await k8sApiJson(config, "GET", `/apis/batch/v1/namespaces/${encodeURIComponent(namespace)}/jobs?labelSelector=${encodeURIComponent(`unidesk.ai/web-probe-sentinel-id=${config.sentinelId}`)}`, null);
|
||||
if (activeJobs.ok === true) {
|
||||
const active = k8sJobItems(activeJobs.bodyJson).filter((job) => numberAtNullable(job, "status.active") > 0);
|
||||
if (active.length > 0) {
|
||||
@@ -2058,7 +2058,7 @@ async function triggerQuickVerifyCronJob(config: WebProbeSentinelServiceConfig,
|
||||
}
|
||||
}
|
||||
|
||||
const cronJob = await k8sApiJson("GET", `/apis/batch/v1/namespaces/${encodeURIComponent(namespace)}/cronjobs/${encodeURIComponent(cronJobName)}`, null);
|
||||
const cronJob = await k8sApiJson(config, "GET", `/apis/batch/v1/namespaces/${encodeURIComponent(namespace)}/cronjobs/${encodeURIComponent(cronJobName)}`, null);
|
||||
if (cronJob.ok !== true) {
|
||||
return {
|
||||
ok: false,
|
||||
@@ -2076,7 +2076,7 @@ async function triggerQuickVerifyCronJob(config: WebProbeSentinelServiceConfig,
|
||||
const now = nowIso();
|
||||
const jobName = manualQuickVerifyJobName(config, now);
|
||||
const job = jobFromCronJobTemplate(config, record(cronJob.bodyJson), jobName, now, reason, source);
|
||||
const created = await k8sApiJson("POST", `/apis/batch/v1/namespaces/${encodeURIComponent(namespace)}/jobs`, job);
|
||||
const created = await k8sApiJson(config, "POST", `/apis/batch/v1/namespaces/${encodeURIComponent(namespace)}/jobs`, job);
|
||||
if (created.ok !== true) {
|
||||
return {
|
||||
ok: false,
|
||||
@@ -2145,9 +2145,9 @@ function jobFromCronJobTemplate(
|
||||
};
|
||||
}
|
||||
|
||||
async function k8sApiJson(method: "GET" | "POST", path: string, body: Record<string, unknown> | null): Promise<Record<string, unknown>> {
|
||||
const host = process.env.KUBERNETES_SERVICE_HOST;
|
||||
const port = Number(process.env.KUBERNETES_SERVICE_PORT_HTTPS ?? process.env.KUBERNETES_SERVICE_PORT ?? 443);
|
||||
async function k8sApiJson(config: WebProbeSentinelServiceConfig, method: "GET" | "POST", path: string, body: Record<string, unknown> | null): Promise<Record<string, unknown>> {
|
||||
const host = stringAtNullable(config.runtime, "kubernetesApi.endpoint.host") ?? process.env.KUBERNETES_SERVICE_HOST;
|
||||
const port = numberAtNullable(config.runtime, "kubernetesApi.endpoint.port") || Number(process.env.KUBERNETES_SERVICE_PORT_HTTPS ?? process.env.KUBERNETES_SERVICE_PORT ?? 443);
|
||||
if (typeof host !== "string" || host.length === 0) return { ok: false, status: "blocked", reason: "kubernetes-service-env-missing", valuesRedacted: true };
|
||||
const tokenPath = "/var/run/secrets/kubernetes.io/serviceaccount/token";
|
||||
const caPath = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt";
|
||||
|
||||
Reference in New Issue
Block a user