From 6ee5cc6a56dd6181d9165d6eb5bb5c78f5eb5f38 Mon Sep 17 00:00:00 2001 From: Prabhat Khera <91852476+prabhat-org@users.noreply.github.com> Date: Thu, 16 Mar 2023 10:10:37 +1300 Subject: [PATCH] fix(ui): namespace cache refresh on reload EE-5155 (#8644) --- .../helm/helm-templates/helm-templates.controller.js | 4 +++- app/kubernetes/services/namespaceService.js | 11 ++++++----- app/kubernetes/services/resourcePoolService.js | 4 ++-- .../views/applications/applicationsController.js | 2 +- .../create/createApplicationController.js | 5 ++++- .../create/createConfigurationController.js | 5 ++++- app/kubernetes/views/configure/configureController.js | 5 ++++- app/kubernetes/views/deploy/deployController.js | 3 ++- .../views/resource-pools/resourcePoolsController.js | 4 ++-- 9 files changed, 28 insertions(+), 15 deletions(-) diff --git a/app/kubernetes/components/helm/helm-templates/helm-templates.controller.js b/app/kubernetes/components/helm/helm-templates/helm-templates.controller.js index 957dcc911..7af3f3436 100644 --- a/app/kubernetes/components/helm/helm-templates/helm-templates.controller.js +++ b/app/kubernetes/components/helm/helm-templates/helm-templates.controller.js @@ -141,7 +141,9 @@ export default class HelmTemplatesController { try { const resourcePools = await this.KubernetesResourcePoolService.get(); - const nonSystemNamespaces = resourcePools.filter((resourcePool) => !KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name)); + const nonSystemNamespaces = resourcePools.filter( + (resourcePool) => !KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name) && resourcePool.Namespace.Status === 'Active' + ); this.state.resourcePools = _.sortBy(nonSystemNamespaces, ({ Namespace }) => (Namespace.Name === 'default' ? 0 : 1)); this.state.resourcePool = this.state.resourcePools[0]; } catch (err) { diff --git a/app/kubernetes/services/namespaceService.js b/app/kubernetes/services/namespaceService.js index fe54c1800..6d82c3e3c 100644 --- a/app/kubernetes/services/namespaceService.js +++ b/app/kubernetes/services/namespaceService.js @@ -81,18 +81,19 @@ class KubernetesNamespaceService { } } - async get(name) { + async get(name, refreshCache = false) { if (name) { return this.$async(this.getAsync, name); } const cachedAllowedNamespaces = this.LocalStorage.getAllowedNamespaces(); - if (cachedAllowedNamespaces) { - updateNamespaces(cachedAllowedNamespaces); - return cachedAllowedNamespaces; - } else { + if (!cachedAllowedNamespaces || refreshCache) { const allowedNamespaces = await this.getAllAsync(); this.LocalStorage.storeAllowedNamespaces(allowedNamespaces); + updateNamespaces(allowedNamespaces); return allowedNamespaces; + } else { + updateNamespaces(cachedAllowedNamespaces); + return cachedAllowedNamespaces; } } diff --git a/app/kubernetes/services/resourcePoolService.js b/app/kubernetes/services/resourcePoolService.js index 639c44db1..1b0f03b26 100644 --- a/app/kubernetes/services/resourcePoolService.js +++ b/app/kubernetes/services/resourcePoolService.js @@ -36,8 +36,8 @@ export function KubernetesResourcePoolService( } // getting the quota for all namespaces is costly by default, so disable getting it by default - async function getAll({ getQuota = false }) { - const namespaces = await KubernetesNamespaceService.get(); + async function getAll({ getQuota = false, refreshCache = false }) { + const namespaces = await KubernetesNamespaceService.get('', refreshCache); const pools = await Promise.all( _.map(namespaces, async (namespace) => { const name = namespace.Name; diff --git a/app/kubernetes/views/applications/applicationsController.js b/app/kubernetes/views/applications/applicationsController.js index 028a7d927..ceeb83fe1 100644 --- a/app/kubernetes/views/applications/applicationsController.js +++ b/app/kubernetes/views/applications/applicationsController.js @@ -189,7 +189,7 @@ class KubernetesApplicationsController { }; this.state.namespaces = await this.KubernetesNamespaceService.get(); - this.state.namespaces = this.state.namespaces.filter((n) => n.Status !== 'Terminating'); + this.state.namespaces = this.state.namespaces.filter((n) => n.Status === 'Active'); this.state.namespaces = _.sortBy(this.state.namespaces, 'Name'); this.state.namespace = this.state.namespaces.length ? (this.state.namespaces.find((n) => n.Name === 'default') ? 'default' : this.state.namespaces[0].Name) : ''; diff --git a/app/kubernetes/views/applications/create/createApplicationController.js b/app/kubernetes/views/applications/create/createApplicationController.js index cc069ef80..8fcff5d04 100644 --- a/app/kubernetes/views/applications/create/createApplicationController.js +++ b/app/kubernetes/views/applications/create/createApplicationController.js @@ -1208,7 +1208,10 @@ class KubernetesCreateApplicationController { ]); this.nodesLimits = nodesLimits; - const nonSystemNamespaces = _.filter(resourcePools, (resourcePool) => !KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name)); + const nonSystemNamespaces = _.filter( + resourcePools, + (resourcePool) => !KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name) && resourcePool.Namespace.Status === 'Active' + ); this.allNamespaces = resourcePools.map(({ Namespace }) => Namespace.Name); this.resourcePools = _.sortBy(nonSystemNamespaces, ({ Namespace }) => (Namespace.Name === 'default' ? 0 : 1)); diff --git a/app/kubernetes/views/configurations/create/createConfigurationController.js b/app/kubernetes/views/configurations/create/createConfigurationController.js index 7be02d396..4b4ecc0f4 100644 --- a/app/kubernetes/views/configurations/create/createConfigurationController.js +++ b/app/kubernetes/views/configurations/create/createConfigurationController.js @@ -196,7 +196,10 @@ class KubernetesCreateConfigurationController { try { const resourcePools = await this.KubernetesResourcePoolService.get(); - this.resourcePools = _.filter(resourcePools, (resourcePool) => !KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name)); + this.resourcePools = _.filter( + resourcePools, + (resourcePool) => !KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name) && resourcePool.Namespace.Status === 'Active' + ); this.formValues.ResourcePool = this.resourcePools[0]; await this.getConfigurations(); diff --git a/app/kubernetes/views/configure/configureController.js b/app/kubernetes/views/configure/configureController.js index dc2248340..a3354dec4 100644 --- a/app/kubernetes/views/configure/configureController.js +++ b/app/kubernetes/views/configure/configureController.js @@ -165,7 +165,10 @@ class KubernetesConfigureController { const allResourcePools = await this.KubernetesResourcePoolService.get(); const resourcePools = _.filter( allResourcePools, - (resourcePool) => !KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name) && !KubernetesNamespaceHelper.isDefaultNamespace(resourcePool.Namespace.Name) + (resourcePool) => + !KubernetesNamespaceHelper.isSystemNamespace(resourcePool.Namespace.Name) && + !KubernetesNamespaceHelper.isDefaultNamespace(resourcePool.Namespace.Name) && + resourcePool.Namespace.Status === 'Active' ); ingressesToDel.forEach((ingress) => { diff --git a/app/kubernetes/views/deploy/deployController.js b/app/kubernetes/views/deploy/deployController.js index aa66134f9..d10734791 100644 --- a/app/kubernetes/views/deploy/deployController.js +++ b/app/kubernetes/views/deploy/deployController.js @@ -284,7 +284,8 @@ class KubernetesDeployController { async getNamespacesAsync() { try { const pools = await this.KubernetesResourcePoolService.get(); - const namespaces = _.map(pools, 'Namespace').sort((a, b) => { + let namespaces = pools.filter((pool) => pool.Namespace.Status === 'Active'); + namespaces = _.map(namespaces, 'Namespace').sort((a, b) => { if (a.Name === 'default') { return -1; } diff --git a/app/kubernetes/views/resource-pools/resourcePoolsController.js b/app/kubernetes/views/resource-pools/resourcePoolsController.js index 55fd2a3ed..b487bb7c7 100644 --- a/app/kubernetes/views/resource-pools/resourcePoolsController.js +++ b/app/kubernetes/views/resource-pools/resourcePoolsController.js @@ -50,11 +50,11 @@ class KubernetesResourcePoolsController { } finally { --actionCount; if (actionCount === 0) { + await this.KubernetesNamespaceService.refreshCacheAsync(); this.$state.reload(this.$state.current); } } } - await this.KubernetesNamespaceService.refreshCacheAsync(); } removeAction(selectedItems) { @@ -77,7 +77,7 @@ class KubernetesResourcePoolsController { async getResourcePoolsAsync() { try { - this.resourcePools = await this.KubernetesResourcePoolService.get('', { getQuota: true }); + this.resourcePools = await this.KubernetesResourcePoolService.get('', { getQuota: true, refreshCache: true }); } catch (err) { this.Notifications.error('Failure', err, 'Unable to retreive namespaces'); }