diff --git a/lib/BaseDownloadController.js b/lib/BaseDownloadController.js index a57904d..203f244 100644 --- a/lib/BaseDownloadController.js +++ b/lib/BaseDownloadController.js @@ -1,5 +1,5 @@ /* - * Copyright 2019 IBM Corp. All Rights Reserved. + * Copyright 2019, 2024 IBM Corp. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,13 @@ const hash = require('object-hash'); const clone = require('clone'); const pLimit = require('p-limit'); +// Limit concurrent check and save of kube resources in `_saveChild()`. +// This limit will apply across separate BaseDownloadController instances, +// e.g. to prevent either large numbers of RemoteResources OR large +// numbers of kube resources in RemoteResources from flooding the +// Kubernetes API. +const globalLimit = pLimit(10); + const CompositeController = require('./CompositeController'); const FetchEnvs = require('./FetchEnvs'); @@ -29,11 +36,6 @@ module.exports = class BaseDownloadController extends CompositeController { constructor(params) { params.finalizerString = params.finalizerString || 'children.downloads.deploy.razee.io'; super(params); - this._limit = pLimit(5); - } - - get limit() { - return this._limit; } async added() { @@ -282,7 +284,8 @@ module.exports = class BaseDownloadController extends CompositeController { } async _saveChild(child) { - let res = await this.limit(async () => { + // Limit concurrency to prevent flooding the Kubernetes API + let res = await globalLimit(async () => { return await this.applyChild(child); });