Skip to content

Commit

Permalink
fix: resolve istio job termination container status logic issue (#55)
Browse files Browse the repository at this point in the history
## Description

Resolve logic bug where job termination was not functioning correctly
because containerStatuses field doesnt exist when pod.status.phase is
pending.

## Related Issue

Fixes [#54](#54)


## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [ ] [Contributor Guide
Steps](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md)(https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md#submitting-a-pull-request)
followed
  • Loading branch information
zachariahmiller authored Dec 7, 2023
1 parent 9b3ad64 commit c0142c2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/istio/pepr/istio-job-termination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ When(a.Pod)
.WithLabel("batch.kubernetes.io/job-name")
.WithLabel("service.istio.io/canonical-name")
.Watch(async pod => {
if (!pod.metadata?.name || !pod.metadata.namespace || !pod.status?.containerStatuses) {
if (!pod.metadata?.name || !pod.metadata.namespace ) {
Log.error(pod, `Invalid Pod definition`);
return;
}


const { name, namespace } = pod.metadata;
const key = `${namespace}/${name}`;

Expand All @@ -29,8 +30,12 @@ When(a.Pod)
}

// Only terminate if the pod is running
if (pod.status.phase == "Running") {
if (pod.status?.phase == "Running") {
// Check all container statuses
if (!pod.status.containerStatuses) {
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")
Expand Down

0 comments on commit c0142c2

Please sign in to comment.