-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (39 loc) · 1.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import axios from 'axios'
import express from 'express'
import { readFileSync } from 'fs'
import https from 'https'
const token = (readFileSync('/var/run/secrets/kubernetes.io/serviceaccount/token')).toString()
const cacert = (readFileSync('/var/run/secrets/kubernetes.io/serviceaccount/ca.crt')).toString()
const currentNs = (readFileSync('/var/run/secrets/kubernetes.io/serviceaccount/namespace')).toString()
const httpsAgent = new https.Agent({
rejectUnauthorized: false, // (NOTE: this will disable client verification)
ca: cacert,
})
const app = express()
const port = 3000
const a = axios.create({
headers: {
"Authorization": `Bearer ${token}`
},
baseURL: `https://${process.env.KUBERNETES_SERVICE_HOST}/api/v1/`,
httpsAgent,
validateStatus: () => true
})
app.get('/healthz', async (req, res) => {
res.status(200)
res.send("OK")
})
app.get('/*', async (req, res) => {
console.log(req.path);
console.log(req.query);
const namespace = req.query?.namespace ? `namespaces/${req.query?.namespace}/` : `namespaces/${currentNs}`
const apiRes = await a.get(`${namespace}${req.path}`)
if (apiRes.status > 299) {
res.status(apiRes.status)
return
}
res.json(apiRes.data)
})
app.listen(port, () => {
console.log(`pod explorer listening on port ${port}`)
})