@@ -2,6 +2,7 @@ import { KubernetesObject, V1Namespace } from '@kubernetes/client-node';
22import LruCache from 'lru-cache' ;
33
44import { config } from './common/config' ;
5+ import { logger } from './common/logger' ;
56import { extractNamespaceName } from './supervisor/watchers/internal-namespaces' ;
67
78const imagesLruCacheOptions : LruCache . Options < string , Set < string > > = {
@@ -42,43 +43,62 @@ function getWorkloadImageAlreadyScannedKey(
4243 return `${ workload . uid } /${ imageName } ` ;
4344}
4445
45- export async function getWorkloadAlreadyScanned (
46+ export function getWorkloadAlreadyScanned (
4647 workload : WorkloadAlreadyScanned ,
47- ) : Promise < string | undefined > {
48+ ) : string | undefined {
4849 const key = workload . uid ;
4950 return state . workloadsAlreadyScanned . get ( key ) ;
5051}
5152
52- export async function setWorkloadAlreadyScanned (
53+ export function setWorkloadAlreadyScanned (
5354 workload : WorkloadAlreadyScanned ,
5455 revision : string ,
55- ) : Promise < boolean > {
56+ ) : boolean {
5657 const key = workload . uid ;
5758 return state . workloadsAlreadyScanned . set ( key , revision ) ;
5859}
5960
60- export async function deleteWorkloadAlreadyScanned (
61+ export function deleteWorkloadAlreadyScanned (
6162 workload : WorkloadAlreadyScanned ,
62- ) : Promise < void > {
63+ ) : void {
6364 const key = workload . uid ;
6465 state . workloadsAlreadyScanned . del ( key ) ;
6566}
6667
67- export async function getWorkloadImageAlreadyScanned (
68+ export function getWorkloadImageAlreadyScanned (
6869 workload : WorkloadAlreadyScanned ,
6970 imageName : string ,
7071 imageId : string ,
71- ) : Promise < string | undefined > {
72+ ) : string | undefined {
73+ const cachedImages = state . imagesAlreadyScanned . dump ( ) . map ( ( entry ) => {
74+ const values = new Array < string > ( ) ;
75+ for ( const v in entry . v . values ( ) ) {
76+ values . push ( v ) ;
77+ }
78+ return `entry: ${ entry . e } , key: ${ entry . k } ; values: ${ values . join ( ',' ) } ` ;
79+ } ) ;
80+ logger . debug (
81+ { 'kubernetes-monitor' : { cachedImages } } ,
82+ 'images in the cache' ,
83+ ) ;
84+
7285 const key = getWorkloadImageAlreadyScannedKey ( workload , imageName ) ;
7386 const hasImageId = state . imagesAlreadyScanned . get ( key ) ?. has ( imageId ) ;
74- return hasImageId ? imageId : undefined ;
87+ const response = hasImageId ? imageId : undefined ;
88+ if ( response !== undefined ) {
89+ logger . debug (
90+ { 'kubernetes-monitor' : { imageId } } ,
91+ 'image already exists in cache' ,
92+ ) ;
93+ }
94+ return response ;
7595}
7696
77- export async function setWorkloadImageAlreadyScanned (
97+ export function setWorkloadImageAlreadyScanned (
7898 workload : WorkloadAlreadyScanned ,
7999 imageName : string ,
80100 imageId : string ,
81- ) : Promise < boolean > {
101+ ) : boolean {
82102 const key = getWorkloadImageAlreadyScannedKey ( workload , imageName ) ;
83103 const images = state . imagesAlreadyScanned . get ( key ) ;
84104 if ( images !== undefined ) {
@@ -92,9 +112,9 @@ export async function setWorkloadImageAlreadyScanned(
92112 return true ;
93113}
94114
95- export async function deleteWorkloadImagesAlreadyScanned (
115+ export function deleteWorkloadImagesAlreadyScanned (
96116 workload : WorkloadImagesAlreadyScanned ,
97- ) : Promise < void > {
117+ ) : void {
98118 for ( const imageId of workload . imageIds ) {
99119 const key = getWorkloadImageAlreadyScannedKey ( workload , imageId ) ;
100120 state . imagesAlreadyScanned . del ( key ) ;
0 commit comments