Fix up formatting and sed usage for heapster deploy.

Also, 'sed -i' isn't supported well across BSD and GNU versions of sed.  See http://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux.  And we were editing files that were checked in to git with a password.  Instead, do this with class sed redirection in a temp dir.

Fixes #2400.
This commit is contained in:
Joe Beda 2014-11-16 17:01:51 -08:00
parent ccc8bc8289
commit c82bd2127f

View File

@ -589,55 +589,58 @@ function restart-kube-proxy {
# Setup monitoring using heapster and InfluxDB # Setup monitoring using heapster and InfluxDB
function setup-monitoring { function setup-monitoring {
if [[ "${MONITORING}" == "true" ]]; then if [[ "${MONITORING}" == "true" ]]; then
echo "Setting up Cluster Monitoring using Heapster." 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" &> /dev/null;
if [ $? -ne 0 ]; then
echo "Failed to Setup Firewall for Monitoring" && false
fi
fi
# Re-use master auth for Grafana if ! gcutil getfirewall monitoring-heapster &> /dev/null; then
get-password if ! gcutil addfirewall monitoring-heapster \
sed -i "s/HTTP_USER, \"value\": \"[^\"]*\"/HTTP_USER, \"value\": \"$KUBE_USER\"/g" "${KUBE_ROOT}/examples/monitoring/influx-grafana-pod.json" --project "${PROJECT}" \
sed -i "s/HTTP_PASS, \"value\": \"[^\"]*\"/HTTP_PASS, \"value\": \"$KUBE_PASSWORD\"/g" "${KUBE_ROOT}/examples/monitoring/influx-grafana-pod.json" --norespect_terminal_width \
local kubectl=${KUBE_ROOT}/cluster/kubectl.sh --sleep_between_polls "${POLL_SLEEP_INTERVAL}" \
if "${kubectl}" create -f "${KUBE_ROOT}/examples/monitoring/influx-grafana-pod.json" &> /dev/null \ --target_tags="${MINION_TAG}" \
&& "${kubectl}" create -f "${KUBE_ROOT}/examples/monitoring/influx-grafana-service.json" &> /dev/null \ --allowed "tcp:80,tcp:8083,tcp:8086,tcp:9200" &> /dev/null; then
&& "${kubectl}" create -f "${KUBE_ROOT}/examples/monitoring/heapster-pod.json" &> /dev/null; then echo "Failed to set up firewall for monitoring" && false
dashboardIP="http://`${kubectl} get -o json pod influx-grafana | grep hostIP | awk '{print $2}' | sed 's/[,|\"]//g'`" fi
echo fi
echo "Grafana dashboard will be available at $dashboardIP. Wait for the monitoring dashboard to be online."
# Re-use master auth for Grafana
get-password
ensure-temp-dir
cp "${KUBE_ROOT}/examples/monitoring/influx-grafana-pod.json" "${KUBE_TEMP}/influx-grafana-pod.0.json"
sed "s/HTTP_USER, \"value\": \"[^\"]*\"/HTTP_USER, \"value\": \"$KUBE_USER\"/g" \
"${KUBE_TEMP}/influx-grafana-pod.0.json" > "${KUBE_TEMP}/influx-grafana-pod.1.json"
sed "s/HTTP_PASS, \"value\": \"[^\"]*\"/HTTP_PASS, \"value\": \"$KUBE_PASSWORD\"/g" \
"${KUBE_TEMP}/influx-grafana-pod.1.json" > "${KUBE_TEMP}/influx-grafana-pod.2.json"
local kubectl="${KUBE_ROOT}/cluster/kubectl.sh"
if "${kubectl}" create -f "${KUBE_TEMP}/influx-grafana-pod.2.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
local dashboard_url="http://$(${kubectl} get -o json pod influx-grafana | grep hostIP | awk '{print $2}' | sed 's/[,|\"]//g')"
echo
echo "Grafana dashboard will be available at $dashboard_url. Wait for the monitoring dashboard to be online."
echo "Use the master user name and password for the dashboard." echo "Use the master user name and password for the dashboard."
echo echo
else else
echo "Failed to Setup Monitoring" echo "Failed to Setup Monitoring"
teardown-monitoring teardown-monitoring
fi fi
fi fi
} }
function teardown-monitoring { function teardown-monitoring {
if [[ "${MONITORING}" == "true" ]]; then if [[ "${MONITORING}" == "true" ]]; then
detect-project local kubectl="${KUBE_ROOT}/cluster/kubectl.sh"
local kubectl=${KUBE_ROOT}/cluster/kubectl.sh "${kubectl}" delete pods heapster &> /dev/null || true
${kubectl} delete pods heapster &> /dev/null || true "${kubectl}" delete pods influx-grafana &> /dev/null || true
${kubectl} delete pods influx-grafana &> /dev/null || true "${kubectl}" delete services influx-master &> /dev/null || true
${kubectl} delete services influx-master &> /dev/null || true
if gcutil getfirewall monitoring-heapster &> /dev/null; then if gcutil getfirewall monitoring-heapster &> /dev/null; then
gcutil deletefirewall \ gcutil deletefirewall \
--project "${PROJECT}" \ --project "${PROJECT}" \
--norespect_terminal_width \ --norespect_terminal_width \
--sleep_between_polls "${POLL_SLEEP_INTERVAL}" \ --sleep_between_polls "${POLL_SLEEP_INTERVAL}" \
--force \ --force \
monitoring-heapster &> /dev/null || true monitoring-heapster &> /dev/null || true
fi fi
fi fi
} }