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