diff --git a/src/frontend/packages/kubernetes/src/kubernetes/kubernetes-entity-generator.ts b/src/frontend/packages/kubernetes/src/kubernetes/kubernetes-entity-generator.ts index 1d3d6e8eb4..44f99515ed 100644 --- a/src/frontend/packages/kubernetes/src/kubernetes/kubernetes-entity-generator.ts +++ b/src/frontend/packages/kubernetes/src/kubernetes/kubernetes-entity-generator.ts @@ -1,5 +1,6 @@ import { Compiler, Injector } from '@angular/core'; import { Validators } from '@angular/forms'; +import moment from 'moment'; import { BaseEndpointAuth } from '../../../core/src/core/endpoint-auth'; import { @@ -71,6 +72,7 @@ import { import { getGuidFromKubePodObj } from './store/kube.getIds'; import { AnalysisReport, + BasicKubeAPIResource, KubeAPIResource, KubeResourceEntityDefinition, KubernetesConfigMap, @@ -80,6 +82,7 @@ import { KubernetesPod, KubernetesStatefulSet, KubeService, + KubeServiceAccount, } from './store/kube.types'; import { KubeDashboardStatus } from './store/kubernetes.effects'; import { generateWorkloadsEntities } from './workloads/store/workloads-entity-generator'; @@ -237,9 +240,9 @@ export class KubeEntityCatalog { public pv: StratosCatalogEntity; public replicaSet: StratosCatalogEntity; public clusterRole: StratosCatalogEntity; - public serviceAccount: StratosCatalogEntity; + public serviceAccount: StratosCatalogEntity; public role: StratosCatalogEntity; - public job: StratosCatalogEntity; + public job: StratosCatalogEntity; constructor() { const endpointDef: StratosEndpointExtensionDefinition = { @@ -390,6 +393,11 @@ export class KubeEntityCatalog { apiVersion: '/api/v1', apiName: 'secrets', listColumns: [ + { + header: 'Type', + field: 'type', + sort: true + }, { header: 'Data Keys', field: (row: KubernetesConfigMap) => `${Object.keys(row.data).length}` @@ -462,10 +470,20 @@ export class KubeEntityCatalog { apiName: 'replicasets', listColumns: [ { - header: 'Replicas', + header: 'Desired', field: 'spec.replicas', sort: true }, + { + header: 'Current', + field: 'status.replicas', + sort: true + }, + { + header: 'Ready', + field: 'status.readyReplicas', + sort: true + }, ] }); this.clusterRole = KubeResourceEntityHelper.generate(endpointDef, { @@ -476,12 +494,16 @@ export class KubeEntityCatalog { apiName: 'clusterroles', apiNamespaced: false, }); - this.serviceAccount = KubeResourceEntityHelper.generate(endpointDef, { + this.serviceAccount = KubeResourceEntityHelper.generate(endpointDef, { type: 'serviceAccount', icon: 'replica_set', label: 'Service Account', apiVersion: '/api/v1', apiName: 'serviceaccounts', + listColumns: [{ + header: 'Secrets', + field: (row: KubeServiceAccount) => row.secrets?.length.toString() + }] }); this.role = KubeResourceEntityHelper.generate(endpointDef, { type: 'role', @@ -490,12 +512,20 @@ export class KubeEntityCatalog { apiVersion: '/apis/rbac.authorization.k8s.io/v1', apiName: 'roles', }); - this.job = KubeResourceEntityHelper.generate(endpointDef, { + this.job = KubeResourceEntityHelper.generate(endpointDef, { type: 'job', icon: 'job', label: 'Job', apiVersion: '/apis/batch/v1', apiName: 'jobs', + listColumns: [{ + header: 'Completions', + field: (row: BasicKubeAPIResource) => this.jobToCompletion(row.spec, row.status) + }, + { + header: 'Duration', + field: (row: BasicKubeAPIResource) => this.jobToDuration(row.status) + }] }); } @@ -567,6 +597,34 @@ export class KubeEntityCatalog { endpoint: endpointDefinition, }); } + + private jobToCompletion(spec: any, status: any): string { + if (!!spec.completions) { + return status.succeeded + '/' + spec.completions; + } + + if (!spec.parallelism) { + return status.succeeded + '/1'; + } + + if (spec.parallelism > 1) { + return status.Succeeded + '/1 of ' + spec.parallelism; + } + + return status.succeeded + '/1'; + } + + private jobToDuration(status: any): string { + if (!status.startTime) { + return ''; + } + + if (!!status.CompletionTime) { + return moment.duration(moment(status.startTime).diff(moment())).humanize(); + } + + return moment.duration(moment(status.startTime).diff(moment(status.completionTime))).humanize(); + } } /** diff --git a/src/frontend/packages/kubernetes/src/kubernetes/store/kube.types.ts b/src/frontend/packages/kubernetes/src/kubernetes/store/kube.types.ts index 602e67f8a7..e6c204ab1a 100644 --- a/src/frontend/packages/kubernetes/src/kubernetes/store/kube.types.ts +++ b/src/frontend/packages/kubernetes/src/kubernetes/store/kube.types.ts @@ -576,3 +576,8 @@ export interface SimpleKubeListColumn { flex?: string; sort?: boolean; } + +export interface KubeServiceAccount { + metadata: Metadata; + secrets: { [name: string]: string; }[]; +}