@axway/axway-central-cli 2.17.0-rc.5 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +28 -6
- package/dist/commands/apply/index.js +24 -9
- package/dist/commands/completion/index.js +9 -3
- package/dist/commands/config/common/index.js +11 -2
- package/dist/commands/config/index.js +7 -2
- package/dist/commands/config/list.js +6 -2
- package/dist/commands/config/set.js +31 -4
- package/dist/commands/config/unset.js +12 -2
- package/dist/commands/create/agentResource.js +32 -12
- package/dist/commands/create/environment.js +16 -6
- package/dist/commands/create/index.js +26 -9
- package/dist/commands/create/serviceAccount.js +6 -2
- package/dist/commands/delete/index.js +33 -15
- package/dist/commands/edit/environment.js +21 -6
- package/dist/commands/edit/index.js +8 -4
- package/dist/commands/get/index.js +44 -27
- package/dist/commands/install/agents.js +73 -44
- package/dist/commands/install/apigeexSaasAgents.js +98 -35
- package/dist/commands/install/awsAgents.js +139 -89
- package/dist/commands/install/awsSaasAgents.js +142 -50
- package/dist/commands/install/azureAgents.js +79 -39
- package/dist/commands/install/edgeAgents.js +110 -17
- package/dist/commands/install/helpers/creators.js +70 -17
- package/dist/commands/install/helpers/deleters.js +11 -2
- package/dist/commands/install/helpers/getters.js +30 -4
- package/dist/commands/install/helpers/index.js +48 -13
- package/dist/commands/install/helpers/inputs.js +98 -26
- package/dist/commands/install/helpers/regex.js +34 -29
- package/dist/commands/install/helpers/templates/awsTemplates.js +23 -6
- package/dist/commands/install/helpers/templates/azureTemplates.js +24 -5
- package/dist/commands/install/helpers/templates/edgeTemplates.js +38 -7
- package/dist/commands/install/helpers/templates/istioTemplates.js +16 -5
- package/dist/commands/install/index.js +10 -4
- package/dist/commands/install/istioAgents.js +117 -40
- package/dist/commands/install/platform.js +52 -20
- package/dist/commands/proxies/create.js +18 -2
- package/dist/commands/proxies/index.js +8 -4
- package/dist/commands/proxies/promote.js +21 -2
- package/dist/common/ApiServerClient.js +173 -64
- package/dist/common/CacheController.js +32 -11
- package/dist/common/CliConfigManager.js +27 -14
- package/dist/common/CompositeError.js +30 -6
- package/dist/common/CoreConfigController.js +40 -18
- package/dist/common/DefinitionsManager.js +76 -29
- package/dist/common/Kubectl.js +25 -2
- package/dist/common/PlatformClient.js +63 -19
- package/dist/common/Renderer.js +87 -25
- package/dist/common/TmpFile.js +28 -11
- package/dist/common/bashCommands.js +22 -3
- package/dist/common/basicPrompts.js +43 -8
- package/dist/common/dataService.js +50 -22
- package/dist/common/errorHandler.js +9 -0
- package/dist/common/resultsRenderers.js +42 -10
- package/dist/common/types.js +341 -116
- package/dist/common/utils.js +99 -37
- package/dist/main.js +2 -0
- package/package.json +2 -2
- package/dist/commands/install/gitHubSaasAgents.js +0 -283
|
@@ -4,32 +4,41 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ApiServerVersions = exports.ApiServerClient = void 0;
|
|
7
|
+
|
|
7
8
|
var _assign = _interopRequireDefault(require("lodash/assign"));
|
|
9
|
+
|
|
8
10
|
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
11
|
+
|
|
9
12
|
var _pickBy = _interopRequireDefault(require("lodash/pickBy"));
|
|
13
|
+
|
|
10
14
|
var _snooplogg = _interopRequireDefault(require("snooplogg"));
|
|
15
|
+
|
|
11
16
|
var _CacheController = require("./CacheController");
|
|
17
|
+
|
|
12
18
|
var _dataService = require("./dataService");
|
|
19
|
+
|
|
13
20
|
var _types = require("./types");
|
|
21
|
+
|
|
14
22
|
var _utils = require("./utils");
|
|
23
|
+
|
|
15
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
|
-
function
|
|
18
|
-
|
|
25
|
+
|
|
26
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
+
|
|
19
28
|
const {
|
|
20
29
|
log
|
|
21
30
|
} = (0, _snooplogg.default)('central:class.ApiServerClient');
|
|
22
|
-
|
|
23
31
|
/**
|
|
24
32
|
* ApiServer backend types
|
|
25
33
|
*/
|
|
26
|
-
|
|
34
|
+
|
|
35
|
+
let ApiServerVersions;
|
|
36
|
+
exports.ApiServerVersions = ApiServerVersions;
|
|
37
|
+
|
|
38
|
+
(function (ApiServerVersions) {
|
|
27
39
|
ApiServerVersions["v1alpha1"] = "v1alpha1";
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Client's types
|
|
32
|
-
*/
|
|
40
|
+
})(ApiServerVersions || (exports.ApiServerVersions = ApiServerVersions = {}));
|
|
41
|
+
|
|
33
42
|
class ApiServerClient {
|
|
34
43
|
/**
|
|
35
44
|
* Init temporary file if "data" is provided - write data to file (as YAML at the moment)
|
|
@@ -43,22 +52,29 @@ class ApiServerClient {
|
|
|
43
52
|
team
|
|
44
53
|
} = {}) {
|
|
45
54
|
_defineProperty(this, "baseUrl", void 0);
|
|
55
|
+
|
|
46
56
|
_defineProperty(this, "region", void 0);
|
|
57
|
+
|
|
47
58
|
_defineProperty(this, "useCache", void 0);
|
|
59
|
+
|
|
48
60
|
_defineProperty(this, "account", void 0);
|
|
61
|
+
|
|
49
62
|
_defineProperty(this, "team", void 0);
|
|
63
|
+
|
|
50
64
|
log(`initializing client with params: baseUrl = ${baseUrl}, region = ${region}, account = ${account}, useCache = ${useCache}, team = ${team}`);
|
|
51
65
|
this.baseUrl = baseUrl;
|
|
52
66
|
this.account = account;
|
|
53
67
|
this.region = region;
|
|
54
68
|
this.useCache = useCache === undefined ? true : useCache; // using cache by default
|
|
69
|
+
|
|
55
70
|
this.team = team;
|
|
56
71
|
}
|
|
57
|
-
|
|
58
72
|
/**
|
|
59
73
|
* Build resource url based on its ResourceDefinition and passed scope def and name.
|
|
60
74
|
* Note that for scope url part both name and def needed.
|
|
61
75
|
*/
|
|
76
|
+
|
|
77
|
+
|
|
62
78
|
buildResourceBaseUrl({
|
|
63
79
|
resourceDef,
|
|
64
80
|
resourceName,
|
|
@@ -72,7 +88,6 @@ class ApiServerClient {
|
|
|
72
88
|
const nameUrl = resourceName ? `/${encodeURIComponent(resourceName)}` : '';
|
|
73
89
|
return `${groupUrl}${scopeUrl}${resourceUrl}${nameUrl}`;
|
|
74
90
|
}
|
|
75
|
-
|
|
76
91
|
/**
|
|
77
92
|
* Generates an array of PUT requests for sub-resources based on resource input
|
|
78
93
|
*
|
|
@@ -86,6 +101,8 @@ class ApiServerClient {
|
|
|
86
101
|
* @returns {Promise<Array<() => Promise<any> | null>} returns an array of "request creators" functions
|
|
87
102
|
* that will be used in {@link resolveSubResourcesRequests} to create sub-resources when needed
|
|
88
103
|
*/
|
|
104
|
+
|
|
105
|
+
|
|
89
106
|
async generateSubResourcesRequests({
|
|
90
107
|
resource,
|
|
91
108
|
resourceName,
|
|
@@ -95,6 +112,7 @@ class ApiServerClient {
|
|
|
95
112
|
version = ApiServerVersions.v1alpha1
|
|
96
113
|
}) {
|
|
97
114
|
var _resourceDef$spec$sub, _resourceDef$spec$sub2;
|
|
115
|
+
|
|
98
116
|
const service = await (0, _dataService.dataService)({
|
|
99
117
|
baseUrl: this.baseUrl,
|
|
100
118
|
region: this.region,
|
|
@@ -113,15 +131,13 @@ class ApiServerClient {
|
|
|
113
131
|
return (0, _isEmpty.default)(foundSubResources) ? null : Object.keys(foundSubResources).map(key => {
|
|
114
132
|
return () => service.put(`${baseUrl}/${key}?fields=${key}`, {
|
|
115
133
|
[key]: foundSubResources[key]
|
|
116
|
-
})
|
|
117
|
-
// note: "catch" will not be needed if APIs will return the sub-resource name in error response
|
|
134
|
+
}) // note: "catch" will not be needed if APIs will return the sub-resource name in error response
|
|
118
135
|
.catch(err => Promise.reject({
|
|
119
136
|
name: key,
|
|
120
137
|
requestError: err
|
|
121
138
|
}));
|
|
122
139
|
});
|
|
123
140
|
}
|
|
124
|
-
|
|
125
141
|
/**
|
|
126
142
|
* Executes sub-resources requests generated by {@link generateSubResourcesRequests}
|
|
127
143
|
*
|
|
@@ -130,55 +146,64 @@ class ApiServerClient {
|
|
|
130
146
|
* @returns {ApiServerClientSingleResult} returns mainResourceResponse merged with successful sub-resources results
|
|
131
147
|
* and error details if encountered
|
|
132
148
|
*/
|
|
149
|
+
|
|
150
|
+
|
|
133
151
|
async resolveSubResourcesRequests(mainResourceResponse, pendingCalls) {
|
|
134
152
|
var _result$error2, _result$error3;
|
|
153
|
+
|
|
135
154
|
if (!pendingCalls) return {
|
|
136
155
|
data: mainResourceResponse,
|
|
137
156
|
error: null
|
|
138
157
|
};
|
|
139
|
-
log(`resolving sub-resources, pending calls = ${pendingCalls.length}.`);
|
|
140
|
-
|
|
158
|
+
log(`resolving sub-resources, pending calls = ${pendingCalls.length}.`); // note: errors set to an empty array initially, will reset to null if no errors found
|
|
159
|
+
|
|
141
160
|
const result = {
|
|
142
161
|
data: null,
|
|
143
162
|
error: []
|
|
144
163
|
};
|
|
145
164
|
const subResourcesCombined = (await Promise.allSettled(pendingCalls.map(call => call()))).reduce((a, c) => {
|
|
146
|
-
if (c.status === 'fulfilled') return {
|
|
147
|
-
...a,
|
|
165
|
+
if (c.status === 'fulfilled') return { ...a,
|
|
148
166
|
...c.value
|
|
149
167
|
};else {
|
|
150
168
|
var _c$reason$requestErro;
|
|
169
|
+
|
|
151
170
|
// expecting only a valid ApiServer error response here
|
|
152
171
|
// re-throw if something different, so it should be handled by command's catch block.
|
|
153
172
|
if ((_c$reason$requestErro = c.reason.requestError) !== null && _c$reason$requestErro !== void 0 && _c$reason$requestErro.errors && Array.isArray(c.reason.requestError.errors)) {
|
|
154
173
|
var _result$error;
|
|
174
|
+
|
|
155
175
|
// note: if APIs are going to return more details this details override will not be needed, just push as in other methods
|
|
156
|
-
(_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.push(...c.reason.requestError.errors.map(e => ({
|
|
157
|
-
...e,
|
|
176
|
+
(_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.push(...c.reason.requestError.errors.map(e => ({ ...e,
|
|
158
177
|
detail: `sub-resource "${c.reason.name}" ${e.detail}`
|
|
159
178
|
})));
|
|
160
179
|
} else throw c.reason;
|
|
180
|
+
|
|
161
181
|
return a;
|
|
162
182
|
}
|
|
163
183
|
}, {});
|
|
164
184
|
result.data = (0, _assign.default)(mainResourceResponse, subResourcesCombined);
|
|
165
185
|
if (!((_result$error2 = result.error) !== null && _result$error2 !== void 0 && _result$error2.length)) result.error = null; // reset errors to null if none encountered
|
|
186
|
+
|
|
166
187
|
log(`resolving sub-resources is complete, data received = ${!(0, _isEmpty.default)(subResourcesCombined)}, errors = ${(_result$error3 = result.error) === null || _result$error3 === void 0 ? void 0 : _result$error3.length}.`);
|
|
167
188
|
return result;
|
|
168
189
|
}
|
|
169
|
-
|
|
170
190
|
/**
|
|
171
191
|
* Check if resources are deleted by making a fetch call for the resources
|
|
172
192
|
*/
|
|
193
|
+
|
|
194
|
+
|
|
173
195
|
checkForResources(sortedResources, sortedDefsArray) {
|
|
174
196
|
return Promise.all(sortedResources.map(resource => {
|
|
175
197
|
var _resource$metadata2, _resource$metadata3, _resource$metadata3$s;
|
|
198
|
+
|
|
176
199
|
const resourceDef = sortedDefsArray.find(def => {
|
|
177
200
|
var _def$spec$scope, _resource$metadata, _resource$metadata$sc;
|
|
201
|
+
|
|
178
202
|
return def.spec.kind === resource.kind && ((_def$spec$scope = def.spec.scope) === null || _def$spec$scope === void 0 ? void 0 : _def$spec$scope.kind) === ((_resource$metadata = resource.metadata) === null || _resource$metadata === void 0 ? void 0 : (_resource$metadata$sc = _resource$metadata.scope) === null || _resource$metadata$sc === void 0 ? void 0 : _resource$metadata$sc.kind);
|
|
179
203
|
});
|
|
180
204
|
const scopeDef = !!((_resource$metadata2 = resource.metadata) !== null && _resource$metadata2 !== void 0 && _resource$metadata2.scope) ? sortedDefsArray.find(def => def.spec.kind === resource.metadata.scope.kind && !def.spec.scope) : undefined;
|
|
181
205
|
const scopeName = (_resource$metadata3 = resource.metadata) === null || _resource$metadata3 === void 0 ? void 0 : (_resource$metadata3$s = _resource$metadata3.scope) === null || _resource$metadata3$s === void 0 ? void 0 : _resource$metadata3$s.name;
|
|
206
|
+
|
|
182
207
|
if (resourceDef) {
|
|
183
208
|
return this.getResourceByName({
|
|
184
209
|
resourceDef,
|
|
@@ -189,7 +214,6 @@ class ApiServerClient {
|
|
|
189
214
|
} else return null;
|
|
190
215
|
}));
|
|
191
216
|
}
|
|
192
|
-
|
|
193
217
|
/**
|
|
194
218
|
* SINGLE RESOURCE CALLS
|
|
195
219
|
*/
|
|
@@ -198,6 +222,8 @@ class ApiServerClient {
|
|
|
198
222
|
* Create a single resource.
|
|
199
223
|
* @param resources resource to create
|
|
200
224
|
*/
|
|
225
|
+
|
|
226
|
+
|
|
201
227
|
async createResource({
|
|
202
228
|
resourceDef,
|
|
203
229
|
resource,
|
|
@@ -213,6 +239,7 @@ class ApiServerClient {
|
|
|
213
239
|
pending: null,
|
|
214
240
|
warning: false
|
|
215
241
|
};
|
|
242
|
+
|
|
216
243
|
try {
|
|
217
244
|
const service = await (0, _dataService.dataService)({
|
|
218
245
|
baseUrl: this.baseUrl,
|
|
@@ -227,10 +254,12 @@ class ApiServerClient {
|
|
|
227
254
|
version
|
|
228
255
|
});
|
|
229
256
|
const response = await service.post(url, (0, _utils.sanitizeMetadata)(resource));
|
|
257
|
+
|
|
230
258
|
if (!resource.name) {
|
|
231
259
|
log('createResource, resource does not have a logical name');
|
|
232
260
|
result.warning = true;
|
|
233
261
|
}
|
|
262
|
+
|
|
234
263
|
const pendingSubResources = await this.generateSubResourcesRequests({
|
|
235
264
|
resource,
|
|
236
265
|
resourceName: response.name,
|
|
@@ -240,6 +269,7 @@ class ApiServerClient {
|
|
|
240
269
|
version
|
|
241
270
|
});
|
|
242
271
|
log(`createResource, pendingSubResources = ${pendingSubResources === null || pendingSubResources === void 0 ? void 0 : pendingSubResources.length}`);
|
|
272
|
+
|
|
243
273
|
if (withSubResources) {
|
|
244
274
|
const {
|
|
245
275
|
data: subResData,
|
|
@@ -252,21 +282,23 @@ class ApiServerClient {
|
|
|
252
282
|
result.pending = pendingSubResources;
|
|
253
283
|
}
|
|
254
284
|
} catch (e) {
|
|
255
|
-
log('createResource, error: ', e);
|
|
256
|
-
// expecting only a valid ApiServer error response here
|
|
285
|
+
log('createResource, error: ', e); // expecting only a valid ApiServer error response here
|
|
257
286
|
// re-throw if something different, so it should be handled by command's catch block.
|
|
287
|
+
|
|
258
288
|
if (e.errors && Array.isArray(e.errors)) {
|
|
259
289
|
result.error = e.errors;
|
|
260
290
|
} else throw e;
|
|
261
291
|
}
|
|
292
|
+
|
|
262
293
|
if (!!result.data) result.data = (0, _utils.sanitizeMetadata)(result.data);
|
|
263
294
|
return result;
|
|
264
295
|
}
|
|
265
|
-
|
|
266
296
|
/**
|
|
267
297
|
* Update a single resource.
|
|
268
298
|
* @param resources resource to create
|
|
269
299
|
*/
|
|
300
|
+
|
|
301
|
+
|
|
270
302
|
async updateResource({
|
|
271
303
|
resourceDef,
|
|
272
304
|
resource,
|
|
@@ -281,6 +313,7 @@ class ApiServerClient {
|
|
|
281
313
|
error: null,
|
|
282
314
|
pending: null
|
|
283
315
|
};
|
|
316
|
+
|
|
284
317
|
try {
|
|
285
318
|
const service = await (0, _dataService.dataService)({
|
|
286
319
|
baseUrl: this.baseUrl,
|
|
@@ -304,6 +337,7 @@ class ApiServerClient {
|
|
|
304
337
|
scopeName,
|
|
305
338
|
version
|
|
306
339
|
});
|
|
340
|
+
|
|
307
341
|
if (withSubResources) {
|
|
308
342
|
const {
|
|
309
343
|
data: subResData,
|
|
@@ -316,17 +350,17 @@ class ApiServerClient {
|
|
|
316
350
|
result.pending = pendingSubResources;
|
|
317
351
|
}
|
|
318
352
|
} catch (e) {
|
|
319
|
-
log('updateResource, error', e);
|
|
320
|
-
// expecting only a valid ApiServer error response here
|
|
353
|
+
log('updateResource, error', e); // expecting only a valid ApiServer error response here
|
|
321
354
|
// re-throw if something different, so it should be handled by command's catch block.
|
|
355
|
+
|
|
322
356
|
if (e.errors && Array.isArray(e.errors)) {
|
|
323
357
|
result.error = e.errors;
|
|
324
358
|
} else throw e;
|
|
325
359
|
}
|
|
360
|
+
|
|
326
361
|
if (!!result.data) result.data = (0, _utils.sanitizeMetadata)(result.data);
|
|
327
362
|
return result;
|
|
328
363
|
}
|
|
329
|
-
|
|
330
364
|
/**
|
|
331
365
|
* Delete a resources by name.
|
|
332
366
|
* @param opts = {
|
|
@@ -338,6 +372,8 @@ class ApiServerClient {
|
|
|
338
372
|
* wait - if provided, a followup GET call will be executed to confirm if the resource removed.
|
|
339
373
|
* }
|
|
340
374
|
*/
|
|
375
|
+
|
|
376
|
+
|
|
341
377
|
async deleteResourceByName({
|
|
342
378
|
resourceDef,
|
|
343
379
|
resourceName,
|
|
@@ -351,6 +387,7 @@ class ApiServerClient {
|
|
|
351
387
|
data: null,
|
|
352
388
|
error: null
|
|
353
389
|
};
|
|
390
|
+
|
|
354
391
|
try {
|
|
355
392
|
const service = await (0, _dataService.dataService)({
|
|
356
393
|
baseUrl: this.baseUrl,
|
|
@@ -365,15 +402,16 @@ class ApiServerClient {
|
|
|
365
402
|
scopeName,
|
|
366
403
|
version
|
|
367
404
|
});
|
|
368
|
-
const response = await service.delete(url);
|
|
369
|
-
// note: delete "response" value from api-server is translated to an empty string currently.
|
|
405
|
+
const response = await service.delete(url); // note: delete "response" value from api-server is translated to an empty string currently.
|
|
370
406
|
// If its true, constructing a simple representation from provided data (definition, name, scope name)
|
|
371
407
|
// and manually set it as the "data" key.
|
|
408
|
+
|
|
372
409
|
result.data = response === '' ? (0, _utils.buildGenericResource)({
|
|
373
410
|
resourceDef,
|
|
374
411
|
resourceName,
|
|
375
412
|
scopeName
|
|
376
413
|
}) : response;
|
|
414
|
+
|
|
377
415
|
if (wait) {
|
|
378
416
|
await new Promise(resolve => setTimeout(async () => {
|
|
379
417
|
const res = await this.getResourceByName({
|
|
@@ -383,6 +421,7 @@ class ApiServerClient {
|
|
|
383
421
|
scopeName,
|
|
384
422
|
version
|
|
385
423
|
});
|
|
424
|
+
|
|
386
425
|
if (!!res.data) {
|
|
387
426
|
result.data = null;
|
|
388
427
|
result.error = [{
|
|
@@ -390,20 +429,21 @@ class ApiServerClient {
|
|
|
390
429
|
status: 0
|
|
391
430
|
}];
|
|
392
431
|
}
|
|
432
|
+
|
|
393
433
|
resolve({});
|
|
394
434
|
}, _types.WAIT_TIMEOUT));
|
|
395
435
|
}
|
|
396
436
|
} catch (e) {
|
|
397
|
-
log('deleteResourceByName, error: ', e);
|
|
398
|
-
// expecting only a valid ApiServer error response here
|
|
437
|
+
log('deleteResourceByName, error: ', e); // expecting only a valid ApiServer error response here
|
|
399
438
|
// re-throw if something different so it should be handled by command's catch block.
|
|
439
|
+
|
|
400
440
|
if (e.errors && Array.isArray(e.errors)) {
|
|
401
441
|
result.error = e.errors;
|
|
402
442
|
} else throw e;
|
|
403
443
|
}
|
|
444
|
+
|
|
404
445
|
return result;
|
|
405
446
|
}
|
|
406
|
-
|
|
407
447
|
/**
|
|
408
448
|
* Get a resources list.
|
|
409
449
|
* @param opts = {
|
|
@@ -415,6 +455,8 @@ class ApiServerClient {
|
|
|
415
455
|
* progressListener - Optional callback invoked multiple times with download progress
|
|
416
456
|
* }
|
|
417
457
|
*/
|
|
458
|
+
|
|
459
|
+
|
|
418
460
|
async getResourcesList({
|
|
419
461
|
resourceDef,
|
|
420
462
|
scopeDef,
|
|
@@ -428,6 +470,7 @@ class ApiServerClient {
|
|
|
428
470
|
data: null,
|
|
429
471
|
error: null
|
|
430
472
|
};
|
|
473
|
+
|
|
431
474
|
try {
|
|
432
475
|
const service = await (0, _dataService.dataService)({
|
|
433
476
|
baseUrl: this.baseUrl,
|
|
@@ -444,16 +487,16 @@ class ApiServerClient {
|
|
|
444
487
|
const response = await service.getWithPagination(url, query, 50, {}, progressListener);
|
|
445
488
|
result.data = response;
|
|
446
489
|
} catch (e) {
|
|
447
|
-
log('getResourcesList, error: ', e);
|
|
448
|
-
// expecting only a valid ApiServer error response here
|
|
490
|
+
log('getResourcesList, error: ', e); // expecting only a valid ApiServer error response here
|
|
449
491
|
// re-throw if something different so it should be handled by command's catch block.
|
|
492
|
+
|
|
450
493
|
if (e.errors && Array.isArray(e.errors)) {
|
|
451
494
|
result.error = e.errors;
|
|
452
495
|
} else throw e;
|
|
453
496
|
}
|
|
497
|
+
|
|
454
498
|
return result;
|
|
455
499
|
}
|
|
456
|
-
|
|
457
500
|
/**
|
|
458
501
|
* Get a resources by name.
|
|
459
502
|
* @param opts = {
|
|
@@ -464,6 +507,8 @@ class ApiServerClient {
|
|
|
464
507
|
* version - apis version (using alpha1 by default currently)
|
|
465
508
|
* }
|
|
466
509
|
*/
|
|
510
|
+
|
|
511
|
+
|
|
467
512
|
async getResourceByName({
|
|
468
513
|
resourceDef,
|
|
469
514
|
resourceName,
|
|
@@ -476,6 +521,7 @@ class ApiServerClient {
|
|
|
476
521
|
data: null,
|
|
477
522
|
error: null
|
|
478
523
|
};
|
|
524
|
+
|
|
479
525
|
try {
|
|
480
526
|
const service = await (0, _dataService.dataService)({
|
|
481
527
|
baseUrl: this.baseUrl,
|
|
@@ -493,23 +539,26 @@ class ApiServerClient {
|
|
|
493
539
|
const response = await service.get(url);
|
|
494
540
|
result.data = response;
|
|
495
541
|
} catch (e) {
|
|
496
|
-
log('getResourceByName, error: ', e);
|
|
497
|
-
// expecting only a valid ApiServer error response here
|
|
542
|
+
log('getResourceByName, error: ', e); // expecting only a valid ApiServer error response here
|
|
498
543
|
// re-throw if something different so it should be handled by command's catch block.
|
|
544
|
+
|
|
499
545
|
if (e.errors && Array.isArray(e.errors)) {
|
|
500
546
|
result.error = e.errors;
|
|
501
547
|
} else throw e;
|
|
502
548
|
}
|
|
549
|
+
|
|
503
550
|
return result;
|
|
504
551
|
}
|
|
505
|
-
|
|
506
552
|
/**
|
|
507
553
|
* Fetch definition endpoints to get specs for available resources.
|
|
508
554
|
* Note that only "management" group is used currently.
|
|
509
555
|
* @returns { group1: { resources: Map, cli: Map }, group2: { ... }, groupN: { ... } }
|
|
510
556
|
*/
|
|
557
|
+
|
|
558
|
+
|
|
511
559
|
async getSpecs(version = ApiServerVersions.v1alpha1) {
|
|
512
560
|
log(`get specs`);
|
|
561
|
+
|
|
513
562
|
try {
|
|
514
563
|
const specs = {};
|
|
515
564
|
const service = await (0, _dataService.dataService)({
|
|
@@ -518,11 +567,15 @@ class ApiServerClient {
|
|
|
518
567
|
account: this.account
|
|
519
568
|
});
|
|
520
569
|
const groups = await service.getWithPagination(`/definitions/${version}/groups`);
|
|
570
|
+
|
|
521
571
|
for (const group of groups) {
|
|
522
572
|
let resources = [];
|
|
523
573
|
let cli = [];
|
|
574
|
+
|
|
524
575
|
const cachedGroup = _CacheController.CacheController.get(`groups-${group.name}-${version}`);
|
|
576
|
+
|
|
525
577
|
let cacheUpdated = false;
|
|
578
|
+
|
|
526
579
|
if (this.useCache && cachedGroup && cachedGroup.resourceVersion === group.metadata.resourceVersion) {
|
|
527
580
|
log(`valid ${group.name}/${version} found in cache`);
|
|
528
581
|
resources = cachedGroup.resources;
|
|
@@ -530,32 +583,38 @@ class ApiServerClient {
|
|
|
530
583
|
} else {
|
|
531
584
|
log(`no valid ${group.name}/${version} found in cache or cache usage is not set`);
|
|
532
585
|
[resources, cli] = await Promise.all([service.getWithPagination(`/definitions/${version}/groups/${group.name}/resources`), service.getWithPagination(`/definitions/${version}/groups/${group.name}/commandlines`)]);
|
|
586
|
+
|
|
533
587
|
_CacheController.CacheController.set(`groups-${group.name}-${version}`, {
|
|
534
588
|
resourceVersion: group.metadata.resourceVersion,
|
|
535
589
|
resources,
|
|
536
590
|
cli
|
|
537
591
|
});
|
|
592
|
+
|
|
538
593
|
cacheUpdated = true;
|
|
539
594
|
}
|
|
595
|
+
|
|
540
596
|
specs[group.name] = {
|
|
541
597
|
resources: new Map(),
|
|
542
598
|
cli: new Map()
|
|
543
599
|
};
|
|
600
|
+
|
|
544
601
|
for (const r of resources) {
|
|
545
602
|
specs[group.name].resources.set(r.name, r);
|
|
546
603
|
}
|
|
604
|
+
|
|
547
605
|
for (const c of cli) {
|
|
548
606
|
specs[group.name].cli.set(c.name, c);
|
|
549
607
|
}
|
|
608
|
+
|
|
550
609
|
if (cacheUpdated) _CacheController.CacheController.writeToFile();
|
|
551
610
|
}
|
|
611
|
+
|
|
552
612
|
return specs;
|
|
553
613
|
} catch (e) {
|
|
554
614
|
log('get specs, error: ', e);
|
|
555
615
|
throw e;
|
|
556
616
|
}
|
|
557
617
|
}
|
|
558
|
-
|
|
559
618
|
/**
|
|
560
619
|
* BULK CALLS
|
|
561
620
|
*/
|
|
@@ -566,9 +625,11 @@ class ApiServerClient {
|
|
|
566
625
|
* sorting of the array of resources with "compareResourcesByKindAsc".
|
|
567
626
|
* @param resources array of resources to create
|
|
568
627
|
*/
|
|
628
|
+
|
|
629
|
+
|
|
569
630
|
async bulkCreate(resources, sortedDefsMap, version) {
|
|
570
|
-
log(`bulk create`);
|
|
571
|
-
|
|
631
|
+
log(`bulk create`); // sort() is modifying the existing array so cloning it before use.
|
|
632
|
+
|
|
572
633
|
const sortedDefsArray = Array.from(sortedDefsMap.values());
|
|
573
634
|
const sortedResources = [...resources].sort((0, _utils.compareResourcesByKindAsc)(sortedDefsArray));
|
|
574
635
|
const pendingSubResources = [];
|
|
@@ -577,21 +638,29 @@ class ApiServerClient {
|
|
|
577
638
|
error: [],
|
|
578
639
|
warning: []
|
|
579
640
|
};
|
|
641
|
+
|
|
580
642
|
for (const resource of sortedResources) {
|
|
581
643
|
var _resource$metadata7, _resource$metadata8, _resource$metadata8$s;
|
|
644
|
+
|
|
582
645
|
const resourceDef = sortedDefsArray.find(def => {
|
|
583
646
|
var _def$spec$scope2, _resource$metadata4, _resource$metadata4$s;
|
|
647
|
+
|
|
584
648
|
return def.spec.kind === resource.kind && ((_def$spec$scope2 = def.spec.scope) === null || _def$spec$scope2 === void 0 ? void 0 : _def$spec$scope2.kind) === ((_resource$metadata4 = resource.metadata) === null || _resource$metadata4 === void 0 ? void 0 : (_resource$metadata4$s = _resource$metadata4.scope) === null || _resource$metadata4$s === void 0 ? void 0 : _resource$metadata4$s.kind);
|
|
585
649
|
});
|
|
650
|
+
|
|
586
651
|
if (!resourceDef) {
|
|
587
652
|
var _resource$metadata5, _resource$metadata5$s;
|
|
653
|
+
|
|
588
654
|
let errorMessage = `No resource definition found for "kind/${resource.kind}"`;
|
|
655
|
+
|
|
589
656
|
if (!!((_resource$metadata5 = resource.metadata) !== null && _resource$metadata5 !== void 0 && (_resource$metadata5$s = _resource$metadata5.scope) !== null && _resource$metadata5$s !== void 0 && _resource$metadata5$s.kind)) {
|
|
590
657
|
var _resource$metadata6, _resource$metadata6$s;
|
|
658
|
+
|
|
591
659
|
errorMessage += ` in the scope "${(_resource$metadata6 = resource.metadata) === null || _resource$metadata6 === void 0 ? void 0 : (_resource$metadata6$s = _resource$metadata6.scope) === null || _resource$metadata6$s === void 0 ? void 0 : _resource$metadata6$s.kind}".`;
|
|
592
660
|
} else {
|
|
593
661
|
errorMessage += ' with no scope.';
|
|
594
662
|
}
|
|
663
|
+
|
|
595
664
|
bulkResult.error.push({
|
|
596
665
|
name: resource.name || 'Unknown name',
|
|
597
666
|
kind: resource.kind,
|
|
@@ -599,6 +668,7 @@ class ApiServerClient {
|
|
|
599
668
|
});
|
|
600
669
|
continue;
|
|
601
670
|
}
|
|
671
|
+
|
|
602
672
|
const scopeDef = !!((_resource$metadata7 = resource.metadata) !== null && _resource$metadata7 !== void 0 && _resource$metadata7.scope) ? sortedDefsArray.find(def => def.spec.kind === resource.metadata.scope.kind && !def.spec.scope) : undefined;
|
|
603
673
|
const scopeName = (_resource$metadata8 = resource.metadata) === null || _resource$metadata8 === void 0 ? void 0 : (_resource$metadata8$s = _resource$metadata8.scope) === null || _resource$metadata8$s === void 0 ? void 0 : _resource$metadata8$s.name;
|
|
604
674
|
const res = await this.createResource({
|
|
@@ -609,11 +679,13 @@ class ApiServerClient {
|
|
|
609
679
|
version,
|
|
610
680
|
withSubResources: false
|
|
611
681
|
});
|
|
682
|
+
|
|
612
683
|
if (res.data && !res.error) {
|
|
613
684
|
// note: bulk operation requires creation of sub-resources after all main resources created
|
|
614
685
|
// since a sub-resource might have a reference to another resource.
|
|
615
686
|
if (!!res.pending) {
|
|
616
687
|
var _res$warning;
|
|
688
|
+
|
|
617
689
|
pendingSubResources.push({
|
|
618
690
|
mainResult: res.data,
|
|
619
691
|
pendingCalls: res.pending,
|
|
@@ -621,6 +693,7 @@ class ApiServerClient {
|
|
|
621
693
|
});
|
|
622
694
|
} else {
|
|
623
695
|
var _bulkResult$warning;
|
|
696
|
+
|
|
624
697
|
if (res.warning) (_bulkResult$warning = bulkResult.warning) === null || _bulkResult$warning === void 0 ? void 0 : _bulkResult$warning.push(res.data);else bulkResult.success.push(res.data);
|
|
625
698
|
}
|
|
626
699
|
} else if (res.error) {
|
|
@@ -632,13 +705,15 @@ class ApiServerClient {
|
|
|
632
705
|
});
|
|
633
706
|
}
|
|
634
707
|
}
|
|
635
|
-
}
|
|
708
|
+
} // creating sub-resources
|
|
709
|
+
|
|
636
710
|
|
|
637
|
-
// creating sub-resources
|
|
638
711
|
for (const p of pendingSubResources) {
|
|
639
712
|
const subResResult = await this.resolveSubResourcesRequests(p.mainResult, p.pendingCalls);
|
|
713
|
+
|
|
640
714
|
if (subResResult.data && !subResResult.error) {
|
|
641
715
|
var _bulkResult$warning2;
|
|
716
|
+
|
|
642
717
|
if (p.withWarning) (_bulkResult$warning2 = bulkResult.warning) === null || _bulkResult$warning2 === void 0 ? void 0 : _bulkResult$warning2.push(subResResult.data);else bulkResult.success.push(subResResult.data);
|
|
643
718
|
} else if (subResResult.error) {
|
|
644
719
|
for (const nextError of subResResult.error) {
|
|
@@ -650,18 +725,20 @@ class ApiServerClient {
|
|
|
650
725
|
}
|
|
651
726
|
}
|
|
652
727
|
}
|
|
728
|
+
|
|
653
729
|
return bulkResult;
|
|
654
730
|
}
|
|
655
|
-
|
|
656
731
|
/**
|
|
657
732
|
* Bulk creation of resources.
|
|
658
733
|
* There is no endpoint for bulk create so executing them one-by-one. Order of calls calculated by
|
|
659
734
|
* sorting of the array of resources with "compareResourcesByKindAsc".
|
|
660
735
|
* @param resources array of resources to create
|
|
661
736
|
*/
|
|
737
|
+
|
|
738
|
+
|
|
662
739
|
async bulkCreateOrUpdate(resources, sortedDefsMap, version) {
|
|
663
|
-
log(`bulk create or update`);
|
|
664
|
-
|
|
740
|
+
log(`bulk create or update`); // sort() is modifying the existing array so cloning it before use.
|
|
741
|
+
|
|
665
742
|
const sortedDefsArray = Array.from(sortedDefsMap.values());
|
|
666
743
|
const sortedResources = [...resources].sort((0, _utils.compareResourcesByKindAsc)(sortedDefsArray));
|
|
667
744
|
const bulkResult = {
|
|
@@ -679,22 +756,29 @@ class ApiServerClient {
|
|
|
679
756
|
created: [],
|
|
680
757
|
updated: []
|
|
681
758
|
};
|
|
759
|
+
|
|
682
760
|
for (const resource of sortedResources) {
|
|
683
761
|
var _resource$metadata12, _resource$metadata13, _resource$metadata13$;
|
|
762
|
+
|
|
684
763
|
const resourceDef = sortedDefsArray.find(def => {
|
|
685
764
|
var _def$spec$scope3, _resource$metadata9, _resource$metadata9$s;
|
|
765
|
+
|
|
686
766
|
return def.spec.kind === resource.kind && ((_def$spec$scope3 = def.spec.scope) === null || _def$spec$scope3 === void 0 ? void 0 : _def$spec$scope3.kind) === ((_resource$metadata9 = resource.metadata) === null || _resource$metadata9 === void 0 ? void 0 : (_resource$metadata9$s = _resource$metadata9.scope) === null || _resource$metadata9$s === void 0 ? void 0 : _resource$metadata9$s.kind);
|
|
687
|
-
});
|
|
688
|
-
|
|
767
|
+
}); // the check below is already happening when loading the specs but checking again just in case.
|
|
768
|
+
|
|
689
769
|
if (!resourceDef) {
|
|
690
770
|
var _resource$metadata10, _resource$metadata10$;
|
|
771
|
+
|
|
691
772
|
let errorMessage = `No resource definition found for "kind/${resource.kind}"`;
|
|
773
|
+
|
|
692
774
|
if (!!((_resource$metadata10 = resource.metadata) !== null && _resource$metadata10 !== void 0 && (_resource$metadata10$ = _resource$metadata10.scope) !== null && _resource$metadata10$ !== void 0 && _resource$metadata10$.kind)) {
|
|
693
775
|
var _resource$metadata11, _resource$metadata11$;
|
|
776
|
+
|
|
694
777
|
errorMessage += ` in the scope "${(_resource$metadata11 = resource.metadata) === null || _resource$metadata11 === void 0 ? void 0 : (_resource$metadata11$ = _resource$metadata11.scope) === null || _resource$metadata11$ === void 0 ? void 0 : _resource$metadata11$.kind}".`;
|
|
695
778
|
} else {
|
|
696
779
|
errorMessage += ' with no scope.';
|
|
697
780
|
}
|
|
781
|
+
|
|
698
782
|
bulkResult.created.error.push({
|
|
699
783
|
name: resource.name || 'Unknown name',
|
|
700
784
|
kind: resource.kind,
|
|
@@ -702,21 +786,19 @@ class ApiServerClient {
|
|
|
702
786
|
});
|
|
703
787
|
continue;
|
|
704
788
|
}
|
|
789
|
+
|
|
705
790
|
const scopeDef = !!((_resource$metadata12 = resource.metadata) !== null && _resource$metadata12 !== void 0 && _resource$metadata12.scope) ? sortedDefsArray.find(def => def.spec.kind === resource.metadata.scope.kind && !def.spec.scope) : undefined;
|
|
706
|
-
const scopeName = (_resource$metadata13 = resource.metadata) === null || _resource$metadata13 === void 0 ? void 0 : (_resource$metadata13$ = _resource$metadata13.scope) === null || _resource$metadata13$ === void 0 ? void 0 : _resource$metadata13$.name;
|
|
791
|
+
const scopeName = (_resource$metadata13 = resource.metadata) === null || _resource$metadata13 === void 0 ? void 0 : (_resource$metadata13$ = _resource$metadata13.scope) === null || _resource$metadata13$ === void 0 ? void 0 : _resource$metadata13$.name; // only making getResource call if resource has a name
|
|
707
792
|
|
|
708
|
-
// only making getResource call if resource has a name
|
|
709
793
|
let getResult = resource.name ? await this.getResourceByName({
|
|
710
794
|
resourceDef,
|
|
711
795
|
resourceName: resource.name,
|
|
712
796
|
scopeDef,
|
|
713
797
|
scopeName
|
|
714
|
-
}) : null;
|
|
798
|
+
}) : null; // Create new resources first
|
|
715
799
|
|
|
716
|
-
// Create new resources first
|
|
717
800
|
if (!getResult || getResult !== null && getResult !== void 0 && getResult.error && getResult.error[0].status === 404) {
|
|
718
801
|
// Resource is not found, do the create
|
|
719
|
-
|
|
720
802
|
const res = await this.createResource({
|
|
721
803
|
resource,
|
|
722
804
|
resourceDef,
|
|
@@ -725,11 +807,13 @@ class ApiServerClient {
|
|
|
725
807
|
version,
|
|
726
808
|
withSubResources: false
|
|
727
809
|
});
|
|
810
|
+
|
|
728
811
|
if (res.data && !res.error) {
|
|
729
812
|
// note: bulk operation requires creation of sub-resources after all main resources created
|
|
730
813
|
// since a sub-resource might have a reference to another resource.
|
|
731
814
|
if (!!res.pending) {
|
|
732
815
|
var _res$warning2;
|
|
816
|
+
|
|
733
817
|
pendingSubResources.created.push({
|
|
734
818
|
mainResult: res.data,
|
|
735
819
|
pendingCalls: res.pending,
|
|
@@ -737,6 +821,7 @@ class ApiServerClient {
|
|
|
737
821
|
});
|
|
738
822
|
} else {
|
|
739
823
|
var _bulkResult$created$w;
|
|
824
|
+
|
|
740
825
|
if (res.warning) (_bulkResult$created$w = bulkResult.created.warning) === null || _bulkResult$created$w === void 0 ? void 0 : _bulkResult$created$w.push(res.data);else bulkResult.created.success.push(res.data);
|
|
741
826
|
}
|
|
742
827
|
} else if (res.error) {
|
|
@@ -759,9 +844,11 @@ class ApiServerClient {
|
|
|
759
844
|
version,
|
|
760
845
|
withSubResources: false
|
|
761
846
|
});
|
|
847
|
+
|
|
762
848
|
if (res.data && !res.error) {
|
|
763
849
|
if (!!res.pending) {
|
|
764
850
|
var _res$warning3;
|
|
851
|
+
|
|
765
852
|
pendingSubResources.updated.push({
|
|
766
853
|
mainResult: res.data,
|
|
767
854
|
pendingCalls: res.pending,
|
|
@@ -786,13 +873,15 @@ class ApiServerClient {
|
|
|
786
873
|
errors: getResult.error
|
|
787
874
|
};
|
|
788
875
|
}
|
|
789
|
-
}
|
|
876
|
+
} // creating sub-resources
|
|
877
|
+
|
|
790
878
|
|
|
791
|
-
// creating sub-resources
|
|
792
879
|
for (const p of pendingSubResources.created) {
|
|
793
880
|
const subResResult = await this.resolveSubResourcesRequests(p.mainResult, p.pendingCalls);
|
|
881
|
+
|
|
794
882
|
if (subResResult.data && !subResResult.error) {
|
|
795
883
|
var _bulkResult$created$w2;
|
|
884
|
+
|
|
796
885
|
if (p.withWarning) (_bulkResult$created$w2 = bulkResult.created.warning) === null || _bulkResult$created$w2 === void 0 ? void 0 : _bulkResult$created$w2.push(subResResult.data);else bulkResult.created.success.push(subResResult.data);
|
|
797
886
|
} else if (subResResult.error) {
|
|
798
887
|
for (const nextError of subResResult.error) {
|
|
@@ -803,10 +892,12 @@ class ApiServerClient {
|
|
|
803
892
|
});
|
|
804
893
|
}
|
|
805
894
|
}
|
|
806
|
-
}
|
|
807
|
-
|
|
895
|
+
} // creating sub-resources
|
|
896
|
+
|
|
897
|
+
|
|
808
898
|
for (const p of pendingSubResources.updated) {
|
|
809
899
|
const subResResult = await this.resolveSubResourcesRequests(p.mainResult, p.pendingCalls);
|
|
900
|
+
|
|
810
901
|
if (subResResult.data && !subResResult.error) {
|
|
811
902
|
bulkResult.updated.success.push(subResResult.data);
|
|
812
903
|
} else if (subResResult.error) {
|
|
@@ -819,41 +910,51 @@ class ApiServerClient {
|
|
|
819
910
|
}
|
|
820
911
|
}
|
|
821
912
|
}
|
|
913
|
+
|
|
822
914
|
return bulkResult;
|
|
823
915
|
}
|
|
824
|
-
|
|
825
916
|
/**
|
|
826
917
|
* Bulk deletion of resources.
|
|
827
918
|
* Order of calls calculated by sorting of the array of resources with "compareResourcesByKindDesc".
|
|
828
919
|
* @param resources array of resources to create
|
|
829
920
|
*/
|
|
921
|
+
|
|
922
|
+
|
|
830
923
|
async bulkDelete(resources, sortedDefsMap, wait, version) {
|
|
831
|
-
log(`bulk delete`);
|
|
832
|
-
|
|
924
|
+
log(`bulk delete`); // sort() is modifying the existing array so cloning it before use.
|
|
925
|
+
|
|
833
926
|
const sortedDefsArray = Array.from(sortedDefsMap.values());
|
|
834
927
|
const sortedResources = [...resources].sort((0, _utils.compareResourcesByKindDesc)(sortedDefsArray));
|
|
835
928
|
const bulkResult = {
|
|
836
929
|
success: [],
|
|
837
930
|
error: []
|
|
838
931
|
};
|
|
932
|
+
|
|
839
933
|
for (const resource of sortedResources) {
|
|
840
934
|
try {
|
|
841
935
|
var _resource$metadata15, _resource$metadata16, _resource$metadata16$;
|
|
936
|
+
|
|
842
937
|
const resourceDef = sortedDefsArray.find(def => {
|
|
843
938
|
var _def$spec$scope4, _resource$metadata14, _resource$metadata14$;
|
|
939
|
+
|
|
844
940
|
return def.spec.kind === resource.kind && ((_def$spec$scope4 = def.spec.scope) === null || _def$spec$scope4 === void 0 ? void 0 : _def$spec$scope4.kind) === ((_resource$metadata14 = resource.metadata) === null || _resource$metadata14 === void 0 ? void 0 : (_resource$metadata14$ = _resource$metadata14.scope) === null || _resource$metadata14$ === void 0 ? void 0 : _resource$metadata14$.kind);
|
|
845
941
|
});
|
|
846
942
|
const scopeDef = !!((_resource$metadata15 = resource.metadata) !== null && _resource$metadata15 !== void 0 && _resource$metadata15.scope) ? sortedDefsArray.find(def => def.spec.kind === resource.metadata.scope.kind && !def.spec.scope) : undefined;
|
|
847
943
|
const scopeName = (_resource$metadata16 = resource.metadata) === null || _resource$metadata16 === void 0 ? void 0 : (_resource$metadata16$ = _resource$metadata16.scope) === null || _resource$metadata16$ === void 0 ? void 0 : _resource$metadata16$.name;
|
|
944
|
+
|
|
848
945
|
if (!resourceDef) {
|
|
849
946
|
var _resource$metadata17, _resource$metadata17$;
|
|
947
|
+
|
|
850
948
|
let errorMessage = `No resource definition found for "kind/${resource.kind}"`;
|
|
949
|
+
|
|
851
950
|
if (!!((_resource$metadata17 = resource.metadata) !== null && _resource$metadata17 !== void 0 && (_resource$metadata17$ = _resource$metadata17.scope) !== null && _resource$metadata17$ !== void 0 && _resource$metadata17$.kind)) {
|
|
852
951
|
var _resource$metadata18, _resource$metadata18$;
|
|
952
|
+
|
|
853
953
|
errorMessage += ` in the scope "${(_resource$metadata18 = resource.metadata) === null || _resource$metadata18 === void 0 ? void 0 : (_resource$metadata18$ = _resource$metadata18.scope) === null || _resource$metadata18$ === void 0 ? void 0 : _resource$metadata18$.kind}".`;
|
|
854
954
|
} else {
|
|
855
955
|
errorMessage += ' with no scope.';
|
|
856
956
|
}
|
|
957
|
+
|
|
857
958
|
bulkResult.error.push({
|
|
858
959
|
name: resource.name || 'Unknown name',
|
|
859
960
|
kind: resource.kind,
|
|
@@ -861,6 +962,7 @@ class ApiServerClient {
|
|
|
861
962
|
});
|
|
862
963
|
continue;
|
|
863
964
|
}
|
|
965
|
+
|
|
864
966
|
const res = await this.deleteResourceByName({
|
|
865
967
|
resourceName: resource.name,
|
|
866
968
|
resourceDef,
|
|
@@ -868,6 +970,7 @@ class ApiServerClient {
|
|
|
868
970
|
scopeName,
|
|
869
971
|
version
|
|
870
972
|
});
|
|
973
|
+
|
|
871
974
|
if (res.error) {
|
|
872
975
|
for (const nextError of res.error) {
|
|
873
976
|
bulkResult.error.push({
|
|
@@ -897,25 +1000,28 @@ class ApiServerClient {
|
|
|
897
1000
|
}
|
|
898
1001
|
}
|
|
899
1002
|
}
|
|
1003
|
+
|
|
900
1004
|
if (wait) {
|
|
901
1005
|
let pendingResources = [];
|
|
902
1006
|
pendingResources = await this.checkForResources(sortedResources, sortedDefsArray);
|
|
903
1007
|
const pendingDeletingResource = pendingResources.some(res => res === null || res === void 0 ? void 0 : res.data);
|
|
1008
|
+
|
|
904
1009
|
if (pendingDeletingResource) {
|
|
905
1010
|
setTimeout(async () => {
|
|
906
1011
|
pendingResources = await this.checkForResources(sortedResources, sortedDefsArray);
|
|
907
1012
|
}, _types.WAIT_TIMEOUT);
|
|
908
1013
|
const stillPending = pendingResources.some(res => res === null || res === void 0 ? void 0 : res.data);
|
|
1014
|
+
|
|
909
1015
|
if (stillPending) {
|
|
910
1016
|
const pendingResNames = pendingResources.map(res => {
|
|
911
1017
|
var _res$data;
|
|
1018
|
+
|
|
912
1019
|
return res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.name;
|
|
913
1020
|
});
|
|
914
1021
|
bulkResult.success.forEach((res, index) => pendingResNames.includes(res.name) && bulkResult.success.splice(index, 1));
|
|
915
1022
|
pendingResources.forEach(res => {
|
|
916
1023
|
if (res !== null && res !== void 0 && res.data) {
|
|
917
|
-
bulkResult.error.push({
|
|
918
|
-
...res.data,
|
|
1024
|
+
bulkResult.error.push({ ...res.data,
|
|
919
1025
|
error: {
|
|
920
1026
|
detail: 'Not deleted yet.'
|
|
921
1027
|
}
|
|
@@ -925,7 +1031,10 @@ class ApiServerClient {
|
|
|
925
1031
|
} else return bulkResult;
|
|
926
1032
|
} else return bulkResult;
|
|
927
1033
|
}
|
|
1034
|
+
|
|
928
1035
|
return bulkResult;
|
|
929
1036
|
}
|
|
1037
|
+
|
|
930
1038
|
}
|
|
1039
|
+
|
|
931
1040
|
exports.ApiServerClient = ApiServerClient;
|