Skip to content

Commit 8dabb02

Browse files
committed
fix: cache workloads using uid instead of name as caching key
This solves the case where a workload is added, deleted, and then added again. Snyk-monitor thinks the image for this workload has already been scanned (because we cache this internally by name), however, this is a completely new workload and needs to be re-scanned so the generated Project can be visible for import in Snyk. So use uid in the caching key instead of name, which ensures a completely new instance of the new workload will result in a new cache key.
1 parent 2f50c1c commit 8dabb02

File tree

1 file changed

+2
-2
lines changed
  • src/supervisor/watchers/handlers

1 file changed

+2
-2
lines changed

src/supervisor/watchers/handlers/pod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function handleReadyPod(workloadMetadata: IWorkload[]): void {
6969
const imagesToScan: IWorkload[] = [];
7070
const imageKeys: string[] = [];
7171
for (const image of workloadMetadata) {
72-
const imageKey = `${image.namespace}/${image.type}/${image.name}/${image.imageId}`;
72+
const imageKey = `${image.namespace}/${image.type}/${image.uid}/${image.imageId}`;
7373
if (state.imagesAlreadyScanned.get(imageKey) !== undefined) {
7474
continue;
7575
}
@@ -110,7 +110,7 @@ export async function podWatchHandler(pod: V1Pod): Promise<void> {
110110
const workloadMember = workloadMetadata[0];
111111
const workloadMetadataPayload = constructWorkloadMetadata(workloadMember);
112112
const workloadLocator = workloadMetadataPayload.workloadLocator;
113-
const workloadKey = `${workloadLocator.namespace}/${workloadLocator.type}/${workloadLocator.name}`;
113+
const workloadKey = `${workloadLocator.namespace}/${workloadLocator.type}/${workloadMember.uid}`;
114114
const workloadRevision = workloadMember.revision ? workloadMember.revision.toString() : ''; // this is actually the observed generation
115115
if (state.workloadsAlreadyScanned.get(workloadKey) !== workloadRevision) { // either not exists or different
116116
state.workloadsAlreadyScanned.set(workloadKey, workloadRevision); // empty string takes zero bytes and is !== undefined

0 commit comments

Comments
 (0)