@@ -4,7 +4,7 @@ import LruCache from 'lru-cache';
44import { config } from './common/config' ;
55import { extractNamespaceName } from './supervisor/watchers/internal-namespaces' ;
66
7- const imagesLruCacheOptions : LruCache . Options < string , string > = {
7+ const imagesLruCacheOptions : LruCache . Options < string , Set < string > > = {
88 // limit cache size so we don't exceed memory limit
99 max : config . IMAGES_SCANNED_CACHE . MAX_SIZE ,
1010 // limit cache life so if our backend loses track of an image's data,
@@ -72,10 +72,12 @@ export async function deleteWorkloadAlreadyScanned(
7272
7373export async function getWorkloadImageAlreadyScanned (
7474 workload : WorkloadAlreadyScanned ,
75+ imageName : string ,
7576 imageId : string ,
7677) : Promise < string | undefined > {
77- const key = getWorkloadImageAlreadyScannedKey ( workload , imageId ) ;
78- return state . imagesAlreadyScanned . get ( key ) ;
78+ const key = getWorkloadImageAlreadyScannedKey ( workload , imageName ) ;
79+ const hasImageId = state . imagesAlreadyScanned . get ( key ) ?. has ( imageId ) ;
80+ return hasImageId ? imageId : undefined ;
7981}
8082
8183export async function setWorkloadImageAlreadyScanned (
@@ -84,7 +86,16 @@ export async function setWorkloadImageAlreadyScanned(
8486 value : string ,
8587) : Promise < boolean > {
8688 const key = getWorkloadImageAlreadyScannedKey ( workload , imageId ) ;
87- return state . imagesAlreadyScanned . set ( key , value ) ;
89+ const images = state . imagesAlreadyScanned . get ( key ) ;
90+ if ( images !== undefined ) {
91+ images . add ( value ) ;
92+ } else {
93+ const set = new Set < string > ( ) ;
94+ set . add ( value ) ;
95+ state . imagesAlreadyScanned . set ( key , set ) ;
96+ }
97+
98+ return true ;
8899}
89100
90101export async function deleteWorkloadImagesAlreadyScanned (
@@ -126,7 +137,9 @@ export function deleteNamespace(namespace: V1Namespace): void {
126137
127138export const state = {
128139 shutdownInProgress : false ,
129- imagesAlreadyScanned : new LruCache < string , string > ( imagesLruCacheOptions ) ,
140+ imagesAlreadyScanned : new LruCache < string , Set < string > > (
141+ imagesLruCacheOptions ,
142+ ) ,
130143 workloadsAlreadyScanned : new LruCache < string , string > (
131144 workloadsLruCacheOptions ,
132145 ) ,
0 commit comments