mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
feat(k8s/volumes): introduce storage rollup panel (#4055)
* feat(k8s/applications): storages rollup panel * feat(k8s/volumes): move storages table to volumes view * feat(k8s/volumes): minor UI update * feat(k8s/volumes): remember the selected tab * feat(api/k8s): update user default policies * feat(k8s/ui): minor UI update Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>
This commit is contained in:
parent
99db41f96e
commit
3953acf110
12 changed files with 336 additions and 23 deletions
|
@ -1,14 +1,52 @@
|
|||
import _ from 'lodash-es';
|
||||
import * as _ from 'lodash-es';
|
||||
import filesizeParser from 'filesize-parser';
|
||||
import angular from 'angular';
|
||||
import KubernetesVolumeHelper from 'Kubernetes/helpers/volumeHelper';
|
||||
|
||||
function buildStorages(storages, volumes) {
|
||||
_.forEach(storages, (s) => {
|
||||
const filteredVolumes = _.filter(volumes, ['PersistentVolumeClaim.StorageClass.Name', s.Name, 'PersistentVolumeClaim.StorageClass.Provisioner', s.Provisioner]);
|
||||
s.Volumes = filteredVolumes;
|
||||
s.Size = computeSize(filteredVolumes);
|
||||
});
|
||||
return storages;
|
||||
}
|
||||
|
||||
function computeSize(volumes) {
|
||||
let hasT,
|
||||
hasG,
|
||||
hasM = false;
|
||||
const size = _.sumBy(volumes, (v) => {
|
||||
const storage = v.PersistentVolumeClaim.Storage;
|
||||
if (!hasT && _.endsWith(storage, 'TB')) {
|
||||
hasT = true;
|
||||
} else if (!hasG && _.endsWith(storage, 'GB')) {
|
||||
hasG = true;
|
||||
} else if (!hasM && _.endsWith(storage, 'MB')) {
|
||||
hasM = true;
|
||||
}
|
||||
return filesizeParser(storage, { base: 10 });
|
||||
});
|
||||
if (hasT) {
|
||||
return size / 1000 / 1000 / 1000 / 1000 + 'TB';
|
||||
} else if (hasG) {
|
||||
return size / 1000 / 1000 / 1000 + 'GB';
|
||||
} else if (hasM) {
|
||||
return size / 1000 / 1000 + 'MB';
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
class KubernetesVolumesController {
|
||||
/* @ngInject */
|
||||
constructor($async, $state, Notifications, ModalService, KubernetesVolumeService, KubernetesApplicationService) {
|
||||
constructor($async, $state, Notifications, ModalService, LocalStorage, EndpointProvider, KubernetesStorageService, KubernetesVolumeService, KubernetesApplicationService) {
|
||||
this.$async = $async;
|
||||
this.$state = $state;
|
||||
this.Notifications = Notifications;
|
||||
this.ModalService = ModalService;
|
||||
this.LocalStorage = LocalStorage;
|
||||
this.EndpointProvider = EndpointProvider;
|
||||
this.KubernetesStorageService = KubernetesStorageService;
|
||||
this.KubernetesVolumeService = KubernetesVolumeService;
|
||||
this.KubernetesApplicationService = KubernetesApplicationService;
|
||||
|
||||
|
@ -19,6 +57,10 @@ class KubernetesVolumesController {
|
|||
this.removeActionAsync = this.removeActionAsync.bind(this);
|
||||
}
|
||||
|
||||
selectTab(index) {
|
||||
this.LocalStorage.storeActiveTab('volumes', index);
|
||||
}
|
||||
|
||||
async removeActionAsync(selectedItems) {
|
||||
let actionCount = selectedItems.length;
|
||||
for (const volume of selectedItems) {
|
||||
|
@ -48,12 +90,17 @@ class KubernetesVolumesController {
|
|||
|
||||
async getVolumesAsync() {
|
||||
try {
|
||||
const [volumes, applications] = await Promise.all([this.KubernetesVolumeService.get(), this.KubernetesApplicationService.get()]);
|
||||
const [volumes, applications, storages] = await Promise.all([
|
||||
this.KubernetesVolumeService.get(),
|
||||
this.KubernetesApplicationService.get(),
|
||||
this.KubernetesStorageService.get(this.state.endpointId),
|
||||
]);
|
||||
|
||||
this.volumes = _.map(volumes, (volume) => {
|
||||
volume.Applications = KubernetesVolumeHelper.getUsingApplications(volume, applications);
|
||||
return volume;
|
||||
});
|
||||
this.storages = buildStorages(storages, volumes);
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to retreive resource pools');
|
||||
}
|
||||
|
@ -66,6 +113,10 @@ class KubernetesVolumesController {
|
|||
async onInit() {
|
||||
this.state = {
|
||||
viewReady: false,
|
||||
// endpointId: this.$transition$.params().endpointId, // TODO: use this when moving to endpointID in URL
|
||||
currentName: this.$state.$current.name,
|
||||
endpointId: this.EndpointProvider.endpointID(),
|
||||
activeTab: this.LocalStorage.getActiveTab('volumes'),
|
||||
};
|
||||
|
||||
await this.getVolumes();
|
||||
|
@ -76,6 +127,12 @@ class KubernetesVolumesController {
|
|||
$onInit() {
|
||||
return this.$async(this.onInit);
|
||||
}
|
||||
|
||||
$onDestroy() {
|
||||
if (this.state.currentName !== this.$state.$current.name) {
|
||||
this.LocalStorage.storeActiveTab('volumes', 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default KubernetesVolumesController;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue