1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-23 15:29:42 +02:00
portainer/app/kubernetes/views/dashboard/dashboardController.js
Chaim Lev-Ari 1830a80a61
feat(k8s/resource-pool): add the ability to mark/unmark resource pool as system (#5360)
* feat(k8s/resource-pool): add the ability to mark/unmark resource pool as system

fix(kube/ns): check label to see if namespace is system

refactor(k8s/namespaces): rename variables

feat(kubernetes): toggle system state in the server (#5361)

fix(app/resource-pool): UI fixes

feat(app/resource-pool): add confirmation modal when unamrking system namespace

* refactor(app): review changes

* feat(app/namespaces): introduce store to retrieve namespace system status without changing all the kubernetes models

refactor(app/namespaces): remove unused code first introduced for system tagging

fix(app/namespaces): cache namespaces to retrieve system status regardless of namespace reference format

refactor(app): migrate namespace store from helper to a separate singleton

refactor(app): remove KubernetesNamespaceHelper from DI cycle

* refactor(app): normalize usage of KubernetesNamespaceHelper functions

* refactor(app/k8s): change namespace store to functions instead of class

Co-authored-by: LP B <xAt0mZ@users.noreply.github.com>
2021-08-26 16:00:59 +02:00

98 lines
3 KiB
JavaScript

import angular from 'angular';
import _ from 'lodash-es';
import KubernetesConfigurationHelper from 'Kubernetes/helpers/configurationHelper';
import KubernetesNamespaceHelper from 'Kubernetes/helpers/namespaceHelper';
class KubernetesDashboardController {
/* @ngInject */
constructor(
$async,
Notifications,
EndpointService,
EndpointProvider,
KubernetesResourcePoolService,
KubernetesApplicationService,
KubernetesConfigurationService,
KubernetesVolumeService,
Authentication,
TagService
) {
this.$async = $async;
this.Notifications = Notifications;
this.EndpointService = EndpointService;
this.EndpointProvider = EndpointProvider;
this.KubernetesResourcePoolService = KubernetesResourcePoolService;
this.KubernetesApplicationService = KubernetesApplicationService;
this.KubernetesConfigurationService = KubernetesConfigurationService;
this.KubernetesVolumeService = KubernetesVolumeService;
this.Authentication = Authentication;
this.TagService = TagService;
this.onInit = this.onInit.bind(this);
this.getAll = this.getAll.bind(this);
this.getAllAsync = this.getAllAsync.bind(this);
}
async getAllAsync() {
const isAdmin = this.Authentication.isAdmin();
try {
const endpointId = this.EndpointProvider.endpointID();
const [endpoint, pools, applications, configurations, volumes, tags] = await Promise.all([
this.EndpointService.endpoint(endpointId),
this.KubernetesResourcePoolService.get(),
this.KubernetesApplicationService.get(),
this.KubernetesConfigurationService.get(),
this.KubernetesVolumeService.get(),
this.TagService.tags(),
]);
this.endpoint = endpoint;
this.applications = applications;
this.volumes = volumes;
this.endpointTags = this.endpoint.TagIds.length
? _.join(
_.filter(
_.map(this.endpoint.TagIds, (id) => {
const tag = tags.find((tag) => tag.Id === id);
return tag ? tag.Name : '';
}),
Boolean
),
', '
)
: '-';
if (!isAdmin) {
this.pools = _.filter(pools, (pool) => !KubernetesNamespaceHelper.isSystemNamespace(pool.Namespace.Name));
this.configurations = _.filter(configurations, (config) => !KubernetesConfigurationHelper.isSystemToken(config));
} else {
this.pools = pools;
this.configurations = configurations;
}
} catch (err) {
this.Notifications.error('Failure', err, 'Unable to load dashboard data');
}
}
getAll() {
return this.$async(this.getAllAsync);
}
async onInit() {
this.state = {
viewReady: false,
};
await this.getAll();
this.state.viewReady = true;
}
$onInit() {
return this.$async(this.onInit);
}
}
export default KubernetesDashboardController;
angular.module('portainer.kubernetes').controller('KubernetesDashboardController', KubernetesDashboardController);