import { MarkdownString } from 'vscode' ; import { Bucket } from '../kubernetes/bucket' ; import { GitRepository } from '../kubernetes/gitRepository' ; import { HelmRelease } from '../kubernetes/helmRelease' ; import { HelmRepository } from '../kubernetes/helmRepository' ; import { KubernetesCluster , KubernetesContextWithCluster } from '../kubernetes/kubernetesConfig' ; import { Deployment , KubernetesObjectKinds , Namespace } from '../kubernetes/kubernetesTypes' ; import { Kustomize } from '../kubernetes/kustomize' ; export type KnownTreeNodeResources = KubernetesContextWithCluster | Namespace | Bucket | GitRepository | HelmRepository | HelmRelease | Kustomize | Deployment ; param kubernetesObject returns export function createMarkdownTable ( kubernetesObject ) { const markdown = new MarkdownString ( undefined , true ) ; markdown . isTrusted = true ; markdown . appendMarkdown ( 'Property | Value\n' ) ; markdown . appendMarkdown ( ':--- | :---\n' ) ; if ( 'context' in kubernetesObject ) { createMarkdownTableRow ( 'context name' , kubernetesObject . name , markdown ) ; createMarkdownTableRow ( 'cluster name' , kubernetesObject . context . clusterInfo ?. name , markdown ) ; createMarkdownTableRow ( 'cluster.server' , kubernetesObject . context . clusterInfo ?. cluster ?. server , markdown ) ; createMarkdownTableRow ( 'cluster.certificate-authority' , kubernetesObject . context . clusterInfo ?. cluster ?. [ 'certificate-authority' ] , markdown ) ; createMarkdownTableRow ( 'cluster.certificate-authority-data' , kubernetesObject . context . clusterInfo ?. cluster ?. [ 'certificate-authority-data' ] , markdown ) ; return markdown ; } createMarkdownTableRow ( 'apiVersion' , kubernetesObject . apiVersion , markdown ) ; createMarkdownTableRow ( 'kind' , kubernetesObject . kind , markdown ) ; createMarkdownTableRow ( 'name' , kubernetesObject . metadata ?. name , markdown ) ; createMarkdownTableRow ( 'namespace' , kubernetesObject . metadata ?. namespace , markdown ) ; if ( kubernetesObject . kind === KubernetesObjectKinds . GitRepository ) { createMarkdownTableRow ( 'spec.suspend' , kubernetesObject . spec ?. suspend === undefined ? false : kubernetesObject . spec ?. suspend , markdown ) ; createMarkdownTableRow ( 'spec.url' , kubernetesObject . spec ?. url , markdown ) ; createMarkdownTableRow ( 'spec.ref.commit' , kubernetesObject . spec ?. ref ?. commit , markdown ) ; createMarkdownTableRow ( 'spec.ref.branch' , kubernetesObject . spec ?. ref ?. branch , markdown ) ; createMarkdownTableRow ( 'spec.ref.tag' , kubernetesObject . spec ?. ref ?. tag , markdown ) ; createMarkdownTableRow ( 'spec.ref.semver' , kubernetesObject . spec ?. ref ?. semver , markdown ) ; } else if ( kubernetesObject . kind === KubernetesObjectKinds . HelmRepository ) { createMarkdownTableRow ( 'spec.url' , kubernetesObject . spec ?. url , markdown ) ; } else if ( kubernetesObject . kind === KubernetesObjectKinds . Bucket ) { createMarkdownTableRow ( 'spec.bucketName' , kubernetesObject . spec ?. bucketName , markdown ) ; createMarkdownTableRow ( 'spec.endpoint' , kubernetesObject . spec ?. endpoint , markdown ) ; createMarkdownTableRow ( 'spec.provider' , kubernetesObject . spec ?. provider , markdown ) ; createMarkdownTableRow ( 'spec.insecure' , kubernetesObject . spec ?. insecure , markdown ) ; } else if ( kubernetesObject . kind === KubernetesObjectKinds . Kustomization ) { createMarkdownTableRow ( 'spec.suspend' , kubernetesObject . spec ?. suspend === undefined ? false : kubernetesObject . spec ?. suspend , markdown ) ; createMarkdownTableRow ( 'spec.prune' , kubernetesObject . spec ?. prune , markdown ) ; createMarkdownTableRow ( 'spec.sourceRef.kind' , kubernetesObject . spec ?. sourceRef ?. kind , markdown ) ; createMarkdownTableRow ( 'spec.sourceRef.name' , kubernetesObject . spec ?. sourceRef ?. name , markdown ) ; createMarkdownTableRow ( 'spec.force' , kubernetesObject . spec ?. force , markdown ) ; createMarkdownTableRow ( 'spec.path' , kubernetesObject . spec ?. path , markdown ) ; } else if ( kubernetesObject . kind === KubernetesObjectKinds . HelmRelease ) { createMarkdownTableRow ( 'spec.suspend' , kubernetesObject . spec ?. suspend === undefined ? false : kubernetesObject . spec ?. suspend , markdown ) ; createMarkdownTableRow ( 'spec.chart.spec.chart' , kubernetesObject . spec ?. chart ?. spec ?. chart , markdown ) ; createMarkdownTableRow ( 'spec.chart.spec.sourceRef.kind' , kubernetesObject . spec ?. chart ?. spec ?. sourceRef ?. kind , markdown ) ; createMarkdownTableRow ( 'spec.chart.spec.sourceRef.name' , kubernetesObject . spec ?. chart ?. spec ?. sourceRef ?. name , markdown ) ; createMarkdownTableRow ( 'spec.chart.spec.version' , kubernetesObject . spec ?. chart ?. spec ?. version , markdown ) ; } else if ( kubernetesObject . kind === KubernetesObjectKinds . Deployment ) { createMarkdownTableRow ( 'spec.paused' , kubernetesObject . spec ?. paused , markdown ) ; createMarkdownTableRow ( 'spec.minReadySeconds' , kubernetesObject . spec ?. minReadySeconds , markdown ) ; createMarkdownTableRow ( 'spec.progressDeadlineSeconds' , kubernetesObject . spec ?. progressDeadlineSeconds , markdown ) ; } if ( kubernetesObject . spec ) { if ( 'interval' in kubernetesObject . spec ) { createMarkdownTableRow ( 'spec.interval' , kubernetesObject . spec ?. interval , markdown ) ; } if ( 'timeout' in kubernetesObject . spec ) { createMarkdownTableRow ( 'spec.timeout' , kubernetesObject . spec ?. timeout , markdown ) ; } } const markdownAsLines = markdown . value . split ( '\n' ) ; if ( markdownAsLines . length > 12 ) { markdown . value = markdownAsLines . slice ( 0 , 12 ) . join ( '\n' ) ; } return markdown ; } param propertyName param propertyValue param markdown function createMarkdownTableRow ( propertyName , propertyValue , markdown ) { if ( propertyValue === undefined ) { return ; } markdown . appendMarkdown ( `${ propertyName } | ${ propertyValue }\n` ) ; } param markdown export function createMarkdownHr ( markdown ) { markdown . appendMarkdown ( '\n\n---\n\n' ) ; } param markdown export function createMarkdownError ( prefix , error = '' , markdown ) { markdown . appendMarkdown ( `<span style="color:#f14c4c;">$(error)</span> ${ prefix }: ${ error }\n\n` ) ; }