diff --git a/src/pepr/istio/index.ts b/src/pepr/istio/index.ts index 608af30f4..beef69850 100644 --- a/src/pepr/istio/index.ts +++ b/src/pepr/istio/index.ts @@ -5,6 +5,7 @@ import { Exec, KubeConfig } from "@kubernetes/client-node"; import { Capability, a } from "pepr"; +import { Readable } from "stream"; import { Component, setupLogger } from "../logger"; // configure subproject logger @@ -49,16 +50,22 @@ When(a.Pod) log.error(pod, `Invalid container status in Pod`); return; } - const shouldTerminate = pod.status.containerStatuses - // Ignore the istio-proxy container - .filter(c => c.name != "istio-proxy") - // and if ALL are terminated AND restartPolicy is Never or is OnFailure with a 0 exit code then shouldTerminate is true - .every( - c => - c.state?.terminated && - (pod.spec?.restartPolicy == "Never" || - (pod.spec?.restartPolicy == "OnFailure" && c.state.terminated.exitCode == 0)), + + // if ALL (non istio-proxy) are terminated AND restartPolicy is Never + // or is OnFailure with a 0 exit code + // and istio-proxy is not already terminated then shouldTerminate is true + const shouldTerminate = pod.status.containerStatuses.every(c => { + // handle scenario where proxy was already terminated + if (c.name == "istio-proxy") { + return c.state?.terminated == undefined; + } + + return ( + c.state?.terminated && + (pod.spec?.restartPolicy == "Never" || + (pod.spec?.restartPolicy == "OnFailure" && c.state.terminated.exitCode == 0)) ); + }); if (shouldTerminate) { // Mark the pod as seen @@ -70,6 +77,14 @@ When(a.Pod) kc.loadFromDefault(); const exec = new Exec(kc); + // Trying to avoid passing in process.stdin (this stream read is a no-op) + // The exec call fails with null stdin stream + const dummyStream = new Readable({ + read() { + this.push(null); + }, + }); + await exec.exec( namespace, name, @@ -77,8 +92,8 @@ When(a.Pod) ["pilot-agent", "request", "POST", "/quitquitquit"], null, // Could capture exec stdout here null, // Could capture exec stderr here - process.stdin, - true, + dummyStream, + false, ); log.info(`Terminated sidecar for ${key}`);