detect host ip

This commit is contained in:
Laura Abro
2025-04-28 11:26:31 -03:00
parent 6d6d45300a
commit 6cf7e0db0e

View File

@ -1,7 +1,21 @@
import { TASK_ID, namespaceWrapper } from "@_koii/namespace-wrapper"; import { TASK_ID, namespaceWrapper } from "@_koii/namespace-wrapper";
import "dotenv/config"; import "dotenv/config";
import os from "os";
const imageUrl = "docker.io/hermanyiqunliang/summarizer-agent:0.2"; const imageUrl = "docker.io/labrocadabro/prometheus-summarizer:0.2";
function getHostIP() {
const interfaces = os.networkInterfaces();
for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name] || []) {
// Skip over internal (i.e., 127.0.0.1) and non-IPv4 addresses
if (iface.family === "IPv4" && !iface.internal) {
return iface.address;
}
}
}
throw new Error("Unable to determine host IP address");
}
async function createPodSpec(): Promise<string> { async function createPodSpec(): Promise<string> {
const basePath = await namespaceWrapper.getBasePath(); const basePath = await namespaceWrapper.getBasePath();
@ -29,6 +43,10 @@ spec:
hostPath: hostPath:
path: ${basePath}/orca/data path: ${basePath}/orca/data
type: DirectoryOrCreate type: DirectoryOrCreate
hostAliases:
- ip: "${getHostIP()}"
hostnames:
- "host.docker.internal"
`; `;
return podSpec; return podSpec;
} }
@ -37,10 +55,12 @@ export async function getConfig(): Promise<{
imageURL: string; imageURL: string;
customPodSpec: string; customPodSpec: string;
rootCA: string | null; rootCA: string | null;
timeout: number;
}> { }> {
return { return {
imageURL: imageUrl, imageURL: imageUrl,
customPodSpec: await createPodSpec(), customPodSpec: await createPodSpec(),
rootCA: null, rootCA: null,
timeout: 900000,
}; };
} }