mirror of https://github.com/rancher/ui.git
K8s view in api action
This commit is contained in:
parent
739374128f
commit
a04bf5b8c1
|
|
@ -12,6 +12,25 @@ var K8sResource = Resource.extend({
|
|||
}
|
||||
});
|
||||
},
|
||||
|
||||
goToApi: function() {
|
||||
var endpoint = this.get('endpoint.absolute'); // http://e.f.g.h/ , does not include version. e.f.g.h is where the API actually is.
|
||||
var projectId = this.get(`tab-session.${C.TABSESSION.PROJECT}`);
|
||||
var relative = this.linkFor('self');
|
||||
var url = `${endpoint}r/projects/${projectId}/kubernetes${relative}`;
|
||||
|
||||
// For local development where API doesn't match origin, add basic auth token
|
||||
if ( url.indexOf(window.location.origin) !== 0 )
|
||||
{
|
||||
var token = this.get('cookies').get(C.COOKIE.TOKEN);
|
||||
if ( token )
|
||||
{
|
||||
url = Util.addAuthorization(url, C.USER.BASIC_BEARER, token);
|
||||
}
|
||||
}
|
||||
|
||||
window.open(url, '_blank');
|
||||
},
|
||||
},
|
||||
|
||||
linkFor: function(name) {
|
||||
|
|
@ -70,9 +89,10 @@ var K8sResource = Resource.extend({
|
|||
|
||||
availableActions: function() {
|
||||
var choices = [
|
||||
{ label: 'Edit', icon: 'icon icon-edit', action: 'edit', enabled: true },
|
||||
{ label: 'Edit', icon: 'icon icon-edit', action: 'edit', enabled: true },
|
||||
{ label: 'View in API', icon: 'icon icon-external-link', action: 'goToApi', enabled: true },
|
||||
{ divider: true },
|
||||
{ label: 'Delete', icon: 'icon icon-trash', action: 'promptDelete', enabled: true, altAction: 'delete', color: 'text-warning' },
|
||||
{ label: 'Delete', icon: 'icon icon-trash', action: 'promptDelete', enabled: true, altAction: 'delete', color: 'text-warning' },
|
||||
];
|
||||
|
||||
return choices;
|
||||
|
|
|
|||
|
|
@ -63,9 +63,7 @@ module.exports = function(environment) {
|
|||
apiEndpoint: '/v1',
|
||||
catalogServer: '',
|
||||
catalogEndpoint: '/v1-catalog',
|
||||
kubernetesServer: '',
|
||||
kubernetesEndpoint: '/r/kubernetes',
|
||||
kubectlServer: '',
|
||||
kubectlEndpoint: '/r/kubectld:8091/v1-kubectl',
|
||||
proxyEndpoint: '/v1/proxy',
|
||||
wsEndpoint: '/v1/subscribe' +
|
||||
|
|
@ -138,28 +136,6 @@ module.exports = function(environment) {
|
|||
ENV.APP.catalogServer = '';
|
||||
}
|
||||
|
||||
// Override the K8s server/endpoint with environment var
|
||||
server = process.env.KUBERNETES;
|
||||
if ( server )
|
||||
{
|
||||
ENV.APP.kubernetesServer = normalizeHost(server,8090);
|
||||
}
|
||||
else if (environment === 'production')
|
||||
{
|
||||
ENV.APP.kubernetesServer = '';
|
||||
}
|
||||
|
||||
// Override the Kubectl server/endpoint with environment var
|
||||
server = process.env.KUBECTL;
|
||||
if ( server )
|
||||
{
|
||||
ENV.APP.kubectlServer = normalizeHost(server,8091);
|
||||
}
|
||||
else if (environment === 'production')
|
||||
{
|
||||
ENV.APP.kubectlServer = '';
|
||||
}
|
||||
|
||||
var pl = process.env.PL;
|
||||
if ( pl )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -75,49 +75,7 @@ module.exports = function(app, options) {
|
|||
console.log('Catalog Proxy', req.method, 'to', req.url);
|
||||
catalogProxy.web(req, res);
|
||||
});
|
||||
|
||||
// Kubernetes API
|
||||
var kubernetesPath = config.kubernetesEndpoint;
|
||||
// Default catalog to the regular API
|
||||
var kubernetesServer = config.kubernetesServer || config.apiServer;
|
||||
console.log('Proxying Kubernetes to', kubernetesServer);
|
||||
app.use(kubernetesPath, function(req, res, next) {
|
||||
req.headers['X-Forwarded-Proto'] = req.protocol;
|
||||
var kubernetesProxy = HttpProxy.createProxyServer({
|
||||
xfwd: false,
|
||||
target: kubernetesServer
|
||||
});
|
||||
|
||||
kubernetesProxy.on('error', onProxyError);
|
||||
|
||||
// Don't include root path in proxied request
|
||||
// req.url = path.join(kubernetesPath, req.url);
|
||||
|
||||
console.log('Kubernetes Proxy', req.method, 'to', req.url);
|
||||
kubernetesProxy.web(req, res);
|
||||
});
|
||||
|
||||
// Kubectl API
|
||||
var kubectlPath = config.kubectlEndpoint;
|
||||
// Default catalog to the regular API
|
||||
var kubectlServer = config.kubectlServer || config.kubernetesServer || config.apiServer;
|
||||
console.log('Proxying Kubectl to', kubectlServer);
|
||||
app.use(kubectlPath, function(req, res, next) {
|
||||
req.headers['X-Forwarded-Proto'] = req.protocol;
|
||||
var kubectlProxy = HttpProxy.createProxyServer({
|
||||
xfwd: false,
|
||||
target: kubectlServer
|
||||
});
|
||||
|
||||
kubectlProxy.on('error', onProxyError);
|
||||
|
||||
// include root path in proxied request
|
||||
req.url = path.join(kubectlPath, req.url);
|
||||
|
||||
console.log('Kubectl Proxy', req.method, 'to', req.url);
|
||||
kubectlProxy.web(req, res);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function onProxyError(err, req, res) {
|
||||
console.log('Proxy Error: on', req.method,'to', req.url,':', err);
|
||||
|
|
|
|||
Loading…
Reference in New Issue