Skip to content

Commit e239ac7

Browse files
lins05foxish
authored andcommitted
Fixed loading the executors page through the kubectl proxy. (alteryx#95)
Fix apache-spark-on-k8s#87
1 parent 1f2fd80 commit e239ac7

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
@@ -53,7 +53,28 @@ $(document).ajaxStart(function () {
5353
$.blockUI({message: '<h3>Loading Executors Page...</h3>'});
5454
});
5555

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

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

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

0 commit comments

Comments
 (0)