File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -197,9 +197,11 @@ export function addOrUpdateObject<T extends KubernetesObject>(
197
197
addCallback . forEach ( ( elt : ObjectCallback < T > ) => elt ( obj ) ) ;
198
198
}
199
199
} else {
200
- objects [ ix ] = obj ;
201
- if ( updateCallback ) {
202
- updateCallback . forEach ( ( elt : ObjectCallback < T > ) => elt ( obj ) ) ;
200
+ if ( ! isSameVersion ( objects [ ix ] , obj ) ) {
201
+ objects [ ix ] = obj ;
202
+ if ( updateCallback ) {
203
+ updateCallback . forEach ( ( elt : ObjectCallback < T > ) => elt ( obj ) ) ;
204
+ }
203
205
}
204
206
}
205
207
}
@@ -208,6 +210,14 @@ function isSameObject<T extends KubernetesObject>(o1: T, o2: T): boolean {
208
210
return o1 . metadata ! . name === o2 . metadata ! . name && o1 . metadata ! . namespace === o2 . metadata ! . namespace ;
209
211
}
210
212
213
+ function isSameVersion < T extends KubernetesObject > ( o1 : T , o2 : T ) : boolean {
214
+ return (
215
+ o1 . metadata ! . resourceVersion !== undefined &&
216
+ o1 . metadata ! . resourceVersion !== null &&
217
+ o1 . metadata ! . resourceVersion === o2 . metadata ! . resourceVersion
218
+ ) ;
219
+ }
220
+
211
221
function findKubernetesObject < T extends KubernetesObject > ( objects : T [ ] , obj : T ) : number {
212
222
return objects . findIndex ( ( elt : T ) => {
213
223
return isSameObject ( elt , obj ) ;
Original file line number Diff line number Diff line change @@ -330,11 +330,13 @@ describe('ListWatchCache', () => {
330
330
{
331
331
metadata : {
332
332
name : 'name1' ,
333
+ resourceVersion : '9876' ,
333
334
} as V1ObjectMeta ,
334
335
} as V1Namespace ,
335
336
{
336
337
metadata : {
337
338
name : 'name2' ,
339
+ resourceVersion : '8765' ,
338
340
} as V1ObjectMeta ,
339
341
} as V1Namespace ,
340
342
] ;
@@ -387,7 +389,7 @@ describe('ListWatchCache', () => {
387
389
doneHandler ( null ) ;
388
390
await promise ;
389
391
expect ( addObjects ) . to . deep . equal ( list ) ;
390
- expect ( updateObjects ) . to . deep . equal ( list ) ;
392
+ expect ( updateObjects ) . to . deep . equal ( [ ] ) ;
391
393
} ) ;
392
394
393
395
it ( 'should perform work as an informer with initial list and delete after' , async ( ) => {
@@ -396,18 +398,21 @@ describe('ListWatchCache', () => {
396
398
{
397
399
metadata : {
398
400
name : 'name1' ,
401
+ resourceVersion : '9876' ,
399
402
} as V1ObjectMeta ,
400
403
} as V1Namespace ,
401
404
{
402
405
metadata : {
403
406
name : 'name2' ,
407
+ resourceVersion : '8765' ,
404
408
} as V1ObjectMeta ,
405
409
} as V1Namespace ,
406
410
] ;
407
411
const list2 : V1Namespace [ ] = [
408
412
{
409
413
metadata : {
410
414
name : 'name1' ,
415
+ resourceVersion : '9999' ,
411
416
} as V1ObjectMeta ,
412
417
} as V1Namespace ,
413
418
] ;
@@ -467,6 +472,7 @@ describe('ListWatchCache', () => {
467
472
{
468
473
metadata : {
469
474
name : 'name2' ,
475
+ resourceVersion : '8765' ,
470
476
} as V1ObjectMeta ,
471
477
} as V1Namespace ,
472
478
] ) ;
You can’t perform that action at this time.
0 commit comments