diff --git a/app/kubernetes/views/cluster/cluster.html b/app/kubernetes/views/cluster/cluster.html index f64e517b5..a970a29b9 100644 --- a/app/kubernetes/views/cluster/cluster.html +++ b/app/kubernetes/views/cluster/cluster.html @@ -17,7 +17,7 @@ cpu-limit="ctrl.CPULimit" memory-reservation="ctrl.resourceReservation.Memory" memory-limit="ctrl.MemoryLimit" - display-usage="ctrl.isAdmin" + display-usage="ctrl.hasResourceUsageAccess()" cpu-usage="ctrl.resourceUsage.CPU" memory-usage="ctrl.resourceUsage.Memory" > diff --git a/app/kubernetes/views/cluster/clusterController.js b/app/kubernetes/views/cluster/clusterController.js index 3b78e230d..1c695d042 100644 --- a/app/kubernetes/views/cluster/clusterController.js +++ b/app/kubernetes/views/cluster/clusterController.js @@ -36,6 +36,7 @@ class KubernetesClusterController { this.getComponentStatus = this.getComponentStatus.bind(this); this.getComponentStatusAsync = this.getComponentStatusAsync.bind(this); this.getEndpointsAsync = this.getEndpointsAsync.bind(this); + this.hasResourceUsageAccess = this.hasResourceUsageAccess.bind(this); } async getComponentStatusAsync() { @@ -107,7 +108,7 @@ class KubernetesClusterController { ); this.resourceReservation.Memory = KubernetesResourceReservationHelper.megaBytesValue(this.resourceReservation.Memory); - if (this.isAdmin) { + if (this.hasResourceUsageAccess()) { await this.getResourceUsage(this.endpoint.Id); } } catch (err) { @@ -136,17 +137,25 @@ class KubernetesClusterController { } } + /** + * Check if resource usage stats can be displayed + * @returns {boolean} + */ + hasResourceUsageAccess() { + return this.isAdmin && this.state.useServerMetrics; + } + async onInit() { + this.isAdmin = this.Authentication.isAdmin(); + const useServerMetrics = this.endpoint.Kubernetes.Configuration.UseServerMetrics; + this.state = { applicationsLoading: true, viewReady: false, hasUnhealthyComponentStatus: false, - useServerMetrics: false, + useServerMetrics, }; - this.isAdmin = this.Authentication.isAdmin(); - this.state.useServerMetrics = this.endpoint.Kubernetes.Configuration.UseServerMetrics; - await this.getNodes(); if (this.isAdmin) { await this.getEndpoints(); diff --git a/app/kubernetes/views/cluster/node/node.html b/app/kubernetes/views/cluster/node/node.html index 50105fe5b..13d99df10 100644 --- a/app/kubernetes/views/cluster/node/node.html +++ b/app/kubernetes/views/cluster/node/node.html @@ -85,7 +85,7 @@ memory-usage="ctrl.resourceUsage.Memory" memory-limit="ctrl.memoryLimit" description="Resource reservation represents the total amount of resource assigned to all the applications running on this node." - display-usage="ctrl.state.isAdmin" + display-usage="ctrl.hasResourceUsageAccess()" > diff --git a/app/kubernetes/views/cluster/node/nodeController.js b/app/kubernetes/views/cluster/node/nodeController.js index 8b4369415..bb5c3a90f 100644 --- a/app/kubernetes/views/cluster/node/nodeController.js +++ b/app/kubernetes/views/cluster/node/nodeController.js @@ -46,6 +46,7 @@ class KubernetesNodeController { this.getEndpointsAsync = this.getEndpointsAsync.bind(this); this.updateNodeAsync = this.updateNodeAsync.bind(this); this.drainNodeAsync = this.drainNodeAsync.bind(this); + this.hasResourceUsageAccess = this.hasResourceUsageAccess.bind(this); this.getNodeUsageAsync = this.getNodeUsageAsync.bind(this); } @@ -332,6 +333,10 @@ class KubernetesNodeController { return this.$async(this.getNodesAsync); } + hasResourceUsageAccess() { + return this.state.isAdmin && this.state.useServerMetrics; + } + async getNodeUsageAsync() { try { const nodeName = this.$transition$.params().name; @@ -397,7 +402,7 @@ class KubernetesNodeController { this.memoryLimit = KubernetesResourceReservationHelper.megaBytesValue(this.node.Memory); this.state.isContainPortainer = _.find(this.applications, { ApplicationName: 'portainer' }); - if (this.state.isAdmin) { + if (this.hasResourceUsageAccess()) { await this.getNodeUsage(); } } catch (err) { @@ -412,9 +417,11 @@ class KubernetesNodeController { } async onInit() { + this.availabilities = KubernetesNodeAvailabilities; + this.state = { isAdmin: this.Authentication.isAdmin(), - activeTab: 0, + activeTab: this.LocalStorage.getActiveTab('node'), currentName: this.$state.$current.name, dataLoading: true, eventsLoading: true, @@ -428,15 +435,9 @@ class KubernetesNodeController { hasDuplicateLabelKeys: false, isDrainOperation: false, isContainPortainer: false, - useServerMetrics: false, + useServerMetrics: this.endpoint.Kubernetes.Configuration.UseServerMetrics, }; - this.availabilities = KubernetesNodeAvailabilities; - - this.state.useServerMetrics = this.endpoint.Kubernetes.Configuration.UseServerMetrics; - - this.state.activeTab = this.LocalStorage.getActiveTab('node'); - await this.getNodes(); await this.getEvents(); await this.getApplications(); diff --git a/app/kubernetes/views/resource-pools/edit/resourcePoolController.js b/app/kubernetes/views/resource-pools/edit/resourcePoolController.js index 6e2da1339..d68c64d70 100644 --- a/app/kubernetes/views/resource-pools/edit/resourcePoolController.js +++ b/app/kubernetes/views/resource-pools/edit/resourcePoolController.js @@ -244,7 +244,9 @@ class KubernetesResourcePoolController { return app; }); - await this.getResourceUsage(this.pool.Namespace.Name); + if (this.state.useServerMetrics) { + await this.getResourceUsage(this.pool.Namespace.Name); + } } catch (err) { this.Notifications.error('Failure', err, 'Unable to retrieve applications.'); } finally {