@@ -112,7 +112,12 @@ export class KubeClient {
112
112
rejectUnauthorized : false ,
113
113
requestCert : true ,
114
114
} ) ,
115
- headers : token && { Authorization : 'bearer ' + token } ,
115
+ }
116
+
117
+ if ( token ) {
118
+ config . headers = {
119
+ Authorization : `Bearer ${ token } ` ,
120
+ }
116
121
}
117
122
118
123
const response = await axios . get ( `${ endpoint } ` , config )
@@ -1189,17 +1194,31 @@ export class KubeClient {
1189
1194
1190
1195
async listClusterCustomObject ( resourceAPIGroup : string , resourceAPIVersion : string , resourcePlural : string ) : Promise < any [ ] > {
1191
1196
const customObjectsApi = this . kubeConfig . makeApiClient ( CustomObjectsApi )
1192
- try {
1193
- const { body} = await customObjectsApi . listClusterCustomObject ( resourceAPIGroup , resourceAPIVersion , resourcePlural )
1194
- return ( body as any ) . items ? ( body as any ) . items : [ ]
1195
- } catch ( e : any ) {
1196
- if ( e . response && e . response . statusCode === 404 ) {
1197
- // There is no CRD
1198
- return [ ]
1199
- }
1200
1197
1201
- throw this . wrapK8sClientError ( e )
1198
+ for ( let attempt = 1 ; attempt <= 10 ; attempt ++ ) {
1199
+ try {
1200
+ const { body } = await customObjectsApi . listClusterCustomObject (
1201
+ resourceAPIGroup ,
1202
+ resourceAPIVersion ,
1203
+ resourcePlural
1204
+ )
1205
+ return ( body as any ) . items ? ( body as any ) . items : [ ]
1206
+ } catch ( e : any ) {
1207
+ if ( e . response ?. statusCode === 404 ) {
1208
+ return [ ]
1209
+ }
1210
+
1211
+ const wrappedError = this . wrapK8sClientError ( e )
1212
+ if ( this . isStorageIsReInitializingError ( wrappedError ) ) {
1213
+ await ux . wait ( 1000 )
1214
+ continue
1215
+ }
1216
+
1217
+ throw wrappedError
1218
+ }
1202
1219
}
1220
+
1221
+ throw new Error ( 'Exceeded maximum retry attempts to list cluster custom object: storage is (re)initializing' )
1203
1222
}
1204
1223
1205
1224
async isCatalogSourceExists ( name : string , namespace : string ) : Promise < boolean > {
@@ -1216,16 +1235,6 @@ export class KubeClient {
1216
1235
}
1217
1236
}
1218
1237
1219
- async listCatalogSource ( namespace : string , labelSelector : string ) : Promise < CatalogSource [ ] > {
1220
- const customObjectsApi = this . kubeConfig . makeApiClient ( CustomObjectsApi )
1221
- try {
1222
- const { body} = await customObjectsApi . listNamespacedCustomObject ( 'operators.coreos.com' , 'v1alpha1' , namespace , 'catalogsources' , undefined , undefined , undefined , labelSelector )
1223
- return ( body as any ) . items as CatalogSource [ ]
1224
- } catch ( e : any ) {
1225
- throw this . wrapK8sClientError ( e )
1226
- }
1227
- }
1228
-
1229
1238
async getCatalogSource ( name : string , namespace : string ) : Promise < CatalogSource | undefined > {
1230
1239
const customObjectsApi = this . kubeConfig . makeApiClient ( CustomObjectsApi )
1231
1240
try {
@@ -1914,6 +1923,11 @@ export class KubeClient {
1914
1923
msg . includes ( 'failed calling webhook' ) ||
1915
1924
msg . includes ( 'conversion webhook' )
1916
1925
}
1926
+
1927
+ private isStorageIsReInitializingError ( error : any ) : boolean {
1928
+ const msg = error . message as string
1929
+ return msg . includes ( 'storage is (re)initializing' ) || msg . includes ( 'TooManyRequests' )
1930
+ }
1917
1931
}
1918
1932
1919
1933
class PatchedK8sAppsApi extends AppsV1Api {
0 commit comments