mirror of https://github.com/portainer/portainer
fix(ui): namespace cache refresh on reload EE-5155 (#8644)
parent
44582732bb
commit
6ee5cc6a56
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) : '';
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue