mirror of https://github.com/portainer/portainer
fix(ui): namespace cache refresh on reload EE-5155 (#8657)
parent
47478efd1e
commit
fbc1a2d44d
|
@ -141,7 +141,9 @@ export default class HelmTemplatesController {
|
||||||
try {
|
try {
|
||||||
const resourcePools = await this.KubernetesResourcePoolService.get();
|
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.resourcePools = _.sortBy(nonSystemNamespaces, ({ Namespace }) => (Namespace.Name === 'default' ? 0 : 1));
|
||||||
this.state.resourcePool = this.state.resourcePools[0];
|
this.state.resourcePool = this.state.resourcePools[0];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -81,18 +81,19 @@ class KubernetesNamespaceService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(name) {
|
async get(name, refreshCache = false) {
|
||||||
if (name) {
|
if (name) {
|
||||||
return this.$async(this.getAsync, name);
|
return this.$async(this.getAsync, name);
|
||||||
}
|
}
|
||||||
const cachedAllowedNamespaces = this.LocalStorage.getAllowedNamespaces();
|
const cachedAllowedNamespaces = this.LocalStorage.getAllowedNamespaces();
|
||||||
if (cachedAllowedNamespaces) {
|
if (!cachedAllowedNamespaces || refreshCache) {
|
||||||
updateNamespaces(cachedAllowedNamespaces);
|
|
||||||
return cachedAllowedNamespaces;
|
|
||||||
} else {
|
|
||||||
const allowedNamespaces = await this.getAllAsync();
|
const allowedNamespaces = await this.getAllAsync();
|
||||||
this.LocalStorage.storeAllowedNamespaces(allowedNamespaces);
|
this.LocalStorage.storeAllowedNamespaces(allowedNamespaces);
|
||||||
|
updateNamespaces(allowedNamespaces);
|
||||||
return 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
|
// getting the quota for all namespaces is costly by default, so disable getting it by default
|
||||||
async function getAll({ getQuota = false }) {
|
async function getAll({ getQuota = false, refreshCache = false }) {
|
||||||
const namespaces = await KubernetesNamespaceService.get();
|
const namespaces = await KubernetesNamespaceService.get('', refreshCache);
|
||||||
const pools = await Promise.all(
|
const pools = await Promise.all(
|
||||||
_.map(namespaces, async (namespace) => {
|
_.map(namespaces, async (namespace) => {
|
||||||
const name = namespace.Name;
|
const name = namespace.Name;
|
||||||
|
|
|
@ -189,7 +189,7 @@ class KubernetesApplicationsController {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.state.namespaces = await this.KubernetesNamespaceService.get();
|
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.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) : '';
|
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;
|
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.allNamespaces = resourcePools.map(({ Namespace }) => Namespace.Name);
|
||||||
this.resourcePools = _.sortBy(nonSystemNamespaces, ({ Namespace }) => (Namespace.Name === 'default' ? 0 : 1));
|
this.resourcePools = _.sortBy(nonSystemNamespaces, ({ Namespace }) => (Namespace.Name === 'default' ? 0 : 1));
|
||||||
|
|
|
@ -196,7 +196,10 @@ class KubernetesCreateConfigurationController {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resourcePools = await this.KubernetesResourcePoolService.get();
|
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];
|
this.formValues.ResourcePool = this.resourcePools[0];
|
||||||
await this.getConfigurations();
|
await this.getConfigurations();
|
||||||
|
|
|
@ -165,7 +165,10 @@ class KubernetesConfigureController {
|
||||||
const allResourcePools = await this.KubernetesResourcePoolService.get();
|
const allResourcePools = await this.KubernetesResourcePoolService.get();
|
||||||
const resourcePools = _.filter(
|
const resourcePools = _.filter(
|
||||||
allResourcePools,
|
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) => {
|
ingressesToDel.forEach((ingress) => {
|
||||||
|
|
|
@ -284,7 +284,8 @@ class KubernetesDeployController {
|
||||||
async getNamespacesAsync() {
|
async getNamespacesAsync() {
|
||||||
try {
|
try {
|
||||||
const pools = await this.KubernetesResourcePoolService.get();
|
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') {
|
if (a.Name === 'default') {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,11 +50,11 @@ class KubernetesResourcePoolsController {
|
||||||
} finally {
|
} finally {
|
||||||
--actionCount;
|
--actionCount;
|
||||||
if (actionCount === 0) {
|
if (actionCount === 0) {
|
||||||
|
await this.KubernetesNamespaceService.refreshCacheAsync();
|
||||||
this.$state.reload(this.$state.current);
|
this.$state.reload(this.$state.current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.KubernetesNamespaceService.refreshCacheAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAction(selectedItems) {
|
removeAction(selectedItems) {
|
||||||
|
@ -77,7 +77,7 @@ class KubernetesResourcePoolsController {
|
||||||
|
|
||||||
async getResourcePoolsAsync() {
|
async getResourcePoolsAsync() {
|
||||||
try {
|
try {
|
||||||
this.resourcePools = await this.KubernetesResourcePoolService.get('', { getQuota: true });
|
this.resourcePools = await this.KubernetesResourcePoolService.get('', { getQuota: true, refreshCache: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to retreive namespaces');
|
this.Notifications.error('Failure', err, 'Unable to retreive namespaces');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue