1- const k8s = require ( '../dist/index ' ) ;
1+ const k8s = require ( '@kubernetes/client-node ' ) ;
22
33const kc = new k8s . KubeConfig ( ) ;
44kc . loadFromDefault ( ) ;
55
66const k8sApi = kc . makeApiClient ( k8s . CoreV1Api ) ;
77const metricsClient = new k8s . Metrics ( kc ) ;
88
9- k8s . topPods ( k8sApi , metricsClient , "kube-system" )
10- . then ( ( pods ) => {
11-
9+ k8s . topPods ( k8sApi , metricsClient , 'kube-system' ) . then ( ( pods ) => {
1210 const podsColumns = pods . map ( ( pod ) => {
1311 return {
14- " POD" : pod . Pod . metadata . name ,
15- " CPU(cores)" : pod . CPU . CurrentUsage ,
16- " MEMORY(bytes)" : pod . Memory . CurrentUsage ,
17- }
12+ POD : pod . Pod . metadata ? .name ,
13+ ' CPU(cores)' : pod . CPU . CurrentUsage ,
14+ ' MEMORY(bytes)' : pod . Memory . CurrentUsage ,
15+ } ;
1816 } ) ;
19- console . log ( " TOP PODS" )
20- console . table ( podsColumns )
17+ console . log ( ' TOP PODS' ) ;
18+ console . table ( podsColumns ) ;
2119} ) ;
2220
23- k8s . topPods ( k8sApi , metricsClient , "kube-system" )
24- . then ( ( pods ) => {
25-
21+ k8s . topPods ( k8sApi , metricsClient , 'kube-system' ) . then ( ( pods ) => {
2622 const podsAndContainersColumns = pods . flatMap ( ( pod ) => {
27- return pod . Containers . map ( containerUsage => {
23+ return pod . Containers . map ( ( containerUsage ) => {
2824 return {
29- " POD" : pod . Pod . metadata . name ,
30- " NAME" : containerUsage . Container ,
31- " CPU(cores)" : containerUsage . CPUUsage . CurrentUsage ,
32- " MEMORY(bytes)" : containerUsage . MemoryUsage . CurrentUsage ,
25+ POD : pod . Pod . metadata ? .name ,
26+ NAME : containerUsage . Container ,
27+ ' CPU(cores)' : containerUsage . CPUUsage . CurrentUsage ,
28+ ' MEMORY(bytes)' : containerUsage . MemoryUsage . CurrentUsage ,
3329 } ;
34- } )
30+ } ) ;
3531 } ) ;
3632
37- console . log ( " TOP CONTAINERS" )
38- console . table ( podsAndContainersColumns )
39- } ) ;
33+ console . log ( ' TOP CONTAINERS' ) ;
34+ console . table ( podsAndContainersColumns ) ;
35+ } ) ;
0 commit comments