2024-11-07 14:10:19 +13:00
import { NodeCondition } from 'kubernetes-types/core/v1' ;
import { CellContext } from '@tanstack/react-table' ;
import { Badge } from '@@/Badge' ;
import { Tooltip } from '@@/Tip/Tooltip' ;
import { NodeRowData } from '../types' ;
import { columnHelper } from './helper' ;
export const conditions = columnHelper . accessor ( ( row ) = > getConditions ( row ) , {
header : ( ) = > (
< >
Conditions
< Tooltip
position = "top"
2024-11-12 09:42:14 +13:00
message = "Empty indicates the node is healthy. Orange indicates the node is experiencing MemoryPressure, DiskPressure, NetworkUnavailable or PIDPressure."
2024-11-07 14:10:19 +13:00
/ >
< / >
) ,
id : 'conditions' ,
cell : ConditionsCell ,
} ) ;
function ConditionsCell ( {
row : { original : node } ,
} : CellContext < NodeRowData , NodeCondition [ ] > ) {
const conditions = getConditions ( node ) ;
return (
< div className = "flex flex-wrap gap-1" >
{ conditions . length > 0
? conditions . map ( ( condition ) = > (
< Badge
key = { condition . type ? . toString ( ) }
type = { condition . status === 'True' ? 'warn' : 'success' }
>
{ condition . type }
< / Badge >
) )
: '-' }
< / div >
) ;
}
function getConditions ( node : NodeRowData ) {
return (
2024-11-12 09:42:14 +13:00
// exclude the Ready condition and search for unhealthy conditions
2024-11-07 14:10:19 +13:00
node . status ? . conditions ? . filter (
2024-11-12 09:42:14 +13:00
( condition ) = > condition . type !== 'Ready' && condition . status === 'True'
2024-11-07 14:10:19 +13:00
) ? ? [ ]
) ;
}