Skip to content

Commit

Permalink
account for terminating sidecar
Browse files Browse the repository at this point in the history
  • Loading branch information
rjferguson21 committed Nov 6, 2024
1 parent f399681 commit fdb9303
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 67 deletions.
134 changes: 78 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"k3d-setup": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'"
},
"dependencies": {
"pepr": "0.38.3"
"pepr": "0.37.2"
},
"devDependencies": {
"@jest/globals": "29.7.0",
Expand Down
24 changes: 15 additions & 9 deletions src/pepr/istio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,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
Expand Down
1 change: 0 additions & 1 deletion src/pepr/policies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export async function startExemptionWatch() {
relistIntervalSec: process.env.PEPR_RELIST_INTERVAL_SECONDS
? parseInt(process.env.PEPR_RELIST_INTERVAL_SECONDS, 10)
: 1800,
useHTTP2: process.env.PEPR_HTTP2_WATCH === "true",
};
const watcher = K8s(UDSExemption).Watch(async (exemption, phase) => {
log.debug(`Processing exemption ${exemption.metadata?.name}, watch phase: ${phase}`);
Expand Down

0 comments on commit fdb9303

Please sign in to comment.