diff --git a/frontend/projects/sdk-ui/src/layout/toolbar/toolbar.component.ts b/frontend/projects/sdk-ui/src/layout/toolbar/toolbar.component.ts index 94bfe16..7d83334 100644 --- a/frontend/projects/sdk-ui/src/layout/toolbar/toolbar.component.ts +++ b/frontend/projects/sdk-ui/src/layout/toolbar/toolbar.component.ts @@ -1,13 +1,12 @@ -import { Component, HostBinding, Inject, Input, OnInit } from '@angular/core'; import { Platform } from '@angular/cdk/platform'; -import { Observable } from 'rxjs'; -import { stagger80ms, fadeInUp400ms, scaleIn400ms, fadeInRight400ms } from '@sdk-ui/animations'; -import { CoreConfigService } from '@core-ui/services'; -import { LayoutService, ToolbarService } from '@sdk-ui/services'; +import { Component, HostBinding, Input, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; import { ClusterService } from '@cluster/cluster.service'; -import { ActivatedRoute, Router } from '@angular/router'; +import { CoreConfigService } from '@core-ui/services'; import { K8sService } from '@k8s/k8s.service'; -import { SelectedClusterService } from '@core-ui/services/selected-cluster.service'; +import { fadeInRight400ms, fadeInUp400ms, scaleIn400ms, stagger80ms } from '@sdk-ui/animations'; +import { LayoutService, ToolbarService } from '@sdk-ui/services'; +import { Observable } from 'rxjs'; @Component({ selector: 'kc-toolbar', diff --git a/frontend/src/app/k8s/k8s-cluster-custom-resources/k8s-cluster-custom-resources.service.ts b/frontend/src/app/k8s/k8s-cluster-custom-resources/k8s-cluster-custom-resources.service.ts index 69d81ca..38b1554 100644 --- a/frontend/src/app/k8s/k8s-cluster-custom-resources/k8s-cluster-custom-resources.service.ts +++ b/frontend/src/app/k8s/k8s-cluster-custom-resources/k8s-cluster-custom-resources.service.ts @@ -13,47 +13,19 @@ export class K8sClusterCustomResourcesService { ) {} getCustomResourcesDefination(queryParams?: any): Observable { - return this.k8sService.clusterId$.pipe( - switchMap((clusterId: string) => { - if (!clusterId) { - return of({ data: null }); - } - return this.http.get(endpoints.CLUSTER_CUSTOM_RESOURCES_DEFINATION, { cluster_id: clusterId, ...queryParams }); - }) - ); + return this.http.get(endpoints.CLUSTER_CUSTOM_RESOURCES_DEFINATION, { cluster_id: this.k8sService.clusterIdSnapshot, ...queryParams }); } getCustomResourceDefinationDetails(name: string): Observable { - return this.k8sService.clusterId$.pipe( - switchMap((clusterId: string) => { - if (!clusterId) { - return of({ data: null }); - } - return this.http.get(endpoints.CLUSTER_CUSTOM_RESOURCES_DEFINATION + '/' + name, { cluster_id: clusterId }); - }) - ); + return this.http.get(endpoints.CLUSTER_CUSTOM_RESOURCES_DEFINATION + '/' + name, { cluster_id: this.k8sService.clusterIdSnapshot }); } getCustomResources(params: any): Observable { - return this.k8sService.clusterId$.pipe( - switchMap((clusterId: string) => { - if (!clusterId) { - return of({ data: null }); - } - return this.http.get(endpoints.CLUSTER_CUSTOM_RESOURCES, { ...params, cluster_id: clusterId }); - }) - ); + return this.http.get(endpoints.CLUSTER_CUSTOM_RESOURCES, { ...params, cluster_id: this.k8sService.clusterIdSnapshot }); } getCustomResourceDetails(name: string, qp: any): Observable { - return this.k8sService.clusterId$.pipe( - switchMap((clusterId: string) => { - if (!clusterId) { - return of({ data: null }); - } - return this.http.get(endpoints.CLUSTER_CUSTOM_RESOURCES + '/' + name, { ...qp, cluster_id: clusterId }); - }) - ); + return this.http.get(endpoints.CLUSTER_CUSTOM_RESOURCES + '/' + name, { ...qp, cluster_id: this.k8sService.clusterIdSnapshot }); } /* diff --git a/frontend/src/app/k8s/k8s-cluster-role-binding/k8s-cluster-role-binding.service.ts b/frontend/src/app/k8s/k8s-cluster-role-binding/k8s-cluster-role-binding.service.ts index 1f7b279..1ecde14 100644 --- a/frontend/src/app/k8s/k8s-cluster-role-binding/k8s-cluster-role-binding.service.ts +++ b/frontend/src/app/k8s/k8s-cluster-role-binding/k8s-cluster-role-binding.service.ts @@ -13,25 +13,11 @@ export class K8sClusterRoleBindingService { ) {} getClusterRoleBinding(queryParam?: any): Observable { - return this.k8sService.clusterId$.pipe( - switchMap((clusterId: string) => { - if (!clusterId) { - return of({ data: null }); - } - return this.http.get(endpoints.CLUSTER_ROLE_BINDING, { ...queryParam, cluster_id: clusterId }); - }) - ); + return this.http.get(endpoints.CLUSTER_ROLE_BINDING, { ...queryParam, cluster_id: this.k8sService.clusterIdSnapshot }); } getClusterRoleBindingDetails(name: string): Observable { - return this.k8sService.clusterId$.pipe( - switchMap((clusterId: string) => { - if (!clusterId) { - return of({ data: null }); - } - return this.http.get(endpoints.CLUSTER_ROLE_BINDING + '/' + name, { cluster_id: clusterId }); - }) - ); + return this.http.get(endpoints.CLUSTER_ROLE_BINDING + '/' + name, { cluster_id: this.k8sService.clusterIdSnapshot }); } /* Create & update diff --git a/frontend/src/app/k8s/k8s-cluster-role/k8s-cluster-role-details/k8s-cluster-role-details.component.html b/frontend/src/app/k8s/k8s-cluster-role/k8s-cluster-role-details/k8s-cluster-role-details.component.html index 3efab94..079f2d6 100644 --- a/frontend/src/app/k8s/k8s-cluster-role/k8s-cluster-role-details/k8s-cluster-role-details.component.html +++ b/frontend/src/app/k8s/k8s-cluster-role/k8s-cluster-role-details/k8s-cluster-role-details.component.html @@ -40,30 +40,23 @@

{{ data?.metadata?.name }}

Rules

-
+
- - + + + - - - - + + + + +
ApiGroupsResourcesapiGroupsresourcesnonResourceURLs verbs
{{ item?.apiGroups[0] == '' ? '-' : item?.apiGroups }} - {{ obj }}
-
- -

Resource Names

- {{ item?.resourceNames }} -
-
- {{ obj }}
-
{{ rule.apiGroups && rule.apiGroups[0] !== '' ? rule.apiGroups.join(', ') : '-' }}{{ rule.resources ? rule.resources.join(', ') : '-' }}{{ rule.nonResourceURLs ? rule.nonResourceURLs.join(', ') : '-' }}{{ rule.verbs ? rule.verbs.join(', ') : '-' }}
@@ -86,4 +79,4 @@

Aggregation Rule

There is nothing to display.
- + \ No newline at end of file diff --git a/frontend/src/app/k8s/k8s-cluster-role/k8s-cluster-role.service.ts b/frontend/src/app/k8s/k8s-cluster-role/k8s-cluster-role.service.ts index 9f98eec..3bde34c 100644 --- a/frontend/src/app/k8s/k8s-cluster-role/k8s-cluster-role.service.ts +++ b/frontend/src/app/k8s/k8s-cluster-role/k8s-cluster-role.service.ts @@ -13,25 +13,11 @@ export class K8sClusterRoleService { ) {} getClusterRole(queryParam?: any): Observable { - return this.k8sService.clusterId$.pipe( - switchMap((clusterId: string) => { - if (!clusterId) { - return of({ data: null }); - } - return this.http.get(endpoints.CLUSTER_ROLE, { ...queryParam, cluster_id: clusterId }); - }) - ); + return this.http.get(endpoints.CLUSTER_ROLE, { ...queryParam, cluster_id: this.k8sService.clusterIdSnapshot }); } getClusterRoleDetails(name: string): Observable { - return this.k8sService.clusterId$.pipe( - switchMap((clusterId: string) => { - if (!clusterId) { - return of({ data: null }); - } - return this.http.get(endpoints.CLUSTER_ROLE + '/' + name, { cluster_id: clusterId }); - }) - ); + return this.http.get(endpoints.CLUSTER_ROLE + '/' + name, { cluster_id: this.k8sService.clusterIdSnapshot }); } /* Create & update diff --git a/frontend/src/app/k8s/k8s-namespaces/k8s-namespaces-list/k8s-namespaces-list.component.ts b/frontend/src/app/k8s/k8s-namespaces/k8s-namespaces-list/k8s-namespaces-list.component.ts index 17aca87..8e61eb6 100644 --- a/frontend/src/app/k8s/k8s-namespaces/k8s-namespaces-list/k8s-namespaces-list.component.ts +++ b/frontend/src/app/k8s/k8s-namespaces/k8s-namespaces-list/k8s-namespaces-list.component.ts @@ -335,7 +335,7 @@ export class K8sNamespacesListComponent implements OnInit, OnDestroy { const currentTime = new Date(); const diff = (currentTime.getTime() - this.tokenReceiveTime.getTime()) / 60000; if (diff > 2) { - queryParam = { limit: this.data.length + 10 }; + queryParam = { limit: this.data?.length + 10 }; } else { queryParam = { continue: this.resourceToken }; } @@ -361,6 +361,7 @@ export class K8sNamespacesListComponent implements OnInit, OnDestroy { }, error: err => { this.toastr.error('Failed: ', err.error.message); + this.loadMoreData = false; } }); } diff --git a/frontend/src/app/k8s/k8s-nodes/k8s-nodes.service.ts b/frontend/src/app/k8s/k8s-nodes/k8s-nodes.service.ts index a1fff2a..7c3beae 100644 --- a/frontend/src/app/k8s/k8s-nodes/k8s-nodes.service.ts +++ b/frontend/src/app/k8s/k8s-nodes/k8s-nodes.service.ts @@ -24,14 +24,7 @@ export class K8sNodesService { } getNodeDetails(name: string): Observable { - return this.k8sService.clusterId$.pipe( - switchMap((clusterId: string) => { - if (!clusterId) { - return of({ data: null }); - } - return this.http.get(endpoints.NODE_LIST + '/' + name, { cluster_id: clusterId }); - }) - ); + return this.http.get(endpoints.NODE_LIST + '/' + name, { cluster_id: this.k8sService.clusterIdSnapshot }); } nodeCordonUncordon(name: string): Observable { diff --git a/frontend/src/app/k8s/k8s-nodes/node-details/node-details.component.html b/frontend/src/app/k8s/k8s-nodes/node-details/node-details.component.html index 0aaa0b0..a4abb18 100644 --- a/frontend/src/app/k8s/k8s-nodes/node-details/node-details.component.html +++ b/frontend/src/app/k8s/k8s-nodes/node-details/node-details.component.html @@ -112,8 +112,7 @@

Usage

-

- {{ item.key }}: {{ item.value }} +

{{ item.key }}: {{ convertUnitToBase(item.value, item.key) }}

@@ -197,7 +196,7 @@

Status

Allocatable

- {{ item.key }}: {{ item.value }} + {{ item.key }}: {{ convertUnitToBase(item.value, item.key) }}

@@ -206,7 +205,7 @@

Capacity

- {{ item.key }}: {{ item.value }} + {{ item.key }}: {{ convertUnitToBase(item.value, item.key) }}

@@ -304,7 +303,7 @@

Name - Size (Bytes) + Size (GB) @@ -313,7 +312,7 @@

{{ item }}
- {{ image.sizeBytes }} + {{ convertBytesToGigabytes(image.sizeBytes) }} diff --git a/frontend/src/app/k8s/k8s-nodes/node-details/node-details.component.ts b/frontend/src/app/k8s/k8s-nodes/node-details/node-details.component.ts index 9371efc..77c94f3 100644 --- a/frontend/src/app/k8s/k8s-nodes/node-details/node-details.component.ts +++ b/frontend/src/app/k8s/k8s-nodes/node-details/node-details.component.ts @@ -57,6 +57,13 @@ export class NodeDetailsComponent implements OnInit { icArrowBack = icArrowBack; icCircle = icCircle; + unitMap = { + 'cpu': 'core', + 'memory': 'Gi', + 'pods': '', + 'ephemeral-storage': 'Gi' + }; + constructor( private route: ActivatedRoute, private nodeService: K8sNodesService, @@ -191,4 +198,29 @@ export class NodeDetailsComponent implements OnInit { } return true; } + + convertUnitToBase(value: any, key?: any): any { + const unit = value.replace(/\d/g, ''); + const size = value.replace(/\D/g, ''); + if (unit === 'Ki') { + return Number((parseInt(size) / 1_000_000).toFixed(2)) + ' Gi'; // Convert KiB to GiB + } else if (unit === 'Mi') { + return Number((parseInt(size) / 1_000).toFixed(2)) + ' Gi'; // Convert MiB to GiB + } else if (unit === 'n') { + return Number((parseInt(size) / 1_000_000_000).toFixed(2)) + ' core'; // Convert nano core to core + } else if (unit === 'm') { + return Number((parseInt(size) / 1_000).toFixed(2)) + ' core'; // Convert milli core to core + } else if (key && key === 'ephemeral-storage' && unit == '') { + return Number((parseInt(size) / 1_073_741_824).toFixed(2)) + ' Gi'; // Convert bytes to GiB + } + if(unit == '' && key && this.unitMap[key]) { + return parseFloat(size) + ' ' + this.unitMap[key]; // if no unit is available from data, Return the value with the unit from unitMap + } + return parseFloat(size); // Fallback for other units or plain numbers + } + + //byte to gigabyte + convertBytesToGigabytes(bytes: number): number { + return Number((bytes / (1024 * 1024 * 1024)).toFixed(2)); + } } diff --git a/frontend/src/app/k8s/k8s-persistent-volume/k8s-persistent-volume.service.ts b/frontend/src/app/k8s/k8s-persistent-volume/k8s-persistent-volume.service.ts index b48045b..e6b7f8a 100644 --- a/frontend/src/app/k8s/k8s-persistent-volume/k8s-persistent-volume.service.ts +++ b/frontend/src/app/k8s/k8s-persistent-volume/k8s-persistent-volume.service.ts @@ -13,25 +13,11 @@ export class K8sPersistentVolumeService { ) {} getPersitentVolume(queryParam?: any): Observable { - return this.k8sService.clusterId$.pipe( - switchMap((clusterId: string) => { - if (!clusterId) { - return of({ data: null }); - } - return this.http.get(endpoints.PV_LIST, { ...queryParam, cluster_id: clusterId }); - }) - ); + return this.http.get(endpoints.PV_LIST, { ...queryParam, cluster_id: this.k8sService.clusterIdSnapshot }); } getPvDetails(name: string): Observable { - return this.k8sService.clusterId$.pipe( - switchMap((clusterId: string) => { - if (!clusterId) { - return of({ data: null }); - } - return this.http.get(endpoints.PV_LIST + '/' + name, { cluster_id: clusterId }); - }) - ); + return this.http.get(endpoints.PV_LIST + '/' + name, { cluster_id: this.k8sService.clusterIdSnapshot }); } /* Create & update