@@ -9,6 +9,7 @@ export interface ObjectCache<T> {
9
9
10
10
export class ListWatch < T extends KubernetesObject > implements ObjectCache < T > , Informer < T > {
11
11
private objects : T [ ] = [ ] ;
12
+ private resourceVersion : string ;
12
13
private readonly indexCache : { [ key : string ] : T [ ] } = { } ;
13
14
private readonly callbackCache : { [ key : string ] : Array < ObjectCallback < T > > } = { } ;
14
15
@@ -24,6 +25,7 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
24
25
this . callbackCache [ UPDATE ] = [ ] ;
25
26
this . callbackCache [ DELETE ] = [ ] ;
26
27
this . callbackCache [ ERROR ] = [ ] ;
28
+ this . resourceVersion = '' ;
27
29
if ( autoStart ) {
28
30
this . doneHandler ( null ) ;
29
31
}
@@ -68,11 +70,18 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
68
70
return this . indexCache [ namespace ] as ReadonlyArray < T > ;
69
71
}
70
72
73
+ public latestResourceVersion ( ) : string {
74
+ return this . resourceVersion ;
75
+ }
76
+
71
77
private async doneHandler ( err : any ) {
72
78
if ( err ) {
73
79
this . callbackCache [ ERROR ] . forEach ( ( elt : ObjectCallback < T > ) => elt ( err ) ) ;
74
80
return ;
75
81
}
82
+ // TODO: Don't always list here for efficiency
83
+ // try to restart the watch from resourceVersion, but detect 410 GONE and relist in that case.
84
+ // Or if resourceVersion is empty.
76
85
const promise = this . listFn ( ) ;
77
86
const result = await promise ;
78
87
const list = result . body ;
@@ -109,7 +118,7 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
109
118
addOrUpdateObject ( namespaceList , obj ) ;
110
119
}
111
120
112
- private watchHandler ( phase : string , obj : T ) {
121
+ private watchHandler ( phase : string , obj : T , watchObj ?: any ) {
113
122
switch ( phase ) {
114
123
case 'ADDED' :
115
124
case 'MODIFIED' :
@@ -132,6 +141,12 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
132
141
}
133
142
}
134
143
break ;
144
+ case 'BOOKMARK' :
145
+ // nothing to do, here for documentation, mostly.
146
+ break ;
147
+ }
148
+ if ( watchObj && watchObj . metadata ) {
149
+ this . resourceVersion = watchObj . metadata . resourceVersion ;
135
150
}
136
151
}
137
152
}
0 commit comments