Skip to content

Commit

Permalink
improve prometheus operator setup script (#211)
Browse files Browse the repository at this point in the history
* refactor(prometheus-operator): improve prometheus operator setup script

* style(monitoring): tweaks per review comment
  • Loading branch information
Miles Matthias authored and louisjimenez committed Jul 2, 2019
1 parent 0289dac commit a37ddce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ This setup script assumes:

* You've already enabled Prometheus metric store in Spinnaker
* You've already installed Prometheus Operator to your cluster
* Your kubectl context is the cluster where you have Spinnaker + Prometheus Operator installed

## Usage

`./setup.sh <kubeconfig-context>`
`./setup.sh <spinnaker-namespace>`

provide an optional kubeconfig context to the script to use.

If you don't provide a context, it will use the current kubeconfig context.
provide an optional namespace, if you installed Spinnaker in a different namespace than `default` on your cluster.
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
#!/usr/bin/env bash

ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CONTEXT=${1:-$(kubectl config current-context)}


echo "Adding the Spinnaker ServiceMonitor to current context: ${CONTEXT}"

kubectl apply -f spinnaker-service-monitor.yaml
CONTEXT=$(kubectl config current-context)
NAMESPACE=${1:-default}
KUBECTL="kubectl --context $CONTEXT --namespace $NAMESPACE"
echo "Using context $CONTEXT and namespace $NAMESPACE."

echo "Adding the Spinnaker ServiceMonitor..."
$KUBECTL apply -f spinnaker-service-monitor.yaml

echo "Generating Grafana dashboard configmaps..."

for filename in $ROOT/../prometheus/*-dashboard.json; do
fn_only=$(basename $filename)
for filename in "$ROOT"/../prometheus/*-dashboard.json; do
fn_only=$(basename "$filename")
fn_root="${fn_only%.*}"
dest_file="generated_dashboards/${fn_root}.yaml"

cat grafana-dashboard.yaml.template | sed -e "s/%DASHBOARD%/${fn_root}/" > $dest_file
printf " ${fn_only}: |-\n" >> $dest_file
cat grafana-dashboard.yaml.template | sed -e "s/%DASHBOARD%/$fn_root/" > $dest_file
printf " $fn_only: |-\n" >> $dest_file

cat $filename | sed -e "/\"__inputs\"/,/],/d" \
-e "/\"__requires\"/,/],/d" \
Expand All @@ -26,7 +25,5 @@ for filename in $ROOT/../prometheus/*-dashboard.json; do
>> $dest_file
done


echo "applying dashboards as configmaps to cluster..."

kubectl apply -f generated_dashboards
echo "Applying dashboards as configmaps to cluster..."
$KUBECTL apply -f generated_dashboards

0 comments on commit a37ddce

Please sign in to comment.