Skip to content

Commit f2dbdd5

Browse files
lins05ash211
authored andcommitted
Fixed loading the executors page through the kubectl proxy. (#95)
Fix apache-spark-on-k8s#87
1 parent 6a6e4aa commit f2dbdd5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

core/src/main/resources/org/apache/spark/ui/static/executorspage.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,28 @@ $(document).ajaxStart(function () {
5454
$.blockUI({message: '<h3>Loading Executors Page...</h3>'});
5555
});
5656

57+
function findKubernetesServiceBaseURI() {
58+
var k8sProxyPattern = '/api/v1/proxy/namespaces/';
59+
var k8sProxyPatternPos = document.baseURI.indexOf(k8sProxyPattern);
60+
if (k8sProxyPatternPos > 0) {
61+
// Spark is running in a kubernetes cluster, and the web ui is served
62+
// through the kubectl proxy.
63+
var remaining = document.baseURI.substr(k8sProxyPatternPos + k8sProxyPattern.length);
64+
var urlSlashesCount = remaining.split('/').length - 3;
65+
var words = document.baseURI.split('/');
66+
var baseURI = words.slice(0, words.length - urlSlashesCount).join('/');
67+
return baseURI;
68+
}
69+
70+
return null;
71+
}
72+
5773
function createTemplateURI(appId) {
74+
var kubernetesBaseURI = findKubernetesServiceBaseURI();
75+
if (kubernetesBaseURI) {
76+
return kubernetesBaseURI + '/static/executorspage-template.html';
77+
}
78+
5879
var words = document.baseURI.split('/');
5980
var ind = words.indexOf("proxy");
6081
if (ind > 0) {
@@ -70,6 +91,14 @@ function createTemplateURI(appId) {
7091
}
7192

7293
function getStandAloneppId(cb) {
94+
var kubernetesBaseURI = findKubernetesServiceBaseURI();
95+
if (kubernetesBaseURI) {
96+
var appIdAndPort = kubernetesBaseURI.split('/').slice(-1)[0];
97+
var appId = appIdAndPort.split(':')[0];
98+
cb(appId);
99+
return;
100+
}
101+
73102
var words = document.baseURI.split('/');
74103
var ind = words.indexOf("proxy");
75104
if (ind > 0) {
@@ -95,6 +124,11 @@ function getStandAloneppId(cb) {
95124
}
96125

97126
function createRESTEndPoint(appId) {
127+
var kubernetesBaseURI = findKubernetesServiceBaseURI();
128+
if (kubernetesBaseURI) {
129+
return kubernetesBaseURI + "/api/v1/applications/" + appId + "/allexecutors";
130+
}
131+
98132
var words = document.baseURI.split('/');
99133
var ind = words.indexOf("proxy");
100134
if (ind > 0) {

0 commit comments

Comments
 (0)