Skip to content

Commit

Permalink
Merge pull request #1450 from paulfantom/grafana-refactor
Browse files Browse the repository at this point in the history
jsonnet: include rewritten kubernetes-grafana library
  • Loading branch information
paulfantom authored Oct 22, 2021
2 parents 0bb5998 + 6aa6b78 commit cd044aa
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 115 deletions.
103 changes: 26 additions & 77 deletions jsonnet/kube-prometheus/components/grafana.libsonnet
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local kubernetesGrafana = import 'github.com/brancz/kubernetes-grafana/grafana/grafana.libsonnet';

local defaults = {
local defaults = self,
name: 'grafana',
Expand All @@ -20,88 +22,35 @@ local defaults = {
if !std.setMember(labelName, ['app.kubernetes.io/version'])
},
prometheusName: error 'must provide prometheus name',
dashboards: {},
// TODO(paulfantom): expose those to have a stable API. After kubernetes-grafana refactor those could probably be removed.
rawDashboards: {},
folderDashboards: {},
containers: [],
datasources: [],
config: {},
ldap: null,
plugins: [],
env: [],
};

function(params) {
local g = self,
_config:: defaults + params,
function(params)
local config = defaults + params;
// Safety check
assert std.isObject(g._config.resources),
assert std.isObject(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: std.split(g._config.image, ':')[0],
},
prometheus+:: {
name: g._config.prometheusName,
},
grafana+:: {
labels: g._config.commonLabels,
dashboards: g._config.dashboards,
resources: g._config.resources,
rawDashboards: g._config.rawDashboards,
folderDashboards: g._config.folderDashboards,
containers: g._config.containers,
config+: g._config.config,
ldap: g._config.ldap,
plugins+: g._config.plugins,
env: g._config.env,
} + (
// Conditionally overwrite default setting.
if std.length(g._config.datasources) > 0 then
{ datasources: g._config.datasources }
else {}
),
},
},
kubernetesGrafana(config) {
local g = self,
_config+:: config,

config: glib.grafana.config,
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 ||
std.length(g._config.rawDashboards) > 0 ||
std.length(g._config.folderDashboards) > 0 then {
apiVersion: 'v1',
kind: 'ConfigMapList',
items: glib.grafana.dashboardDefinitions,
},
serviceMonitor: {
apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor',
metadata: {
name: 'grafana',
namespace: g._config.namespace,
labels: g._config.commonLabels,
},
spec: {
selector: {
matchLabels: {
'app.kubernetes.io/name': 'grafana',
serviceMonitor: {
apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor',
metadata: {
name: 'grafana',
namespace: g._config.namespace,
labels: g._config.commonLabels,
},
spec: {
selector: {
matchLabels: {
'app.kubernetes.io/name': 'grafana',
},
},
endpoints: [{
port: 'http',
interval: '15s',
}],
},
endpoints: [{
port: 'http',
interval: '15s',
}],
},
},
}
}
2 changes: 1 addition & 1 deletion jsonnet/kube-prometheus/main.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ local utils = import './lib/utils.libsonnet';
images: {
alertmanager: 'quay.io/prometheus/alertmanager:v' + $.values.common.versions.alertmanager,
blackboxExporter: 'quay.io/prometheus/blackbox-exporter:v' + $.values.common.versions.blackboxExporter,
grafana: 'grafana/grafana:v' + $.values.common.versions.grafana,
grafana: 'grafana/grafana:' + $.values.common.versions.grafana,
kubeStateMetrics: 'k8s.gcr.io/kube-state-metrics/kube-state-metrics:v' + $.values.common.versions.kubeStateMetrics,
nodeExporter: 'quay.io/prometheus/node-exporter:v' + $.values.common.versions.nodeExporter,
prometheus: 'quay.io/prometheus/prometheus:v' + $.values.common.versions.prometheus,
Expand Down
34 changes: 17 additions & 17 deletions jsonnetfile.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"subdir": "grafana"
}
},
"version": "c3b14b24b83cfe9abf1064649d19e2d679f033fb",
"sum": "YrE4DNQsWgYWs6h0j/FjQETt8xDXdYdsslb1WK7xQEk="
"version": "199e363523104ff8b3a12483a4e3eca86372b078",
"sum": "/jDHzVAjHB4AOLkJHw1GyATX5ogZ1iMdcJXZAgaG3+g="
},
{
"source": {
Expand All @@ -18,8 +18,8 @@
"subdir": "contrib/mixin"
}
},
"version": "c72947d87fce5d2b49a5494b5bb484573bd7eb11",
"sum": "IF9N4i2Zgl4vm3ZHe3MDptcqLswNESKy9NMz9av8Im0="
"version": "38a7d79810bd273bd078bf0931480b743afee003",
"sum": "drRRtMPhvpUZ8v7Weqz7Cg2pwDA2cSb6X1pjBPoCx1w="
},
{
"source": {
Expand All @@ -38,7 +38,7 @@
"subdir": "grafana-builder"
}
},
"version": "2ed138b205717af721af57b572bc7cd63bda62fd",
"version": "87b6b50706dfa57b2470470422770f8e7574b7db",
"sum": "U34Nd1ViO2LZ3D8IzygPPRfUcy6zOgCnTMVHZ+9O/QE="
},
{
Expand All @@ -48,8 +48,8 @@
"subdir": ""
}
},
"version": "06d00e40b43e4e618afbebe8e453b5650c659015",
"sum": "oT6Vw714HjoFtnay2WFzzRk/TP2McDaYIEHI2GqNuWY="
"version": "8dc2c0d69f762d943c5bfbdcc17645e346d610ca",
"sum": "TamniMXp0Jy6E5OMOYtcrTJ1P+rFTVNuiOZSkxvckb8="
},
{
"source": {
Expand All @@ -58,7 +58,7 @@
"subdir": "lib/promgrafonnet"
}
},
"version": "06d00e40b43e4e618afbebe8e453b5650c659015",
"version": "8dc2c0d69f762d943c5bfbdcc17645e346d610ca",
"sum": "zv7hXGui6BfHzE9wPatHI/AGZa4A2WKo6pq7ZdqBsps="
},
{
Expand All @@ -68,7 +68,7 @@
"subdir": "jsonnet/kube-state-metrics"
}
},
"version": "1e9d07bfe1509b04f6f5183c4635da2a88d14cbd",
"version": "b730cb415234509e6a1425c79e826f2e7688d27b",
"sum": "U1wzIpTAtOvC1yj43Y8PfvT0JfvnAcMfNH12Wi+ab0Y="
},
{
Expand All @@ -78,7 +78,7 @@
"subdir": "jsonnet/kube-state-metrics-mixin"
}
},
"version": "1e9d07bfe1509b04f6f5183c4635da2a88d14cbd",
"version": "b730cb415234509e6a1425c79e826f2e7688d27b",
"sum": "u8gaydJoxEjzizQ8jY8xSjYgWooPmxw+wIWdDxifMAk="
},
{
Expand All @@ -88,7 +88,7 @@
"subdir": "jsonnet/mixin"
}
},
"version": "0a38647379a5e93f639bf8e634deabcc32e01fb6",
"version": "f710e9d66a09efdb8edc144af555718b7d7ed2e3",
"sum": "qZ4WgiweaE6eeKtFK60QUjLO8sf2L9Q8fgafWvDcyfY=",
"name": "prometheus-operator-mixin"
},
Expand All @@ -99,7 +99,7 @@
"subdir": "jsonnet/prometheus-operator"
}
},
"version": "0a38647379a5e93f639bf8e634deabcc32e01fb6",
"version": "f710e9d66a09efdb8edc144af555718b7d7ed2e3",
"sum": "4e3A/CccaxvLdWFPKJlC/P9RbPhSX6cH/Nj8+N1DBzg="
},
{
Expand All @@ -109,7 +109,7 @@
"subdir": "doc/alertmanager-mixin"
}
},
"version": "523c932859a8b0e4df597bd3f7b1cec6ec9ee246",
"version": "1b8afe7cb5aafe59442e35979ec57401145ea26b",
"sum": "pep+dHzfIjh2SU5pEkwilMCAT/NoL6YYflV4x8cr7vU=",
"name": "alertmanager"
},
Expand All @@ -120,8 +120,8 @@
"subdir": "docs/node-mixin"
}
},
"version": "5a38949451fb3f817e0b1f58a04e03b983f1f8a3",
"sum": "EQTMeoaso8sKLp+d/ylp5wQue4yAjZJjD0Oz7Iq41tk="
"version": "a59b2d89903229db0019f73200ec209758f2fd26",
"sum": "Yr1xB+EEdBYRbsCtl4MDvx6phDg3UoMQtfpWADHyeGk="
},
{
"source": {
Expand All @@ -130,7 +130,7 @@
"subdir": "documentation/prometheus-mixin"
}
},
"version": "60d099088692b6b5bf4b8f4e13f76bd3921da99e",
"version": "c092a74be9cc3e8e3db41efe3136128cef6c1add",
"sum": "m4VHwft4fUcxzL4+52lLZG/V5aH5ZEdjaweb88vISL0=",
"name": "prometheus"
},
Expand All @@ -141,7 +141,7 @@
"subdir": "mixin"
}
},
"version": "fa476b5f6f4d7015a53bcdb6f0a70ec2a1ac3bb2",
"version": "d2d53e575b489a8cbfc9e1723d0e3f62a68faf39",
"sum": "Og+wEHfgzXBvBLAeeQvGNoiCw3FY4LQHlJdpsG/owj8=",
"name": "thanos-mixin"
},
Expand Down
Loading

0 comments on commit cd044aa

Please sign in to comment.