Skip to content

Commit e7cd717

Browse files
author
Jakub Smolar
committed
Add Grafana deploy
1 parent e970e74 commit e7cd717

10 files changed

Lines changed: 139 additions & 0 deletions

File tree

base/grafana/deploy-grafana.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -exuo pipefail
4+
command -v envsubst
5+
6+
FILE_ROOT=${BASH_SOURCE%/*}
7+
NAMESPACE=${NAMESPACE:=tools}
8+
9+
export FILE_ROOT NAMESPACE
10+
11+
# make sure user-workloads are enabled
12+
USER_WORKLOADS=$(oc get cm/cluster-monitoring-config -n openshift-monitoring -ojsonpath='{.data.config\.yaml}')
13+
14+
if ! [ "$USER_WORKLOADS" = "enableUserWorkload: true" ]; then
15+
echo "User Workload is not enabled"
16+
exit ;
17+
fi
18+
19+
envsubst < "${FILE_ROOT}"/operator-group.yaml | oc apply -n "${NAMESPACE}" -f -
20+
oc apply -f "${FILE_ROOT}"/subscription.yaml -n ${NAMESPACE}
21+
22+
oc wait -n "${NAMESPACE}" --for=jsonpath=status.installPlanRef.name subscription grafana-operator --timeout=120s
23+
oc wait -n "${NAMESPACE}" installplan "$(oc get -n "${NAMESPACE}" subscription grafana-operator -o=jsonpath='{.status.installPlanRef.name}')" --for=condition=Installed --timeout=120s
24+
25+
oc -n "$NAMESPACE" apply -f "$FILE_ROOT"/grafana.yaml
26+
27+
oc adm policy add-cluster-role-to-user cluster-monitoring-view -z grafana-sa -n "$NAMESPACE"
28+
29+
TOKEN="$(oc serviceaccounts new-token grafana-sa -n "$NAMESPACE")"
30+
THANOS_URL="$(oc get route/thanos-querier -n openshift-monitoring -ojsonpath='{.spec.host}')"
31+
export TOKEN THANOS_URL
32+
33+
envsubst < "$FILE_ROOT"/grafanadatasource.yaml | oc -n "$NAMESPACE" apply -f -
34+
35+
unset TOKEN
36+

base/grafana/grafana.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: grafana.integreatly.org/v1beta1
2+
kind: Grafana
3+
metadata:
4+
name: grafana
5+
labels:
6+
dashboards: grafana
7+
folders: grafana
8+
spec:
9+
config:
10+
auth.anonymous:
11+
enabled: 'true'
12+
org_role: Admin
13+
auth.basic:
14+
enabled: 'true'
15+
log:
16+
mode: console
17+
security:
18+
admin_password: admin
19+
admin_user: admin
20+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
kind: GrafanaDatasource
2+
apiVersion: grafana.integreatly.org/v1beta1
3+
metadata:
4+
name: grafanadatasource
5+
spec:
6+
datasource:
7+
access: proxy
8+
editable: true
9+
isDefault: true
10+
jsonData:
11+
httpHeaderName1: 'Authorization'
12+
timeInterval: 5s
13+
tlsSkipVerify: true
14+
name: Prometheus
15+
secureJsonData:
16+
httpHeaderValue1: 'Bearer $TOKEN'
17+
type: prometheus
18+
url: 'https://$THANOS_URL'
19+
instanceSelector:
20+
matchLabels:
21+
dashboards: grafana
22+
plugins:
23+
- name: grafana-clock-panel
24+
version: 1.3.0

base/grafana/operator-group.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
apiVersion: operators.coreos.com/v1
3+
kind: OperatorGroup
4+
metadata:
5+
name: ${NAMESPACE}
6+
spec:
7+
targetNamespaces:
8+
- ${NAMESPACE}

base/grafana/subscription.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
apiVersion: operators.coreos.com/v1alpha1
3+
kind: Subscription
4+
metadata:
5+
name: grafana-operator
6+
spec:
7+
channel: v5
8+
installPlanApproval: Automatic
9+
name: grafana-operator
10+
source: community-operators
11+
sourceNamespace: openshift-marketplace
12+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: integreatly.org/v1alpha1
3+
kind: GrafanaDashboard
4+
metadata:
5+
name: app-developer-dashboard
6+
namespace: <your-grafana-namespace>
7+
spec:
8+
json:
9+
url: "https://raw.githubusercontent.com/Kuadrant/kuadrant-operator/main/examples/dashboards/app_developer.json"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
apiVersion: integreatly.org/v1alpha1
3+
kind: GrafanaDashboard
4+
metadata:
5+
name: business-user-dashboard
6+
namespace: <your-grafana-namespace>
7+
spec:
8+
json:
9+
url: "https://raw.githubusercontent.com/Kuadrant/kuadrant-operator/main/examples/dashboards/business_user.json"
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: kustomize.config.k8s.io/v1beta1
3+
kind: Kustomization
4+
5+
resources:
6+
- app_developer_dashboard.yaml
7+
- business_user_dashboard.yaml
8+
- platform_engineer_dashboard.yaml
9+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
apiVersion: integreatly.org/v1alpha1
3+
kind: GrafanaDashboard
4+
metadata:
5+
name: platform-engineer-dashboard
6+
namespace: <your-grafana-namespace>
7+
spec:
8+
json:
9+
url: "https://raw.githubusercontent.com/Kuadrant/kuadrant-operator/main/examples/dashboards/platform_engineer.json"
10+

overlays/kuadrant/kustomization.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ resources:
66
- ../../base/mockserver/
77
- ../../base/jaeger/
88
- ../../base/keycloak-deployment/
9+
- /grafana-dashboards/
910

1011
images:
1112
- name: quay.io/rh_integration/go-httpbin

0 commit comments

Comments
 (0)