@@ -26,54 +26,60 @@ export const GET: RequestHandler = async () => {
2626 // Get minikube IP for NodePort services
2727 let minikubeIP = 'localhost' ;
2828 try {
29- const { stdout : minikubeIPOutput } = await execAsync ( 'minikube ip 2>/dev/null || echo "localhost"' ) ;
29+ const { stdout : minikubeIPOutput } = await execAsync (
30+ 'minikube ip 2>/dev/null || echo "localhost"'
31+ ) ;
3032 if ( minikubeIPOutput . trim ( ) ) {
3133 minikubeIP = minikubeIPOutput . trim ( ) ;
3234 }
3335 } catch ( ipError ) {
3436 console . log ( 'Could not get minikube IP, using localhost' ) ;
3537 }
36-
38+
3739 console . log ( 'Using IP:' , minikubeIP ) ;
38-
40+
3941 // Get all namespaces
4042 const { stdout : namespacesOutput } = await execAsync ( 'kubectl get namespaces -o json' ) ;
4143 const namespaces = JSON . parse ( namespacesOutput ) ;
42-
44+
4345 // Filter for eVault namespaces
4446 const evaultNamespaces = namespaces . items
4547 . filter ( ( ns : any ) => ns . metadata . name . startsWith ( 'evault-' ) )
4648 . map ( ( ns : any ) => ns . metadata . name ) ;
47-
49+
4850 console . log ( 'Found eVault namespaces:' , evaultNamespaces ) ;
49-
51+
5052 let allEVaults : EVault [ ] = [ ] ;
5153
5254 // Get services and pods from each eVault namespace
5355 for ( const namespace of evaultNamespaces ) {
5456 try {
5557 // Get services in this namespace as JSON
56- const { stdout : servicesOutput } = await execAsync ( `kubectl get services -n ${ namespace } -o json` ) ;
58+ const { stdout : servicesOutput } = await execAsync (
59+ `kubectl get services -n ${ namespace } -o json`
60+ ) ;
5761 const services = JSON . parse ( servicesOutput ) ;
58-
62+
5963 // Get pods in this namespace as JSON
60- const { stdout : podsOutput } = await execAsync ( `kubectl get pods -n ${ namespace } -o json` ) ;
64+ const { stdout : podsOutput } = await execAsync (
65+ `kubectl get pods -n ${ namespace } -o json`
66+ ) ;
6167 const pods = JSON . parse ( podsOutput ) ;
62-
68+
6369 console . log ( `=== SERVICES FOR ${ namespace } ===` ) ;
6470 console . log ( JSON . stringify ( services , null , 2 ) ) ;
6571 console . log ( `=== PODS FOR ${ namespace } ===` ) ;
6672 console . log ( JSON . stringify ( pods , null , 2 ) ) ;
6773 console . log ( `=== END DATA ===` ) ;
68-
74+
6975 if ( services . items && services . items . length > 0 ) {
7076 for ( const service of services . items ) {
7177 const serviceName = service . metadata . name ;
7278 const serviceType = service . spec . type ;
7379 const ports = service . spec . ports ;
74-
80+
7581 console . log ( `Service: ${ serviceName } , Type: ${ serviceType } , Ports:` , ports ) ;
76-
82+
7783 // Find NodePort for NodePort services
7884 let nodePort = null ;
7985 if ( serviceType === 'NodePort' && ports ) {
@@ -84,9 +90,9 @@ export const GET: RequestHandler = async () => {
8490 }
8591 }
8692 }
87-
93+
8894 console . log ( `NodePort: ${ nodePort } ` ) ;
89-
95+
9096 // Get pod data for this service
9197 let podData = {
9298 status : 'Unknown' ,
@@ -98,28 +104,39 @@ export const GET: RequestHandler = async () => {
98104 node : 'N/A' ,
99105 podName : 'N/A'
100106 } ;
101-
107+
102108 if ( pods . items && pods . items . length > 0 ) {
103109 // Find pod that matches this service (usually same name or has service label)
104- const matchingPod = pods . items . find ( ( pod : any ) =>
105- pod . metadata . name . includes ( serviceName . replace ( '-service' , '' ) ) ||
106- pod . metadata . labels ?. app === 'evault'
110+ const matchingPod = pods . items . find (
111+ ( pod : any ) =>
112+ pod . metadata . name . includes (
113+ serviceName . replace ( '-service' , '' )
114+ ) || pod . metadata . labels ?. app === 'evault'
107115 ) ;
108-
116+
109117 if ( matchingPod ) {
110118 const pod = matchingPod ;
111- const readyCount = pod . status . containerStatuses ?. filter ( ( cs : any ) => cs . ready ) . length || 0 ;
119+ const readyCount =
120+ pod . status . containerStatuses ?. filter ( ( cs : any ) => cs . ready )
121+ . length || 0 ;
112122 const totalCount = pod . status . containerStatuses ?. length || 0 ;
113- const restarts = pod . status . containerStatuses ?. reduce ( ( sum : number , cs : any ) => sum + ( cs . restartCount || 0 ) , 0 ) || 0 ;
114-
123+ const restarts =
124+ pod . status . containerStatuses ?. reduce (
125+ ( sum : number , cs : any ) => sum + ( cs . restartCount || 0 ) ,
126+ 0
127+ ) || 0 ;
128+
115129 // Calculate age
116130 const creationTime = new Date ( pod . metadata . creationTimestamp ) ;
117131 const now = new Date ( ) ;
118132 const ageMs = now . getTime ( ) - creationTime . getTime ( ) ;
119133 const ageDays = Math . floor ( ageMs / ( 1000 * 60 * 60 * 24 ) ) ;
120- const ageHours = Math . floor ( ( ageMs % ( 1000 * 60 * 60 * 24 ) ) / ( 1000 * 60 * 60 ) ) ;
121- const age = ageDays > 0 ? `${ ageDays } d${ ageHours } h` : `${ ageHours } h` ;
122-
134+ const ageHours = Math . floor (
135+ ( ageMs % ( 1000 * 60 * 60 * 24 ) ) / ( 1000 * 60 * 60 )
136+ ) ;
137+ const age =
138+ ageDays > 0 ? `${ ageDays } d${ ageHours } h` : `${ ageHours } h` ;
139+
123140 podData = {
124141 status : pod . status . phase || 'Unknown' ,
125142 age : age ,
@@ -132,18 +149,18 @@ export const GET: RequestHandler = async () => {
132149 } ;
133150 }
134151 }
135-
152+
136153 // Extract the eVault ID from the namespace
137154 const evaultId = namespace . replace ( 'evault-' , '' ) ;
138-
155+
139156 // Generate service URL
140157 let serviceUrl = '' ;
141158 if ( nodePort ) {
142159 serviceUrl = `http://${ minikubeIP } :${ nodePort } ` ;
143160 }
144-
161+
145162 console . log ( `Service URL: ${ serviceUrl } ` ) ;
146-
163+
147164 allEVaults . push ( {
148165 id : serviceName ,
149166 name : serviceName ,
@@ -172,4 +189,4 @@ export const GET: RequestHandler = async () => {
172189 console . error ( 'Error fetching eVaults:' , error ) ;
173190 return json ( { error : 'Failed to fetch eVaults' , evaults : [ ] } , { status : 500 } ) ;
174191 }
175- } ;
192+ } ;
0 commit comments