Skip to content

Commit

Permalink
Merge pull request #117 from paulfantom/rewrite
Browse files Browse the repository at this point in the history
Rewrite code to use newer design pattern.
  • Loading branch information
brancz authored Oct 21, 2021
2 parents c3b14b2 + b252fde commit 199e363
Show file tree
Hide file tree
Showing 9 changed files with 632 additions and 768 deletions.
347 changes: 146 additions & 201 deletions README.md

Large diffs are not rendered by default.

81 changes: 28 additions & 53 deletions examples/basic-with-image-renderer.jsonnet
Original file line number Diff line number Diff line change
@@ -1,59 +1,34 @@
local grafana = import 'grafana/grafana.libsonnet';

local basicWithImageRenderer =
(grafana {
_config+:: {
namespace: 'monitoring-grafana',
versions+:: {
grafanaImageRenderer: '1.0.9',
},

imageRepos+:: {
grafanaImageRenderer: 'grafana/grafana-image-renderer',
},

grafana+:: {
imageRendererPort: 8081,
imageRendererContainer: {
requests: { cpu: '100m', memory: '100Mi' },
limits: { cpu: '200m', memory: '200Mi' },
},

env+: [
{ name: 'GF_RENDERING_SERVER_URL', value: 'http://localhost:' + $._config.grafana.imageRendererPort + '/render' },
{ name: 'GF_RENDERING_CALLBACK_URL', value: 'http://localhost:' + $._config.grafana.port },
],

containers+: [
{
name: 'grafana-image-renderer',
image: $._config.imageRepos.grafanaImageRenderer + ':' + $._config.versions.grafanaImageRenderer,
ports: [{ name: 'http', containerPort: $._config.grafana.imageRendererPort }],
resources: {
requests: $._config.grafana.imageRendererContainer.requests,
limits: $._config.grafana.imageRendererContainer.limits,
},
},
],
},
},
}).grafana;
local imageRenderer = {
name: 'grafana-image-renderer',
image: 'grafana/grafana-image-renderer:1.0.9',
ports: [{ name: 'http', containerPort: 8081 }],
resources: {
requests: { cpu: '100m', memory: '100Mi' },
limits: { cpu: '200m', memory: '200Mi' },
},
};

