@@ -26,54 +26,60 @@ export const GET: RequestHandler = async () => {
26
26
// Get minikube IP for NodePort services
27
27
let minikubeIP = 'localhost' ;
28
28
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
+ ) ;
30
32
if ( minikubeIPOutput . trim ( ) ) {
31
33
minikubeIP = minikubeIPOutput . trim ( ) ;
32
34
}
33
35
} catch ( ipError ) {
34
36
console . log ( 'Could not get minikube IP, using localhost' ) ;
35
37
}
36
-
38
+
37
39
console . log ( 'Using IP:' , minikubeIP ) ;
38
-
40
+
39
41
// Get all namespaces
40
42
const { stdout : namespacesOutput } = await execAsync ( 'kubectl get namespaces -o json' ) ;
41
43
const namespaces = JSON . parse ( namespacesOutput ) ;
42
-
44
+
43
45
// Filter for eVault namespaces
44
46
const evaultNamespaces = namespaces . items
45
47
. filter ( ( ns : any ) => ns . metadata . name . startsWith ( 'evault-' ) )
46
48
. map ( ( ns : any ) => ns . metadata . name ) ;
47
-
49
+
48
50
console . log ( 'Found eVault namespaces:' , evaultNamespaces ) ;
49
-
51
+
50
52
let allEVaults : EVault [ ] = [ ] ;
51
53
52
54
// Get services and pods from each eVault namespace
53
55
for ( const namespace of evaultNamespaces ) {
54
56
try {
55
57
// 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
+ ) ;
57
61
const services = JSON . parse ( servicesOutput ) ;
58
-
62
+
59
63
// 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
+ ) ;
61
67
const pods = JSON . parse ( podsOutput ) ;
62
-
68
+
63
69
console . log ( `=== SERVICES FOR ${ namespace } ===` ) ;
64
70
console . log ( JSON . stringify ( services , null , 2 ) ) ;
65
71
console . log ( `=== PODS FOR ${ namespace } ===` ) ;
66
72
console . log ( JSON . stringify ( pods , null , 2 ) ) ;
67
73
console . log ( `=== END DATA ===` ) ;
68
-
74
+
69
75
if ( services . items && services . items . length > 0 ) {
70
76
for ( const service of services . items ) {
71
77
const serviceName = service . metadata . name ;
72
78
const serviceType = service . spec . type ;
73
79
const ports = service . spec . ports ;
74
-
80
+
75
81
console . log ( `Service: ${ serviceName } , Type: ${ serviceType } , Ports:` , ports ) ;
76
-
82
+
77
83
// Find NodePort for NodePort services
78
84
let nodePort = null ;
79
85
if ( serviceType === 'NodePort' && ports ) {
@@ -84,9 +90,9 @@ export const GET: RequestHandler = async () => {
84
90
}
85
91
}
86
92
}
87
-
93
+
88
94
console . log ( `NodePort: ${ nodePort } ` ) ;
89
-
95
+
90
96
// Get pod data for this service
91
97
let podData = {
92
98
status : 'Unknown' ,
@@ -98,28 +104,39 @@ export const GET: RequestHandler = async () => {
98
104
node : 'N/A' ,
99
105
podName : 'N/A'
100
106
} ;
101
-
107
+
102
108
if ( pods . items && pods . items . length > 0 ) {
103
109
// 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'
107
115
) ;
108
-
116
+
109
117
if ( matchingPod ) {
110
118
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 ;
112
122
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
+
115
129
// Calculate age
116
130
const creationTime = new Date ( pod . metadata . creationTimestamp ) ;
117
131
const now = new Date ( ) ;
118
132
const ageMs = now . getTime ( ) - creationTime . getTime ( ) ;
119
133
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
+
123
140
podData = {
124
141
status : pod . status . phase || 'Unknown' ,
125
142
age : age ,
@@ -132,18 +149,18 @@ export const GET: RequestHandler = async () => {
132
149
} ;
133
150
}
134
151
}
135
-
152
+
136
153
// Extract the eVault ID from the namespace
137
154
const evaultId = namespace . replace ( 'evault-' , '' ) ;
138
-
155
+
139
156
// Generate service URL
140
157
let serviceUrl = '' ;
141
158
if ( nodePort ) {
142
159
serviceUrl = `http://${ minikubeIP } :${ nodePort } ` ;
143
160
}
144
-
161
+
145
162
console . log ( `Service URL: ${ serviceUrl } ` ) ;
146
-
163
+
147
164
allEVaults . push ( {
148
165
id : serviceName ,
149
166
name : serviceName ,
@@ -172,4 +189,4 @@ export const GET: RequestHandler = async () => {
172
189
console . error ( 'Error fetching eVaults:' , error ) ;
173
190
return json ( { error : 'Failed to fetch eVaults' , evaults : [ ] } , { status : 500 } ) ;
174
191
}
175
- } ;
192
+ } ;
0 commit comments