Skip to content

Commit 3a59b21

Browse files
authored
limit concurrency (#404)
1 parent e84b538 commit 3a59b21

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/BaseDownloadController.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 IBM Corp. All Rights Reserved.
2+
* Copyright 2019, 2024 IBM Corp. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,13 @@ const hash = require('object-hash');
2121
const clone = require('clone');
2222
const pLimit = require('p-limit');
2323

24+
// Limit concurrent check and save of kube resources in `_saveChild()`.
25+
// This limit will apply across separate BaseDownloadController instances,
26+
// e.g. to prevent either large numbers of RemoteResources OR large
27+
// numbers of kube resources in RemoteResources from flooding the
28+
// Kubernetes API.
29+
const globalLimit = pLimit(10);
30+
2431
const CompositeController = require('./CompositeController');
2532

2633
const FetchEnvs = require('./FetchEnvs');
@@ -29,11 +36,6 @@ module.exports = class BaseDownloadController extends CompositeController {
2936
constructor(params) {
3037
params.finalizerString = params.finalizerString || 'children.downloads.deploy.razee.io';
3138
super(params);
32-
this._limit = pLimit(5);
33-
}
34-
35-
get limit() {
36-
return this._limit;
3739
}
3840

3941
async added() {
@@ -282,7 +284,8 @@ module.exports = class BaseDownloadController extends CompositeController {
282284
}
283285

284286
async _saveChild(child) {
285-
let res = await this.limit(async () => {
287+
// Limit concurrency to prevent flooding the Kubernetes API
288+
let res = await globalLimit(async () => {
286289
return await this.applyChild(child);
287290
});
288291

0 commit comments

Comments
 (0)