diff --git a/jsonnet/kube-prometheus/grafana/grafana.libsonnet b/jsonnet/kube-prometheus/grafana/grafana.libsonnet new file mode 100644 index 0000000000000000000000000000000000000000..d20c0b70be9d24c937f49ad4ec6bea5e0cddd160 --- /dev/null +++ b/jsonnet/kube-prometheus/grafana/grafana.libsonnet @@ -0,0 +1,85 @@ +local defaults = { + local defaults = self, + name: 'grafana', + namespace: error 'must provide namespace', + version: error 'must provide version', + // image: error 'must provide image', + imageRepos: 'grafana/grafana', + resources: { + requests: { cpu: '100m', memory: '100Mi' }, + limits: { cpu: '200m', memory: '200Mi' }, + }, + commonLabels:: { + 'app.kubernetes.io/name': defaults.name, + 'app.kubernetes.io/version': defaults.version, + 'app.kubernetes.io/component': 'grafana', + 'app.kubernetes.io/part-of': 'kube-prometheus', + }, + selectorLabels:: { + [labelName]: defaults.commonLabels[labelName] + for labelName in std.objectFields(defaults.commonLabels) + if !std.setMember(labelName, ['app.kubernetes.io/version']) + }, + prometheusName: error 'must provide prometheus name', + dashboards: {}, +}; + +function(params) { + local g = self, + config:: defaults + params, + //local g.config = defaults + params, + // Safety check + assert std.isObject(g.config.resources), + + local glib = (import 'github.com/brancz/kubernetes-grafana/grafana/grafana.libsonnet') + { + _config+:: { + namespace: g.config.namespace, + versions+:: { + grafana: g.config.version, + }, + imageRepos+:: { + grafana: g.config.imageRepos, + }, + prometheus+:: { + name: g.config.prometheusName, + }, + grafana+:: { + labels: g.config.commonLabels, + dashboards: g.config.dashboards, + resources: g.config.resources, + }, + }, + }, + + service: glib.grafana.service, + serviceAccount: glib.grafana.serviceAccount, + deployment: glib.grafana.deployment, + dashboardDatasources: glib.grafana.dashboardDatasources, + dashboardSources: glib.grafana.dashboardSources, + + dashboardDefinitions: if std.length(g.config.dashboards) > 0 then { + apiVersion: 'v1', + kind: 'ConfigMapList', + items: g.dashboardDefinitions, + }, + serviceMonitor: { + apiVersion: 'monitoring.coreos.com/v1', + kind: 'ServiceMonitor', + metadata: { + name: 'grafana', + namespace: g.config.namespace, + labels: g.config.commonLabels, + }, + spec: { + selector: { + matchLabels: { + app: 'grafana', + }, + }, + endpoints: [{ + port: 'http', + interval: '15s', + }], + }, + }, +} diff --git a/jsonnet/kube-prometheus/kube-prometheus.libsonnet b/jsonnet/kube-prometheus/kube-prometheus.libsonnet index 6d8710a8ee9818a35ca1d8f00a01351ec0fc5c61..709cbfe905609e06cee6379853ab5f7903295aff 100644 --- a/jsonnet/kube-prometheus/kube-prometheus.libsonnet +++ b/jsonnet/kube-prometheus/kube-prometheus.libsonnet @@ -1,6 +1,7 @@ local alertmanager = import './alertmanager/alertmanager.libsonnet'; local blackboxExporter = import './blackbox-exporter/blackbox-exporter.libsonnet'; local customMixin = import './mixin/custom.libsonnet'; +local grafana = import './grafana/grafana.libsonnet'; local kubeStateMetrics = import './kube-state-metrics/kube-state-metrics.libsonnet'; local kubernetesMixin = import './mixin/kubernetes.libsonnet'; local nodeExporter = import './node-exporter/node-exporter.libsonnet'; @@ -9,8 +10,6 @@ local prometheusOperator = import './prometheus-operator/prometheus-operator.lib local prometheus = import './prometheus/prometheus.libsonnet'; local prometheusOperator = import './prometheus-operator/prometheus-operator.libsonnet'; - -(import 'github.com/brancz/kubernetes-grafana/grafana/grafana.libsonnet') + { alertmanager: alertmanager({ name: $._config.alertmanagerName, @@ -26,6 +25,13 @@ local prometheusOperator = import './prometheus-operator/prometheus-operator.lib version: '0.18.0', image: 'quay.io/prometheus/blackbox-exporter:v0.18.0', }), + grafana: grafana({ + namespace: $._config.namespace, + version: '7.3.5', + image: 'grafana/grafana:v7.3.7', + dashboards: {}, + prometheusName: $._config.prometheusName, + }), kubeStateMetrics: kubeStateMetrics({ namespace: $._config.namespace, version: '1.9.7', @@ -56,7 +62,7 @@ local prometheusOperator = import './prometheus-operator/prometheus-operator.lib namespace: $._config.namespace, version: '0.8.2', image: 'directxman12/k8s-prometheus-adapter:v0.8.2', - prometheusURL: 'http://prometheus-' + $._config.prometheus.name + '.' + $._config.namespace + '.svc.cluster.local:9090/', + prometheusURL: 'http://prometheus-' + $._config.prometheusName + '.' + $._config.namespace + '.svc.cluster.local:9090/', }), prometheusOperator: prometheusOperator({ namespace: $._config.namespace, @@ -90,36 +96,6 @@ local prometheusOperator = import './prometheus-operator/prometheus-operator.lib }, }, }, - - grafana+:: { - local dashboardDefinitions = super.dashboardDefinitions, - - dashboardDefinitions: { - apiVersion: 'v1', - kind: 'ConfigMapList', - items: dashboardDefinitions, - }, - serviceMonitor: { - apiVersion: 'monitoring.coreos.com/v1', - kind: 'ServiceMonitor', - metadata: { - name: 'grafana', - namespace: $._config.namespace, - labels: $._config.grafana.labels, - }, - spec: { - selector: { - matchLabels: { - app: 'grafana', - }, - }, - endpoints: [{ - port: 'http', - interval: '15s', - }], - }, - }, - }, } + { _config+:: { namespace: 'default', @@ -129,22 +105,5 @@ local prometheusOperator = import './prometheus-operator/prometheus-operator.lib role: 'alert-rules', prometheus: $._config.prometheusName, }, - - versions+:: { grafana: '7.3.5' }, - - grafana+:: { - labels: { - 'app.kubernetes.io/name': 'grafana', - 'app.kubernetes.io/version': $._config.versions.grafana, - 'app.kubernetes.io/component': 'grafana', - 'app.kubernetes.io/part-of': 'kube-prometheus', - }, - // FIXME(paulfantom): Same as with rules and alerts. - // This should be gathering all dashboards from components without having to enumerate all dashboards. - dashboards: {}, - //$.mixins.nodeExporter.grafanaDashboards + - //$.mixins.kubernetes.grafanaDashboards, - //$.mixins.prometheus.grafanaDashboards, - }, }, }