diff --git a/src/index.ts b/src/index.ts index 00c05af..8eaba19 100644 --- a/src/index.ts +++ b/src/index.ts @@ -71,23 +71,30 @@ export async function checkAndResize() { continue; } - const container = pod.spec.containers.find(c => c.volumeMounts?.some(mount => mount.name === volume.name)); + const mounts: { container: typeof pod.spec.containers[0]; mount: NonNullable[0] }[] = []; - if (!container) { - continue; + for (const c of pod.spec.containers) { + const containerMounts = c.volumeMounts?.filter(m => m.name === volume.name) ?? []; + for (const m of containerMounts) { + mounts.push({ container: c, mount: m }); + } } - if (!pod.status.containerStatuses?.find(status => status.name === container.name)?.ready) { - console.log(` Pod ${pod.metadata.name} is not ready. Skipped.`); + if (mounts.length === 0) { continue; } - const mount = container.volumeMounts?.find(m => m.name === volume.name); + const readyMount = mounts.find(({ container }) => + pod.status.containerStatuses?.find(status => status.name === container.name)?.ready + ); - if (!mount) { + if (!readyMount) { + console.log(` Pod ${pod.metadata.name} has no ready container with this volume. Skipped.`); continue; } + const { container, mount } = readyMount; + let dfResult; try { @@ -107,7 +114,7 @@ export async function checkAndResize() { for (const dfLine of dfResult.split("\n")) { const [_device, capacity, used, _free, _percent, mountPath] = dfLine.split(/\s+/u); - if (mountPath === mount.mountPath) { + if (mountPath && (mount.mountPath === mountPath || mount.mountPath.startsWith(mountPath + "/"))) { const capacityBytes = parseInt(capacity, 10) * 1024; usedBytes = parseInt(used, 10) * 1024;