import { MarkdownString } from 'vscode' ; import { HelmRelease } from '../../kubernetes/helmRelease' ; import { Kustomize } from '../../kubernetes/kustomize' ; import { createMarkdownError , createMarkdownHr , createMarkdownTable } from '../../utils/markdownUtils' ; import { TreeNode , TreeNodeIcon } from './treeNode' ; /**
 * Base class for all Workload tree view items.
 */ export class WorkloadNode extends TreeNode { /**
     * Whether or not the appliication failed to reconcile.
     */ isReconcileFailed = false ; resource : Kustomize | HelmRelease ; constructor ( label , resource ) { super ( label ) ; this . resource = resource ; this . updateStatus ( resource ) ; } param resource updateStatus ( resource ) { const conditions = resource . status . conditions ; const condition = Array . isArray ( conditions ) ? conditions [ 0 ] : conditions ; if ( condition ?. status === 'False' ) { this . isReconcileFailed = true ; this . setIcon ( TreeNodeIcon . Error ) ; } else { this . isReconcileFailed = false ; this . setIcon ( TreeNodeIcon . Success ) ; } } get tooltip ( ) { return this . getMarkdownHover ( this . resource ) ; } get description ( ) { const isSuspendIcon = this . resource . spec ?. suspend ? '⏸ ' : '' ; return `${ isSuspendIcon }${ this . resource . kind }` ; } param resource returns getMarkdownHover ( resource ) { const markdown = createMarkdownTable ( resource ) ; if ( this . isReconcileFailed ) { const conditions = resource . status . conditions ; const condition = Array . isArray ( conditions ) ? conditions [ 0 ] : conditions ; createMarkdownHr ( markdown ) ; createMarkdownError ( 'Status message' , condition ?. message , markdown ) ; createMarkdownError ( 'Status reason' , condition ?. reason , markdown ) ; } return markdown ; } }