diff --git a/build/cluster.js b/build/cluster.js index 42b1cb80ddbea3f22b7cad00cd58398c1896679a..ab116989c0b563d95caa5c00ff3a327b1ecff09d 100644 --- a/build/cluster.js +++ b/build/cluster.js @@ -26,6 +26,11 @@ import conf from './conf'; */ const clusterHealthzUrl = `http://${conf.backend.apiServerHost}/healthz`; +/** + * The validate URL of the heapster to check that it is running. + */ +const heapsterValidateUrl = `http://${conf.backend.heapsterServerHost}/validate`; + /** * A Number, representing the ID value of the timer that is set for function which periodically * checks if cluster is running. The null means that no timer is running. @@ -34,6 +39,14 @@ const clusterHealthzUrl = `http://${conf.backend.apiServerHost}/healthz`; */ let isRunningSetIntervalHandler = null; +/** + * A Number, representing the ID value of the timer that is set for function which periodically + * checks if Heapster is running. The null means that no timer is running. + * + * @type {?number} + */ +let isHeapsterRunningSetIntervalHandler = null; + /** * Checks if cluster health check return correct status. * When custer is up and running then return 'ok'. @@ -48,6 +61,20 @@ function clusterHealthCheck(doneFn) { }); } +/** + * Checks if Heapster return debug messages. + * When Heapster is running then return some debug text otherwise server return error. + * @param {function(?Error=)} doneFn + */ +function heapsterHealthCheck(doneFn) { + childProcess.exec(`curl ${heapsterValidateUrl}`, function(err, stdout) { + if (err) { + return doneFn(new Error(err)); + } + return doneFn(stdout.trim()); + }); +} + /** * Creates cluster from scratch. * Downloads latest version of kubernetes from git repository. @@ -59,7 +86,7 @@ function clusterHealthCheck(doneFn) { * * Install golang * * Install etcd */ -gulp.task('local-up-cluster', ['spawn-cluster', 'wait-for-cluster']); +gulp.task('local-up-cluster', ['spawn-cluster', 'wait-for-cluster', 'wait-for-heapster']); /** * Spawns a local Kubernetes cluster running inside a Docker container.: @@ -75,6 +102,35 @@ gulp.task('spawn-cluster', function(doneFn) { }); }); +/** + * Checks periodically if heapster is up and running. + */ +gulp.task('wait-for-heapster', function(doneFn) { + let counter = 0; + if (!isHeapsterRunningSetIntervalHandler) { + isHeapsterRunningSetIntervalHandler = setInterval(isRunning, 1000); + } + + function isRunning() { + if (counter % 10 === 0) { + gulpUtil.log( + gulpUtil.colors.magenta( + `Waiting for a Heapster on ${conf.backend.heapsterServerHost}...`)); + } + counter += 1; + + // constantly query the heapster until it is properly running + heapsterHealthCheck(function(result) { + if (result.length > 0) { + gulpUtil.log(gulpUtil.colors.magenta('Heapster is up and running.')); + clearTimeout(isHeapsterRunningSetIntervalHandler); + isHeapsterRunningSetIntervalHandler = null; + doneFn(); + } + }); + } +}); + /** * Checks periodically if cluster is up and running. */ diff --git a/build/conf.js b/build/conf.js index dd9fb09b9cdf92c9a8bff9bf35e7dd64cc65398d..8ceaf9304df1fe1c1a90c8d394c053be9b47dc67 100644 --- a/build/conf.js +++ b/build/conf.js @@ -46,6 +46,10 @@ export default { * Address for the Kubernetes API server. */ apiServerHost: 'localhost:8080', + /** + * Address for the Heapster API server. + */ + heapsterServerHost: 'localhost:8082', }, /** diff --git a/build/hyperkube.sh b/build/hyperkube.sh index 386e10e121dc906e412f31eec3ec0dc4397070ea..75f703ff8c54257d1a900cda3e84dd2d6bb6be6e 100755 --- a/build/hyperkube.sh +++ b/build/hyperkube.sh @@ -20,6 +20,8 @@ K8S_VERSION="1.1.2" # Port of the apiserver to serve on. PORT=8080 +# Port of the heapster to serve on. +HEAPSTER_PORT=8082 docker run --net=host -d gcr.io/google_containers/etcd:2.0.12 \ /usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data @@ -43,3 +45,7 @@ docker run \ docker run -d --net=host --privileged gcr.io/google_containers/hyperkube:v${K8S_VERSION} \ /hyperkube proxy --master=http://127.0.0.1:${PORT} --v=2 + +# Runs Heapster in standalone mode +docker run --net=host -d kubernetes/heapster -port ${HEAPSTER_PORT}\ + --source=kubernetes:http://127.0.0.1:${PORT}?inClusterConfig=false&auth=""