mirror of
https://github.com/skooner-k8s/skooner.git
synced 2026-08-24 04:16:18 +00:00
make protobuff the default method and move it as an env var in backend
This commit is contained in:
@@ -4,9 +4,11 @@ import {Notifier} from './components/notifier';
|
||||
import Error from './components/error';
|
||||
import {initRouter} from './router';
|
||||
import log from './utils/log';
|
||||
import {setContext, Context} from './utils/localStorageHelpers';
|
||||
import Button from './components/button';
|
||||
import LogoSvg from './art/k8dashSvg';
|
||||
import HamburgerSvg from './art/hamburgerSvg';
|
||||
import api from './services/api';
|
||||
|
||||
type State = {
|
||||
content?: ReactNode;
|
||||
@@ -27,6 +29,7 @@ class App extends Component<{}, State> {
|
||||
this.setState({content, contentDate: Date.now(), hasError: false});
|
||||
window.scrollTo(0, 0);
|
||||
});
|
||||
this.setContext();
|
||||
}
|
||||
|
||||
componentDidCatch(err: Error, info: any) { // eslint-disable-line class-methods-use-this
|
||||
@@ -34,6 +37,12 @@ class App extends Component<{}, State> {
|
||||
this.setState({hasError: true});
|
||||
}
|
||||
|
||||
setContext() {
|
||||
api.context().then((context: Context) => {
|
||||
setContext(context);
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const {content, contentDate, hasError, menuToggled} = this.state || {};
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ const apis = {
|
||||
exec,
|
||||
metrics: metricsFactory(),
|
||||
oidc: oidcFactory(),
|
||||
context,
|
||||
|
||||
clusterRole,
|
||||
namespace: namespaceService,
|
||||
@@ -187,4 +188,8 @@ function logs(namespace: string, name: string, container: string, tailLines: num
|
||||
}
|
||||
}
|
||||
|
||||
function context() {
|
||||
return request('/context');
|
||||
}
|
||||
|
||||
export default apis;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
const CONTEXT = 'context';
|
||||
|
||||
export type Context = {
|
||||
protoEnabled?: boolean;
|
||||
promethusEnabled?: boolean;
|
||||
}
|
||||
|
||||
export function getContextItem(item: string) {
|
||||
return getItem(CONTEXT)[item];
|
||||
}
|
||||
|
||||
export function setContext(context: Context) {
|
||||
setItem(CONTEXT, {
|
||||
protoEnabled: true,
|
||||
promethusEnabled: false,
|
||||
...context,
|
||||
});
|
||||
}
|
||||
|
||||
export function setItem(item: string, object: Object) {
|
||||
localStorage.setItem(item, JSON.stringify(object));
|
||||
}
|
||||
|
||||
export function getItem(item: string) {
|
||||
return JSON.parse(localStorage.getItem(item) || '');
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import {k8s} from '../proto/proto';
|
||||
import {getContextItem} from './localStorageHelpers';
|
||||
|
||||
const {Unknown} = k8s.io.apimachinery.pkg.runtime;
|
||||
const {NodeMetrics} = k8s.io.metrics.pkg.apis.metrics.v1beta1;
|
||||
@@ -18,36 +19,36 @@ export const kindMap: {
|
||||
| typeof EventList
|
||||
| typeof NodeList
|
||||
| typeof PodList,
|
||||
path: string
|
||||
paths: string[]
|
||||
}
|
||||
} = {
|
||||
NodeMetrics: {
|
||||
proto: NodeMetrics,
|
||||
path: '/apis/metrics.k8s.io/v1beta1/node',
|
||||
paths: ['/apis/metrics.k8s.io/v1beta1/node'],
|
||||
},
|
||||
NodeMetricsList: {
|
||||
proto: NodeMetricsList,
|
||||
path: '/apis/metrics.k8s.io/v1beta1/nodes',
|
||||
paths: ['/apis/metrics.k8s.io/v1beta1/nodes'],
|
||||
},
|
||||
PodMetrics: {
|
||||
proto: PodMetrics,
|
||||
path: '/apis/metrics.k8s.io/v1beta1/pod',
|
||||
paths: ['/apis/metrics.k8s.io/v1beta1/pod'],
|
||||
},
|
||||
PodMetricsList: {
|
||||
proto: PodMetricsList,
|
||||
path: '/apis/metrics.k8s.io/v1beta1/pods',
|
||||
paths: ['/apis/metrics.k8s.io/v1beta1/pods'],
|
||||
},
|
||||
EventList: {
|
||||
proto: EventList,
|
||||
path: 'api/v1/events',
|
||||
paths: ['api/v1/events'],
|
||||
},
|
||||
NodeList: {
|
||||
proto: NodeList,
|
||||
path: 'api/v1/nodes',
|
||||
paths: ['api/v1/nodes'],
|
||||
},
|
||||
PodList: {
|
||||
proto: PodList,
|
||||
path: 'api/v1/pods',
|
||||
paths: ['api/v1/pods', 'v1beta1/namespaces/kube-system/pods', 'v1/namespaces/kube-system/pods'],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -68,22 +69,14 @@ export function protoParser(raw: Uint8Array) {
|
||||
}
|
||||
|
||||
export function isProtoEnabled(): boolean {
|
||||
return window.localStorage.getItem('protoEnabled') === 'true';
|
||||
return getContextItem('protoEnabled');
|
||||
}
|
||||
|
||||
export function isProtoEligible(url: string) {
|
||||
for (const value of Object.values(kindMap)) {
|
||||
if (url.includes(value.path)) {
|
||||
if (value.paths.some(path => url.includes(path))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function enableProto(): void {
|
||||
window.localStorage.setItem('protoEnabled', 'true');
|
||||
}
|
||||
|
||||
export function disableProto(): void {
|
||||
window.localStorage.setItem('protoEnabled', 'false');
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ const OIDC_SECRET = process.env.OIDC_SECRET;
|
||||
const OIDC_URL = process.env.OIDC_URL;
|
||||
const OIDC_SCOPES = process.env.OIDC_SCOPES || 'openid email';
|
||||
const OIDC_METADATA = JSON.parse(process.env.OIDC_METADATA || '{}');
|
||||
const USE_PROTO = process.env.USE_PROTO !== 'false' || true;
|
||||
const clientMetadata = Object.assign({client_id: OIDC_CLIENT_ID, client_secret: OIDC_SECRET}, OIDC_METADATA);
|
||||
|
||||
console.log('OIDC_URL: ', OIDC_URL || 'None');
|
||||
@@ -50,6 +51,7 @@ if (NODE_ENV !== 'production') app.use(cors());
|
||||
app.use('/', preAuth, express.static('public'));
|
||||
app.get('/oidc', getOidc);
|
||||
app.post('/oidc', postOidc);
|
||||
app.get('/context', getContext);
|
||||
app.use('/*', createProxyMiddleware(proxySettings));
|
||||
app.use(handleErrors);
|
||||
|
||||
@@ -57,6 +59,12 @@ const port = process.env.SERVER_PORT || 4654;
|
||||
http.createServer(app).listen(port);
|
||||
console.log(`Server started. Listening on port ${port}`);
|
||||
|
||||
function getContext(req, res) {
|
||||
res.json({
|
||||
"protoEnabled": USE_PROTO,
|
||||
})
|
||||
}
|
||||
|
||||
function preAuth(req, res, next) {
|
||||
const auth = req.header('Authorization');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user