mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Handle named ports in probe label renderer (#4118)
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
f4a6fefa42
commit
221ab46540
@ -85,7 +85,7 @@ export enum PodStatus {
|
|||||||
EVICTED = "Evicted"
|
EVICTED = "Evicted"
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPodContainer {
|
export interface IPodContainer extends Partial<Record<PodContainerProbe, IContainerProbe>> {
|
||||||
name: string;
|
name: string;
|
||||||
image: string;
|
image: string;
|
||||||
command?: string[];
|
command?: string[];
|
||||||
@ -136,16 +136,19 @@ export interface IPodContainer {
|
|||||||
readOnly: boolean;
|
readOnly: boolean;
|
||||||
mountPath: string;
|
mountPath: string;
|
||||||
}[];
|
}[];
|
||||||
livenessProbe?: IContainerProbe;
|
|
||||||
readinessProbe?: IContainerProbe;
|
|
||||||
startupProbe?: IContainerProbe;
|
|
||||||
imagePullPolicy: string;
|
imagePullPolicy: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PodContainerProbe = "livenessProbe" | "readinessProbe" | "startupProbe";
|
||||||
|
|
||||||
interface IContainerProbe {
|
interface IContainerProbe {
|
||||||
httpGet?: {
|
httpGet?: {
|
||||||
path?: string;
|
path?: string;
|
||||||
port: number;
|
|
||||||
|
/**
|
||||||
|
* either a port number or an IANA_SVC_NAME string referring to a port defined in the container
|
||||||
|
*/
|
||||||
|
port: number | string;
|
||||||
scheme: string;
|
scheme: string;
|
||||||
host?: string;
|
host?: string;
|
||||||
};
|
};
|
||||||
@ -438,50 +441,64 @@ export class Pod extends WorkloadKubeObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getLivenessProbe(container: IPodContainer) {
|
getLivenessProbe(container: IPodContainer) {
|
||||||
return this.getProbe(container.livenessProbe);
|
return this.getProbe(container, "livenessProbe");
|
||||||
}
|
}
|
||||||
|
|
||||||
getReadinessProbe(container: IPodContainer) {
|
getReadinessProbe(container: IPodContainer) {
|
||||||
return this.getProbe(container.readinessProbe);
|
return this.getProbe(container, "readinessProbe");
|
||||||
}
|
}
|
||||||
|
|
||||||
getStartupProbe(container: IPodContainer) {
|
getStartupProbe(container: IPodContainer) {
|
||||||
return this.getProbe(container.startupProbe);
|
return this.getProbe(container, "startupProbe");
|
||||||
}
|
}
|
||||||
|
|
||||||
getProbe(probeData: IContainerProbe) {
|
private getProbe(container: IPodContainer, field: PodContainerProbe): string[] {
|
||||||
if (!probeData) return [];
|
const probe: string[] = [];
|
||||||
|
const probeData = container[field];
|
||||||
|
|
||||||
|
if (!probeData) {
|
||||||
|
return probe;
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
httpGet, exec, tcpSocket, initialDelaySeconds, timeoutSeconds,
|
httpGet, exec, tcpSocket,
|
||||||
periodSeconds, successThreshold, failureThreshold
|
initialDelaySeconds = 0,
|
||||||
|
timeoutSeconds = 0,
|
||||||
|
periodSeconds = 0,
|
||||||
|
successThreshold = 0,
|
||||||
|
failureThreshold = 0
|
||||||
} = probeData;
|
} = probeData;
|
||||||
const probe = [];
|
|
||||||
|
|
||||||
// HTTP Request
|
// HTTP Request
|
||||||
if (httpGet) {
|
if (httpGet) {
|
||||||
const { path, port, host, scheme } = httpGet;
|
const { path = "", port, host = "", scheme } = httpGet;
|
||||||
|
const resolvedPort = typeof port === "number"
|
||||||
|
? port
|
||||||
|
// Try and find the port number associated witht the name or fallback to the name itself
|
||||||
|
: container.ports?.find(containerPort => containerPort.name === port)?.containerPort || port;
|
||||||
|
|
||||||
probe.push(
|
probe.push(
|
||||||
"http-get",
|
"http-get",
|
||||||
`${scheme.toLowerCase()}://${host || ""}:${port || ""}${path || ""}`,
|
`${scheme.toLowerCase()}://${host}:${resolvedPort}${path}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command
|
// Command
|
||||||
if (exec && exec.command) {
|
if (exec?.command) {
|
||||||
probe.push(`exec [${exec.command.join(" ")}]`);
|
probe.push(`exec [${exec.command.join(" ")}]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TCP Probe
|
// TCP Probe
|
||||||
if (tcpSocket && tcpSocket.port) {
|
if (tcpSocket?.port) {
|
||||||
probe.push(`tcp-socket :${tcpSocket.port}`);
|
probe.push(`tcp-socket :${tcpSocket.port}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
probe.push(
|
probe.push(
|
||||||
`delay=${initialDelaySeconds || "0"}s`,
|
`delay=${initialDelaySeconds}s`,
|
||||||
`timeout=${timeoutSeconds || "0"}s`,
|
`timeout=${timeoutSeconds}s`,
|
||||||
`period=${periodSeconds || "0"}s`,
|
`period=${periodSeconds}s`,
|
||||||
`#success=${successThreshold || "0"}`,
|
`#success=${successThreshold}`,
|
||||||
`#failure=${failureThreshold || "0"}`,
|
`#failure=${failureThreshold}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return probe;
|
return probe;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user