@@ -31,6 +31,7 @@ import { StatusLabel, StatusLabelProps } from '../common/Label';
3131import Link from '../common/Link' ;
3232import ResourceListView from '../common/Resource/ResourceListView' ;
3333import { SimpleTableProps } from '../common/SimpleTable' ;
34+ import { TooltipIcon } from '../common/Tooltip' ;
3435import LightTooltip from '../common/Tooltip/TooltipLight' ;
3536
3637function getPodStatus ( pod : Pod ) {
@@ -246,9 +247,43 @@ export function PodListRenderer(props: PodListProps) {
246247 const cpu = getCpuUsage ( pod ) ;
247248 if ( cpu === undefined ) return ;
248249
249- const { value, unit } = unparseCpu ( String ( cpu ) ) ;
250-
251- return `${ value } ${ unit } ` ;
250+ const { value : aValue , unit : aUnit } = unparseCpu ( String ( cpu ) ) ;
251+
252+ const request = pod . spec . containers
253+ . map ( c => parseCpu ( c . resources ?. requests ?. cpu || '0' ) )
254+ . reduce ( ( a , b ) => a + b , 0 ) ;
255+
256+ const limit = pod . spec . containers
257+ . map ( c => parseCpu ( c . resources ?. limits ?. cpu || '0' ) )
258+ . reduce ( ( a , b ) => a + b , 0 ) ;
259+
260+ const tooltipLines = [ ] ;
261+ if ( request > 0 ) {
262+ const { value : rValue , unit : rUnit } = unparseCpu ( String ( request ) ) ;
263+ const percentOfRequest = ( ( cpu / request ) * 100 ) . toFixed ( 1 ) ;
264+ tooltipLines . push (
265+ t ( 'Request' ) +
266+ `: ${ percentOfRequest } % (${ aValue } ${ aUnit } /${ rValue } ${ rUnit } )`
267+ ) ;
268+ }
269+ if ( limit > 0 ) {
270+ const { value : lValue , unit : lUnit } = unparseCpu ( String ( limit ) ) ;
271+ const percentOfLimit = ( ( cpu / limit ) * 100 ) . toFixed ( 1 ) ;
272+ tooltipLines . push (
273+ t ( 'Limit' ) + `: ${ percentOfLimit } % (${ aValue } ${ aUnit } /${ lValue } ${ lUnit } )`
274+ ) ;
275+ }
276+
277+ return (
278+ < Box display = "flex" alignItems = "center" >
279+ < span style = { { whiteSpace : 'nowrap' } } > { `${ aValue } ${ aUnit } ` } </ span >
280+ { tooltipLines . length > 0 && (
281+ < TooltipIcon >
282+ < span style = { { whiteSpace : 'pre-line' } } > { tooltipLines . join ( '\n' ) } </ span >
283+ </ TooltipIcon >
284+ ) }
285+ </ Box >
286+ ) ;
252287 } ,
253288 getValue : ( pod : Pod ) => getCpuUsage ( pod ) ?? 0 ,
254289 } ,
@@ -259,9 +294,43 @@ export function PodListRenderer(props: PodListProps) {
259294 render : ( pod : Pod ) => {
260295 const memory = getMemoryUsage ( pod ) ;
261296 if ( memory === undefined ) return ;
262- const { value, unit } = unparseRam ( memory ) ;
263-
264- return `${ value } ${ unit } ` ;
297+ const { value : aValue , unit : aUnit } = unparseRam ( memory ) ;
298+
299+ const request = pod . spec . containers
300+ . map ( c => parseRam ( c . resources ?. requests ?. memory || '0' ) )
301+ . reduce ( ( a , b ) => a + b , 0 ) ;
302+
303+ const limit = pod . spec . containers
304+ . map ( c => parseRam ( c . resources ?. limits ?. memory || '0' ) )
305+ . reduce ( ( a , b ) => a + b , 0 ) ;
306+
307+ const tooltipLines = [ ] ;
308+ if ( request > 0 ) {
309+ const { value : rValue , unit : rUnit } = unparseRam ( request ) ;
310+ const percentOfRequest = ( ( memory / request ) * 100 ) . toFixed ( 1 ) ;
311+ tooltipLines . push (
312+ t ( 'Request' ) +
313+ `: ${ percentOfRequest } % (${ aValue } ${ aUnit } /${ rValue } ${ rUnit } )`
314+ ) ;
315+ }
316+ if ( limit > 0 ) {
317+ const { value : lValue , unit : lUnit } = unparseRam ( limit ) ;
318+ const percentOfLimit = ( ( memory / limit ) * 100 ) . toFixed ( 1 ) ;
319+ tooltipLines . push (
320+ t ( 'Limit' ) + `: ${ percentOfLimit } % (${ aValue } ${ aUnit } /${ lValue } ${ lUnit } )`
321+ ) ;
322+ }
323+
324+ return (
325+ < Box display = "flex" alignItems = "center" >
326+ < span style = { { whiteSpace : 'nowrap' } } > { `${ aValue } ${ aUnit } ` } </ span >
327+ { tooltipLines . length > 0 && (
328+ < TooltipIcon >
329+ < span style = { { whiteSpace : 'pre-line' } } > { tooltipLines . join ( '\n' ) } </ span >
330+ </ TooltipIcon >
331+ ) }
332+ </ Box >
333+ ) ;
265334 } ,
266335 getValue : ( pod : Pod ) => getMemoryUsage ( pod ) ?? 0 ,
267336 } ,
0 commit comments