Skip to content

Commit a394b4e

Browse files
authored
Merge pull request #1026 from snyk/fix/state
fix: track image state to avoid sending data for deleted workloads
2 parents 55577f9 + 900b19a commit a394b4e

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/scanner/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ async function scanImagesAndSendResults(
136136
const workloadState = await getWorkloadAlreadyScanned(workload);
137137
const imageState = await getWorkloadImageAlreadyScanned(
138138
workload,
139-
workload.imageId,
139+
workload.imageName,
140140
);
141-
if (workloadState === undefined && imageState === undefined) {
141+
if (workloadState === undefined || imageState === undefined) {
142142
logger.info(
143143
{ workloadName },
144144
'the workload has been deleted while scanning was in progress, skipping sending scan results',

src/supervisor/watchers/handlers/pod.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,19 @@ async function handleReadyPod(workloadMetadata: IWorkload[]): Promise<void> {
9595
for (const workload of workloadMetadata) {
9696
const scanned = await getWorkloadImageAlreadyScanned(
9797
workload,
98-
workload.imageId,
98+
workload.imageName,
9999
);
100-
if (scanned !== undefined) {
100+
// ImageID contains the resolved image digest.
101+
// ImageName may contain a tag. The image behind this tag can be mutated and can change over time.
102+
// We need to compare on ImageID which will reliably tell us if the image has changed.
103+
if (scanned === workload.imageId) {
101104
continue;
102105
}
103-
await setWorkloadImageAlreadyScanned(workload, workload.imageId, ''); // empty string takes zero bytes and is !== undefined
106+
await setWorkloadImageAlreadyScanned(
107+
workload,
108+
workload.imageName,
109+
workload.imageId,
110+
);
104111
workloadToScan.push(workload);
105112
}
106113

0 commit comments

Comments
 (0)