From 46a22b3c4447705705c4c30ec0fe282bb6fbe128 Mon Sep 17 00:00:00 2001 From: Vishnu Kannan Date: Fri, 7 Nov 2014 21:30:31 +0000 Subject: [PATCH] Fix monitoring setup script. Remove the firewall rule created for monitoring as part of kube-down. Reuse master auth for Grafana. --- cluster/gce/util.sh | 34 +++++++++++++-------- cluster/kube-down.sh | 1 + cluster/rackspace/util.sh | 4 +++ cluster/vagrant/util.sh | 4 +++ cluster/vsphere/util.sh | 4 +++ examples/monitoring/influx-grafana-pod.json | 4 +-- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index f1732d7c52..bfd5de2d43 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -589,45 +589,53 @@ function restart-kube-proxy { # Setup monitoring using heapster and InfluxDB function setup-monitoring { - if [ $MONITORING ]; then - teardown-monitoring + if [[ "${MONITORING}" == "true" ]]; then + echo "Setting up Cluster Monitoring using Heapster." + detect-project if ! gcutil getfirewall monitoring-heapster &> /dev/null; then gcutil addfirewall monitoring-heapster \ --project "${PROJECT}" \ --norespect_terminal_width \ --sleep_between_polls "${POLL_SLEEP_INTERVAL}" \ --target_tags="${MINION_TAG}" \ - --allowed "tcp:80,tcp:8083,tcp:8086,tcp:9200"; + --allowed "tcp:80,tcp:8083,tcp:8086,tcp:9200" &> /dev/null; if [ $? -ne 0 ]; then echo "Failed to Setup Firewall for Monitoring" && false fi fi + + # Re-use master auth for Grafana + get-password + sed -i "s/HTTP_USER, \"value\": \"[^\"]*\"/HTTP_USER, \"value\": \"$KUBE_USER\"/g" "${KUBE_ROOT}/examples/monitoring/influx-grafana-pod.json" + sed -i "s/HTTP_PASS, \"value\": \"[^\"]*\"/HTTP_PASS, \"value\": \"$KUBE_PASSWORD\"/g" "${KUBE_ROOT}/examples/monitoring/influx-grafana-pod.json" local kubectl=${KUBE_ROOT}/cluster/kubectl.sh - ${kubectl} create -f "${KUBE_ROOT}/examples/monitoring/influx-grafana-pod.json" > /dev/null && - ${kubectl} create -f "${KUBE_ROOT}/examples/monitoring/influx-grafana-service.json" > /dev/null && - ${kubectl} create -f "${KUBE_ROOT}/examples/monitoring/heapster-pod.json" > /dev/null - if [ $? -ne 0 ]; then + if "${kubectl}" create -f "${KUBE_ROOT}/examples/monitoring/influx-grafana-pod.json" &> /dev/null \ + && "${kubectl}" create -f "${KUBE_ROOT}/examples/monitoring/influx-grafana-service.json" &> /dev/null \ + && "${kubectl}" create -f "${KUBE_ROOT}/examples/monitoring/heapster-pod.json" &> /dev/null; then + dashboardIP="http://$KUBE_USER:$KUBE_PASSWORD@`${kubectl} get -o json pod influx-grafana | grep hostIP | awk '{print $2}' | sed 's/[,|\"]//g'`" + echo "Grafana dashboard will be available at $dashboardIP. Wait for the monitoring dashboard to be online. Use the master user name and password for the dashboard." + else echo "Failed to Setup Monitoring" teardown-monitoring - else - dashboardIP="http://admin:admin@`${kubectl} get -o json pod influx-grafana | grep hostIP | awk '{print $2}' | sed 's/[,|\"]//g'`" - echo "Grafana dashboard will be available at $dashboardIP. Wait for the monitoring dashboard to be online." fi fi } function teardown-monitoring { - if [ $MONITORING ]; then + if [[ "${MONITORING}" == "true" ]]; then + detect-project local kubectl=${KUBE_ROOT}/cluster/kubectl.sh ${kubectl} delete pods heapster &> /dev/null || true ${kubectl} delete pods influx-grafana &> /dev/null || true ${kubectl} delete services influx-master &> /dev/null || true - gcutil deletefirewall \ + if gcutil getfirewall monitoring-heapster &> /dev/null; then + gcutil deletefirewall \ --project "${PROJECT}" \ --norespect_terminal_width \ --sleep_between_polls "${POLL_SLEEP_INTERVAL}" \ --force \ - monitoring-heapster || true > /dev/null + monitoring-heapster &> /dev/null || true + fi fi } diff --git a/cluster/kube-down.sh b/cluster/kube-down.sh index e1329b5052..8dc3ea6bca 100755 --- a/cluster/kube-down.sh +++ b/cluster/kube-down.sh @@ -27,6 +27,7 @@ source "${KUBE_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh" echo "Bringing down cluster using provider: $KUBERNETES_PROVIDER" verify-prereqs +teardown-monitoring kube-down echo "Done" diff --git a/cluster/rackspace/util.sh b/cluster/rackspace/util.sh index 28999b57d1..ae32a4db6e 100644 --- a/cluster/rackspace/util.sh +++ b/cluster/rackspace/util.sh @@ -327,6 +327,10 @@ function setup-monitoring { echo "TODO" } +function teardown-monitoring { + echo "TODO" +} + # Perform preparations required to run e2e tests function prepare-e2e() { echo "Rackspace doesn't need special preparations for e2e tests" diff --git a/cluster/vagrant/util.sh b/cluster/vagrant/util.sh index 371b6d684e..a38e40b936 100644 --- a/cluster/vagrant/util.sh +++ b/cluster/vagrant/util.sh @@ -177,6 +177,10 @@ function setup-monitoring { echo "TODO" } +function teardown-monitoring { + echo "TODO" +} + # Perform preparations required to run e2e tests function prepare-e2e() { echo "Vagrant doesn't need special preparations for e2e tests" diff --git a/cluster/vsphere/util.sh b/cluster/vsphere/util.sh index 17d77c16c6..e665d559dc 100755 --- a/cluster/vsphere/util.sh +++ b/cluster/vsphere/util.sh @@ -475,3 +475,7 @@ function test-teardown { function setup-monitoring { echo "TODO" } + +function teardown-monitoring { + echo "TODO" +} diff --git a/examples/monitoring/influx-grafana-pod.json b/examples/monitoring/influx-grafana-pod.json index 001ecdda1b..885c41adbf 100644 --- a/examples/monitoring/influx-grafana-pod.json +++ b/examples/monitoring/influx-grafana-pod.json @@ -18,8 +18,8 @@ "name": "grafana", "image": "kubernetes/heapster_grafana", "ports": [{"containerPort": 80, "hostPort": 80}], - "env": [{"name": HTTP_USER, "value": admin}, - {"name": HTTP_PASS, "value": admin}], + "env": [{"name": HTTP_USER, "value": "admin"}, + {"name": HTTP_PASS, "value": "admin"}], }, { "name": "elasticsearch", "image": "dockerfile/elasticsearch",