{
apiVersion: 'v1',
kind: 'List',
items: [
basicWithImageRenderer.dashboardSources,
basicWithImageRenderer.dashboardDatasources,
basicWithImageRenderer.deployment,
basicWithImageRenderer.serviceAccount,
basicWithImageRenderer.service {
spec+: { ports: [
port {
nodePort: 30910,
}
for port in super.ports
] },
_config:: {
namespace: 'monitoring-grafana',
env: [
{ name: 'GF_RENDERING_SERVER_URL', value: 'http://localhost:' + imageRenderer.ports[0].containerPort + '/render' },
{ name: 'GF_RENDERING_CALLBACK_URL', value: 'http://localhost:' + $.grafana._config.port },
],
},

grafana: grafana($._config) + {
service+: {
spec+: {
ports: [
port {
nodePort: 30910,
}
for port in super.ports
],
},
},
],
},
}
33 changes: 11 additions & 22 deletions examples/basic-with-mixin.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,21 @@ local kubernetesMixin = import 'github.com/kubernetes-monitoring/kubernetes-mixi
local grafana = import 'grafana/grafana.libsonnet';

{
local basicWithMixin =
(grafana {
_config+:: {
namespace: 'monitoring-grafana',
grafana+:: {
dashboards: kubernetesMixin.grafanaDashboards,
},
},
}).grafana,
_config:: {
namespace: 'monitoring-grafana',
dashboards: kubernetesMixin.grafanaDashboards,
},

apiVersion: 'v1',
kind: 'List',
items:
basicWithMixin.dashboardDefinitions +
[
basicWithMixin.dashboardSources,
basicWithMixin.dashboardDatasources,
basicWithMixin.deployment,
basicWithMixin.serviceAccount,
basicWithMixin.service {
spec+: { ports: [
grafana: grafana($._config) + {
service+: {
spec+: {
ports: [
port {
nodePort: 30910,
}
for port in super.ports
] },
],
},
],
},
},
}
29 changes: 10 additions & 19 deletions examples/basic.jsonnet
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
local grafana = import 'grafana/grafana.libsonnet';

{
local basic =
(grafana {
_config+:: {
namespace: 'monitoring-grafana',
},
}).grafana,
_config:: {
namespace: 'monitoring-grafana',
},

apiVersion: 'v1',
kind: 'List',
items:
basic.dashboardDefinitions +
[
basic.dashboardSources,
basic.dashboardDatasources,
basic.deployment,
basic.serviceAccount,
basic.service {
spec+: { ports: [
grafana: grafana($._config) + {
service+: {
spec+: {
ports: [
port {
nodePort: 30910,
}
for port in super.ports
] },
],
},
],
},
},
}
60 changes: 30 additions & 30 deletions examples/custom-ini.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@ local grafana = import 'grafana/grafana.libsonnet';

{
local customIni =
(grafana {
_config+:: {
namespace: 'monitoring-grafana',
grafana+:: {
config: {
sections: {
metrics: { enabled: true },
'auth.ldap': {
enabled: true,
config_file: '/etc/grafana/ldap.toml',
allow_sign_up: true,
},
},
},
ldap: |||
[[servers]]
host = "127.0.0.1"
port = 389
use_ssl = false
start_tls = false
ssl_skip_verify = false
grafana({
_config+:: {
namespace: 'monitoring-grafana',
grafana+:: {
config: {
sections: {
metrics: { enabled: true },
'auth.ldap': {
enabled: true,
config_file: '/etc/grafana/ldap.toml',
allow_sign_up: true,
},
},
},
ldap: |||
[[servers]]
host = "127.0.0.1"
port = 389
use_ssl = false
start_tls = false
ssl_skip_verify = false
bind_dn = "cn=admin,dc=grafana,dc=org"
bind_password = 'grafana'
bind_dn = "cn=admin,dc=grafana,dc=org"
bind_password = 'grafana'
search_filter = "(cn=%s)"
search_filter = "(cn=%s)"
search_base_dns = ["dc=grafana,dc=org"]
|||,
},
},
}).grafana,
search_base_dns = ["dc=grafana,dc=org"]
|||,
},
},
}),

apiVersion: 'v1',
kind: 'List',
items:
customIni.dashboardDefinitions +
customIni.dashboardDefinitions.items +
[
customIni.config,
customIni.dashboardSources,
Expand Down
100 changes: 44 additions & 56 deletions examples/dashboard-definition.jsonnet
Original file line number Diff line number Diff line change
@@ -1,66 +1,54 @@
local grafana = import 'github.com/grafana/grafonnet-lib/grafonnet/grafana.libsonnet';
local dashboard = grafana.dashboard;
local row = grafana.row;
local prometheus = grafana.prometheus;
local template = grafana.template;
local graphPanel = grafana.graphPanel;
local grafonnet = import 'github.com/grafana/grafonnet-lib/grafonnet/grafana.libsonnet';
local dashboard = grafonnet.dashboard;
local row = grafonnet.row;
local prometheus = grafonnet.prometheus;
local template = grafonnet.template;
local graphPanel = grafonnet.graphPanel;

local grafana = import 'grafana/grafana.libsonnet';

local grafanaWithDashboards =
(grafana
{
_config+:: {
namespace: 'monitoring-grafana',
grafana+:: {
dashboards+:: {
'my-dashboard.json':
dashboard.new('My Dashboard')
.addTemplate(
{
current: {
text: 'Prometheus',
value: 'Prometheus',
},
hide: 0,
label: null,
name: 'datasource',
options: [],
query: 'prometheus',
refresh: 1,
regex: '',
type: 'datasource',
},
)
.addRow(
row.new()
.addPanel(
graphPanel.new('My Panel', span=6, datasource='$datasource')
.addTarget(prometheus.target('vector(1)')),
)
),
},
},
},
}).grafana;

{
apiVersion: 'v1',
kind: 'List',
items:
grafanaWithDashboards.dashboardDefinitions +
[
grafanaWithDashboards.dashboardSources,
grafanaWithDashboards.dashboardDatasources,
grafanaWithDashboards.deployment,
grafanaWithDashboards.serviceAccount,
grafanaWithDashboards.service {
spec+: { ports: [
_config:: {
namespace: 'monitoring-grafana',
dashboards+: {
'my-dashboard.json':
dashboard.new('My Dashboard')
.addTemplate(
{
current: {
text: 'Prometheus',
value: 'Prometheus',
},
hide: 0,
label: null,
name: 'datasource',
options: [],
query: 'prometheus',
refresh: 1,
regex: '',
type: 'datasource',
},
)
.addRow(
row.new()
.addPanel(
graphPanel.new('My Panel', span=6, datasource='$datasource')
.addTarget(prometheus.target('vector(1)')),
)
),
},
},

grafana: grafana($._config) + {
service+: {
spec+: {
ports: [
port {
nodePort: 30910,
}
for port in super.ports
] },
],
},
],
},
},
}
Loading

0 comments on commit 199e363

Please sign in to comment.