Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions frontend/projects/sdk-ui/src/layout/toolbar/toolbar.component.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,19 @@ export class K8sClusterCustomResourcesService {
) {}

getCustomResourcesDefination(queryParams?: any): Observable<any> {
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<any> {
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<any> {
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<any> {
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 });
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,11 @@ export class K8sClusterRoleBindingService {
) {}

getClusterRoleBinding(queryParam?: any): Observable<any> {
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<any> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,23 @@ <h3 class="px-4 mb-2">{{ data?.metadata?.name }}</h3>
<mat-expansion-panel-header class="info-table-row">
<mat-panel-title><h2 class="kube-card__title mt-6">Rules</h2></mat-panel-title>
</mat-expansion-panel-header>
<div class="kube-table__wrapper">
<div class="kube-table__wrapper mt-4">
<div class="kube-table--responsive">
<table class="kube-table heading-diff">
<thead>
<tr>
<th>ApiGroups</th>
<th>Resources</th>
<th>apiGroups</th>
<th>resources</th>
<th>nonResourceURLs</th>
<th>verbs</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of data?.rules">
<td>{{ item?.apiGroups[0] == '' ? '-' : item?.apiGroups }}</td>
<td>
<span *ngFor="let obj of item?.resources">{{ obj }}<br /></span>
<br />
<span *ngIf="item?.resourceNames">
<h3>Resource Names</h3>
<span>{{ item?.resourceNames }}</span>
</span>
</td>
<td>
<span *ngFor="let obj of item?.verbs">{{ obj }}<br /></span>
</td>
<tr *ngFor="let rule of data?.rules">
<td>{{ rule.apiGroups && rule.apiGroups[0] !== '' ? rule.apiGroups.join(', ') : '-' }}</td>
<td>{{ rule.resources ? rule.resources.join(', ') : '-' }}</td>
<td>{{ rule.nonResourceURLs ? rule.nonResourceURLs.join(', ') : '-' }}</td>
<td>{{ rule.verbs ? rule.verbs.join(', ') : '-' }}</td>
</tr>
</tbody>
</table>
Expand All @@ -86,4 +79,4 @@ <h2 class="kube-card__title">Aggregation Rule</h2>
<ng-template #emptyDataStatus>
<h6 class="color-text text-center">There is nothing to display.</h6>
</ng-template>
</ng-template>
</ng-template>
18 changes: 2 additions & 16 deletions frontend/src/app/k8s/k8s-cluster-role/k8s-cluster-role.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,11 @@ export class K8sClusterRoleService {
) {}

getClusterRole(queryParam?: any): Observable<any> {
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<any> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand All @@ -361,6 +361,7 @@ export class K8sNamespacesListComponent implements OnInit, OnDestroy {
},
error: err => {
this.toastr.error('Failed: ', err.error.message);
this.loadMoreData = false;
}
});
}
Expand Down
9 changes: 1 addition & 8 deletions frontend/src/app/k8s/k8s-nodes/k8s-nodes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ export class K8sNodesService {
}

getNodeDetails(name: string): Observable<any> {
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<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ <h3 *ngIf="metrics?.metadata?.creationTimestamp; else noData" class="kc-dataset_
<div class="kc-dataset__name">Usage</div>
<div *ngIf="metrics?.metadata?.creationTimestamp; else noData">
<div *ngFor="let item of metrics?.usage | keyvalue">
<h3 class="kc-dataset__value">
<span class="kc-dataset-key">{{ item.key }}: </span> {{ item.value }}
<h3 class="kc-dataset__value"> <span class="kc-dataset-key">{{ item.key }}: </span> {{ convertUnitToBase(item.value, item.key) }}
</h3>
</div>
</div>
Expand Down Expand Up @@ -197,7 +196,7 @@ <h2 class="kube-card__title">Status</h2>
<div class="kc-dataset">
<div class="kc-dataset__name">Allocatable</div>
<h3 class="kc-dataset__value" *ngFor="let item of details?.status?.allocatable | keyvalue">
<span class="kc-dataset-key">{{ item.key }}: </span> {{ item.value }}
<span class="kc-dataset-key">{{ item.key }}: </span> {{ convertUnitToBase(item.value, item.key) }}
</h3>
</div>
</div>
Expand All @@ -206,7 +205,7 @@ <h3 class="kc-dataset__value" *ngFor="let item of details?.status?.allocatable |
<div class="kc-dataset">
<div class="kc-dataset__name">Capacity</div>
<h3 class="kc-dataset__value" *ngFor="let item of details?.status?.capacity | keyvalue">
<span class="kc-dataset-key">{{ item.key }}: </span> {{ item.value }}
<span class="kc-dataset-key">{{ item.key }}: </span> {{ convertUnitToBase(item.value, item.key) }}
</h3>
</div>
</div>
Expand Down Expand Up @@ -304,7 +303,7 @@ <h3 class="kc-dataset__value" *ngFor="let item of details?.status?.daemonEndpoin
<thead>
<tr>
<th width="30%">Name</th>
<th width="40%">Size (Bytes)</th>
<th width="40%">Size (GB)</th>
</tr>
</thead>
<tbody>
Expand All @@ -313,7 +312,7 @@ <h3 class="kc-dataset__value" *ngFor="let item of details?.status?.daemonEndpoin
<span *ngFor="let item of image.names"> {{ item }} <br /> </span>
</td>
<td width="10%">
{{ image.sizeBytes }}
{{ convertBytesToGigabytes(image.sizeBytes) }}
</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,11 @@ export class K8sPersistentVolumeService {
) {}

getPersitentVolume(queryParam?: any): Observable<any> {
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<any> {
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
Expand Down
Loading