Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Grafana deploy #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions base/grafana/deploy-grafana.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -exuo pipefail
command -v envsubst

FILE_ROOT=${BASH_SOURCE%/*}
NAMESPACE=${NAMESPACE:=tools}

export FILE_ROOT NAMESPACE

# make sure user-workloads are enabled
USER_WORKLOADS=$(oc get cm/cluster-monitoring-config -n openshift-monitoring -ojsonpath='{.data.config\.yaml}')

if ! [ "$USER_WORKLOADS" = "enableUserWorkload: true" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok for an empty cluster, but ROSA for example has a lot more data there

echo "User Workload is not enabled"
exit ;
fi

envsubst < "${FILE_ROOT}"/operator-group.yaml | oc apply -n "${NAMESPACE}" -f -
oc apply -f "${FILE_ROOT}"/subscription.yaml -n ${NAMESPACE}

oc wait -n "${NAMESPACE}" --for=jsonpath=status.installPlanRef.name subscription grafana-operator --timeout=120s
oc wait -n "${NAMESPACE}" installplan "$(oc get -n "${NAMESPACE}" subscription grafana-operator -o=jsonpath='{.status.installPlanRef.name}')" --for=condition=Installed --timeout=120s

oc -n "$NAMESPACE" apply -f "$FILE_ROOT"/grafana.yaml

oc adm policy add-cluster-role-to-user cluster-monitoring-view -z grafana-sa -n "$NAMESPACE"

TOKEN="$(oc serviceaccounts new-token grafana-sa -n "$NAMESPACE")"
THANOS_URL="$(oc get route/thanos-querier -n openshift-monitoring -ojsonpath='{.spec.host}')"
export TOKEN THANOS_URL

envsubst < "$FILE_ROOT"/grafanadatasource.yaml | oc -n "$NAMESPACE" apply -f -

unset TOKEN

20 changes: 20 additions & 0 deletions base/grafana/grafana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: grafana.integreatly.org/v1beta1
kind: Grafana
metadata:
name: grafana
labels:
dashboards: grafana
folders: grafana
spec:
config:
auth.anonymous:
enabled: 'true'
org_role: Admin
auth.basic:
enabled: 'true'
log:
mode: console
security:
admin_password: admin
admin_user: admin

24 changes: 24 additions & 0 deletions base/grafana/grafanadatasource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
kind: GrafanaDatasource
apiVersion: grafana.integreatly.org/v1beta1
metadata:
name: grafanadatasource
spec:
datasource:
access: proxy
editable: true
isDefault: true
jsonData:
httpHeaderName1: 'Authorization'
timeInterval: 5s
tlsSkipVerify: true
name: Prometheus
secureJsonData:
httpHeaderValue1: 'Bearer $TOKEN'
type: prometheus
url: 'https://$THANOS_URL'
instanceSelector:
matchLabels:
dashboards: grafana
plugins:
- name: grafana-clock-panel
version: 1.3.0
8 changes: 8 additions & 0 deletions base/grafana/operator-group.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: ${NAMESPACE}
spec:
targetNamespaces:
- ${NAMESPACE}
12 changes: 12 additions & 0 deletions base/grafana/subscription.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: grafana-operator
spec:
channel: v5
installPlanApproval: Automatic
name: grafana-operator
source: community-operators
sourceNamespace: openshift-marketplace

9 changes: 9 additions & 0 deletions overlays/kuadrant/grafana-dashboards/app_developer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: integreatly.org/v1alpha1
kind: GrafanaDashboard
metadata:
name: app-developer-dashboard
namespace: <your-grafana-namespace>
spec:
json:
url: "https://raw.githubusercontent.com/Kuadrant/kuadrant-operator/main/examples/dashboards/app_developer.json"
10 changes: 10 additions & 0 deletions overlays/kuadrant/grafana-dashboards/business_user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: integreatly.org/v1alpha1
kind: GrafanaDashboard
metadata:
name: business-user-dashboard
namespace: <your-grafana-namespace>
spec:
json:
url: "https://raw.githubusercontent.com/Kuadrant/kuadrant-operator/main/examples/dashboards/business_user.json"

9 changes: 9 additions & 0 deletions overlays/kuadrant/grafana-dashboards/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- app_developer_dashboard.yaml
- business_user_dashboard.yaml
- platform_engineer_dashboard.yaml

10 changes: 10 additions & 0 deletions overlays/kuadrant/grafana-dashboards/platform_engineer.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not look like json (same as other 2 files)

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: integreatly.org/v1alpha1
kind: GrafanaDashboard
metadata:
name: platform-engineer-dashboard
namespace: <your-grafana-namespace>
spec:
json:
url: "https://raw.githubusercontent.com/Kuadrant/kuadrant-operator/main/examples/dashboards/platform_engineer.json"

1 change: 1 addition & 0 deletions overlays/kuadrant/kustomization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ resources:
- ../../base/mockserver/
- ../../base/jaeger/
- ../../base/keycloak-deployment/
- /grafana-dashboards/

images:
- name: quay.io/rh_integration/go-httpbin
Expand Down