mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
* refactor(http): parse axios errors (#6325) * refactor(home): use endpoint-list as react component [EE-1814] (#6060) * refactor(home): use endpoint-list as react component fix(home): add missing features and refactors - kubebutton - group name - poll when endpoint is off - state management refactor(endpoints): use stat component fix(endpoints): add space between items refactor(endpoints): move stats to components refactor(endpoints): fetch time refactor(home): move logic refactor(home): move fe render logic refactor(settings): use vanilla js for publicSettings refactor(kube): remove angular from kube config service feat(home): add kubeconfig button feat(home): send analytics when opening kubeconfig modal fix(home): memoize footer refactor(home): use react-query for loading fix(home): show correct control for kubeconfig modal refactor(home): use debounce refactor(home): use new components refactor(home): replace endpoints with environments refactor(home): move endpoint-list component to home fix(home): show group name refactor(home): use switch for environment icon fix(kubeconfig): fix default case refactor(axios): use parse axios error refactor(home): use link components for navigate fix(home): align azure icon refactor(home): refactor stats refactor(home): export envstatusbadge refactor(home): remove unused bindings * chore(home): write tests for edge indicator * chore(home): basic stories for environment item * style(settings): reformat * fix(environments): add publicurl * refactor(home): use table components * refactor(datatables): merge useSearchBarState * refactor(home): fetch group in env item * chore(tests): basic tests * chore(home): test when no envs * refactor(tags): use axios for tagService * refactor(env-groups): use axios for getGroups * feat(app): ui-state context provider * refactor(home): create MotdPanel * refactor(app): create InformationPanel * feat(endpoints): fetch number of total endpoints * refactor(app): merge hooks * refactor(home): migrate view to react [EE-1810] fixes [EE-1810] refactor(home): wip use react view feat(home): show message if no endpoints refactor(home): show endpoint list refactor(home): don't use home to manage link refactor(home): move state refactor(home): check if edge using util refactor(home): move inf panels chore(home): tests refactor(home): load groups and tags in env-item refactor(settings): revert publicSettings change refactor(home): move confirm snapshot method * fix(home): show tags * fix(environments): handle missing snapshots * fix(kube/volumes): fetch pesistent volume claims * refactor(kube): remove use of endpointProvider * refactor(endpoints): set current endpoint * chore(home): add data-cy for tests * chore(tests): mock axios-progress-bar * refactor(home): move use env list to env module * feat(app): sync home view changes with ee * fix(home): sort page header * fix(app): fix tests * chore(github): use yarn cache * refactor(environments): load list of groups * chore(babel): remove auto 18n keys extraction * chore(environments): fix tests * refactor(k8s/application): use current endpoint * fix(app/header): add margin to header * refactor(app): remove unused types * refactor(app): use rq onError handler * refactor(home): wrap element with button
121 lines
4.1 KiB
JavaScript
121 lines
4.1 KiB
JavaScript
import _ from 'lodash-es';
|
|
import filesizeParser from 'filesize-parser';
|
|
import angular from 'angular';
|
|
import KubernetesVolumeHelper from 'Kubernetes/helpers/volumeHelper';
|
|
import KubernetesResourceQuotaHelper from 'Kubernetes/helpers/resourceQuotaHelper';
|
|
|
|
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) {
|
|
const size = _.sumBy(volumes, (v) => filesizeParser(v.PersistentVolumeClaim.Storage, { base: 10 }));
|
|
const format = KubernetesResourceQuotaHelper.formatBytes(size);
|
|
return `${format.Size}${format.SizeUnit}`;
|
|
}
|
|
|
|
class KubernetesVolumesController {
|
|
/* @ngInject */
|
|
constructor($async, $state, Notifications, Authentication, ModalService, LocalStorage, KubernetesStorageService, KubernetesVolumeService, KubernetesApplicationService) {
|
|
this.$async = $async;
|
|
this.$state = $state;
|
|
this.Notifications = Notifications;
|
|
this.Authentication = Authentication;
|
|
this.ModalService = ModalService;
|
|
this.LocalStorage = LocalStorage;
|
|
this.KubernetesStorageService = KubernetesStorageService;
|
|
this.KubernetesVolumeService = KubernetesVolumeService;
|
|
this.KubernetesApplicationService = KubernetesApplicationService;
|
|
|
|
this.onInit = this.onInit.bind(this);
|
|
this.getVolumes = this.getVolumes.bind(this);
|
|
this.getVolumesAsync = this.getVolumesAsync.bind(this);
|
|
this.removeAction = this.removeAction.bind(this);
|
|
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) {
|
|
try {
|
|
await this.KubernetesVolumeService.delete(volume);
|
|
this.Notifications.success('Volume successfully removed', volume.PersistentVolumeClaim.Name);
|
|
const index = this.volumes.indexOf(volume);
|
|
this.volumes.splice(index, 1);
|
|
} catch (err) {
|
|
this.Notifications.error('Failure', err, 'Unable to remove volume');
|
|
} finally {
|
|
--actionCount;
|
|
if (actionCount === 0) {
|
|
this.$state.reload(this.$state.current);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
removeAction(selectedItems) {
|
|
this.ModalService.confirmDeletion('Do you want to remove the selected volume(s)?', (confirmed) => {
|
|
if (confirmed) {
|
|
return this.$async(this.removeActionAsync, selectedItems);
|
|
}
|
|
});
|
|
}
|
|
|
|
async getVolumesAsync() {
|
|
const storageClasses = this.endpoint.Kubernetes.Configuration.StorageClasses;
|
|
try {
|
|
const [volumes, applications, storages] = await Promise.all([
|
|
this.KubernetesVolumeService.get(undefined, storageClasses),
|
|
this.KubernetesApplicationService.get(),
|
|
this.KubernetesStorageService.get(this.endpoint.Id),
|
|
]);
|
|
|
|
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 namespaces');
|
|
}
|
|
}
|
|
|
|
getVolumes() {
|
|
return this.$async(this.getVolumesAsync);
|
|
}
|
|
|
|
async onInit() {
|
|
this.state = {
|
|
viewReady: false,
|
|
currentName: this.$state.$current.name,
|
|
activeTab: this.LocalStorage.getActiveTab('volumes'),
|
|
isAdmin: this.Authentication.isAdmin(),
|
|
};
|
|
|
|
await this.getVolumes();
|
|
|
|
this.state.viewReady = true;
|
|
}
|
|
|
|
$onInit() {
|
|
return this.$async(this.onInit);
|
|
}
|
|
|
|
$onDestroy() {
|
|
if (this.state.currentName !== this.$state.$current.name) {
|
|
this.LocalStorage.storeActiveTab('volumes', 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
export default KubernetesVolumesController;
|
|
angular.module('portainer.kubernetes').controller('KubernetesVolumesController', KubernetesVolumesController);
|