From e8b06b2da7a5df68ac02bcf227078dfad1ac1e57 Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Wed, 9 Dec 2020 09:25:44 +0000 Subject: [PATCH] Add additional information to new kube resource tables (#4825) * Allow k8s namespaces to be added as favourites * k8s: Add support for more resource types in a generic way * Improve the home page * Fix lint issue * Tweaks and refactoring * Add separator to layout menu * Improve incremental loading * Various tidyups and improvements * Tidy ups and improvemts to async loading * Fix progress spinner alignment * Unscubribe * Minor bug fixes and a few tidy ups * Further tidy ups * Fix front end unit tests * Unit test fix * Further unit tests fixes * Endpoint card unit test fixes * Fix unit tests * Tidy up favorite card * Further refinement to the UI * Fix missing dates from recents on CF view * Get app deploy from home screen working * Add message for when no connected endpoints * Unit test fixes * Kubernetes Home Card unit test fixes * Fix unit test error * Move components to remove dependency on large shared module * Fix unit test and add deploy tiles to CF Home Card * Fix word wrap on favorite name * Add tool tip * Style tidy ups * Minor tidy ups * Check favorites exists before navigating to them * Fix test imports * First round of tidy ups of the user favorites code * Further refactor to reduce the complexity of user favorites * Fix unit tests * Allow Kubernetes namespaces to be favorited * Fix duplicate import * Tidy ups * e2e Debugging * Fix for org delete e2e test * E2e Test fix * Refactor out common entity operator * Slight refactor * Fix frontend unit tests * Unit test fix * Address PR feedback so far * Address PR feedback * Fix connected endpoint state check on home screen * Address PR feedback * Restore apps link * Improve typing * Fix undefined error * Fix unit test * Fix ordering issue * Add a default home card * Fix frong end lint issues * Merge fixes * Fix unit tests * WIP * Fixes for pods view * Tidy ups * Add more resource types * Fix lint issue * Fix lint issue * Fix unit test * Fix lint issues * Fix build issue * Fix unit test * Unit test fix * Fix unit tests * More improvements * Numerous improvements * Fix lint issue * RE-arrange kube entity creation - now assign directly to kube entity catalog - to access custom kube generator resources have to do some funnies in kubernetes-tab-base.component.ts * Fix services in namespace view - kube guid and namespace was mixed up - now follow standard pattern of kube guid then namespace in ctor * Fix merge issues * Changes following review * Fix unit tests * Fix merge issue * Fix merge issues * Changes following merge * Changes following merge * Add additional information to new kube resource tables * Fix merge conflicts * Only show analysis link when enabled * Fix issue favoriting from side panel * Fix expression changed error * Fix expression changed errors * Fix a few minor issues and unit test * Remove old namespace components * Remvoe TODO * Fix merge issue * Fix PR issues * Delete fixes - fixes to delete action param - added to delete pods - successEntityHandler doesn't run, so have to manually clear pagination sections * Fix delete ns - ensure delete action has correct guid - ensure response has kube guid * Don't use generic url validation for kube endpoints (#4826) - this was recently added - false negative for minikube url (https://192.168.39.159:8443) * Improvement and fix for no-content component (#4827) * Improvements and fixes for no-content component - add colour to improve monotone views on first load - fix issue where no-content header arrow failed to show in production (see https://github.com/angular/angular-cli/issues/17440) * Fix another opacity percentage - seen in import kube table edit endpoint name cell * Bump github.com/mattn/go-sqlite3 from 1.13.0 to 1.14.5 in /src/jetstream (#4816) Bumps [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) from 1.13.0 to 1.14.5. - [Release notes](https://github.com/mattn/go-sqlite3/releases) - [Commits](https://github.com/mattn/go-sqlite3/compare/v1.13.0...v1.14.5) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Document deployment with an ingress; make ingress host optional (#4793) * Minor Kube Fixes (#4829) * Fix home screen kube card pod link * Ensure reset list filter button also resets helm chart repo filter * Ensure we handle the case where the versions info is unable * Fix link for namespaces Co-authored-by: Neil MacDougall * Fix expanding pod row * Fix show of analysis in namespace resource viewer * Fix fav namespace link Co-authored-by: Neil MacDougall Co-authored-by: Neil MacDougall Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Ivan Kapelyukhin Co-authored-by: Neil MacDougall --- .../kubernetes/kubernetes-entity-generator.ts | 68 +++++++++++++++++-- .../src/kubernetes/store/kube.types.ts | 5 ++ 2 files changed, 68 insertions(+), 5 deletions(-) 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; }[]; +}