mirror of
https://github.com/carlosedp/cluster-monitoring.git
synced 2024-11-20 19:07:17 +01:00
Load additional modules dynamically from vars module definition
This commit is contained in:
parent
ad1677dad5
commit
87ed1bf665
66
main.jsonnet
66
main.jsonnet
@ -1,14 +1,13 @@
|
||||
local k = import 'ksonnet/ksonnet.beta.3/k.libsonnet';
|
||||
local vars = import 'vars.jsonnet';
|
||||
local enabledModules = [module.name for module in vars.modules if module.enabled];
|
||||
|
||||
local join_objects(objs) =
|
||||
local aux(arr, i, running) =
|
||||
if i >= std.length(arr) then
|
||||
running
|
||||
else
|
||||
aux(arr, i + 1, running + arr[i]) tailstrict;
|
||||
aux(objs, 0, {});
|
||||
local aux(arr, i, running) =
|
||||
if i >= std.length(arr) then
|
||||
running
|
||||
else
|
||||
aux(arr, i + 1, running + arr[i]) tailstrict;
|
||||
aux(objs, 0, {});
|
||||
|
||||
local kp = (import 'kube-prometheus/kube-prometheus.libsonnet')
|
||||
+ (import 'kube-prometheus/kube-prometheus-anti-affinity.libsonnet')
|
||||
@ -18,49 +17,26 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet')
|
||||
+ (import 'kube-prometheus/kube-prometheus-insecure-kubelet.libsonnet')
|
||||
+ (import 'base_operator_stack.jsonnet')
|
||||
+ (import 'smtp_server.jsonnet')
|
||||
// Additional Modules
|
||||
// Additional modules are loaded dynamically from vars.jsonnet
|
||||
+ join_objects([module.file for module in vars.modules if module.enabled])
|
||||
// Load image versions last to override default from modules
|
||||
+ (import 'image_sources_versions.jsonnet');
|
||||
|
||||
// Generate core modules
|
||||
{ ['00namespace-' + name]: kp.kubePrometheus[name] for name in std.objectFields(kp.kubePrometheus) }
|
||||
{ ['0prometheus-operator-' + name]: kp.prometheusOperator[name] for name in std.objectFields(kp.prometheusOperator) } +
|
||||
{ ['prometheus-adapter-' + name]: kp.prometheusAdapter[name] for name in std.objectFields(kp.prometheusAdapter) } +
|
||||
{ ['prometheus-' + name]: kp.prometheus[name] for name in std.objectFields(kp.prometheus) } +
|
||||
{ ['alertmanager-' + name]: kp.alertmanager[name] for name in std.objectFields(kp.alertmanager) } +
|
||||
{ ['kube-state-metrics-' + name]: kp.kubeStateMetrics[name] for name in std.objectFields(kp.kubeStateMetrics) } +
|
||||
{ ['node-exporter-' + name]: kp.nodeExporter[name] for name in std.objectFields(kp.nodeExporter) } +
|
||||
{ ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) } +
|
||||
{ ['ingress-' + name]: kp.ingress[name] for name in std.objectFields(kp.ingress) } +
|
||||
{ ['0prometheus-operator-' + name]: kp.prometheusOperator[name] for name in std.objectFields(kp.prometheusOperator) }
|
||||
{ ['prometheus-adapter-' + name]: kp.prometheusAdapter[name] for name in std.objectFields(kp.prometheusAdapter) }
|
||||
{ ['prometheus-' + name]: kp.prometheus[name] for name in std.objectFields(kp.prometheus) }
|
||||
{ ['alertmanager-' + name]: kp.alertmanager[name] for name in std.objectFields(kp.alertmanager) }
|
||||
{ ['kube-state-metrics-' + name]: kp.kubeStateMetrics[name] for name in std.objectFields(kp.kubeStateMetrics) }
|
||||
{ ['node-exporter-' + name]: kp.nodeExporter[name] for name in std.objectFields(kp.nodeExporter) }
|
||||
{ ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) }
|
||||
{ ['ingress-' + name]: kp.ingress[name] for name in std.objectFields(kp.ingress) }
|
||||
{ ['smtp-server-' + name]: kp.smtpServer[name] for name in std.objectFields(kp.smtpServer) }
|
||||
// Additional Modules
|
||||
|
||||
{
|
||||
[std.asciiLower(moduleName) + '-' + objName]: {kp.moduleName[objName]}
|
||||
for objName in [std.objectFields(kp[moduleName]] for moduleName in enabledModules
|
||||
{ // Dynamically generate additional modules from vars.jsonnet
|
||||
[std.asciiLower(module.name) + '-' + name]: kp[module.name][name]
|
||||
for module in vars.modules
|
||||
if module.enabled
|
||||
for name in std.objectFields(kp[module.name])
|
||||
}
|
||||
|
||||
|
||||
// {
|
||||
// local items = ["a", "b", "c"],
|
||||
// joined: {
|
||||
// [x + i]: {
|
||||
// data: "x = %s and i = %s" % [x, i],
|
||||
// } for i in ["1", "2"] for x in items
|
||||
// }
|
||||
// }
|
||||
|
||||
// { ['arm-exporter-' + name]: kp.armExporter[name] for name in std.objectFields(kp.armExporter) }
|
||||
|
||||
// {[std.asciiLower(moduleName) + '-' + objName]: kp.moduleName[objName] for objName in [std.objectFields(kp[moduleName]) for moduleName in enabledModules]}
|
||||
|
||||
// (if vars.installModules['arm-exporter'] then
|
||||
// { ['arm-exporter-' + name]: kp.armExporter[name] for name in std.objectFields(kp.armExporter) } else {}) +
|
||||
// (if vars.installModules.metallb then
|
||||
// { ['metallb-' + name]: kp.metallb[name] for name in std.objectFields(kp.metallb) } else {}) +
|
||||
// (if vars.installModules.traefik then
|
||||
// { ['traefik-' + name]: kp.traefik[name] for name in std.objectFields(kp.traefik) } else {}) +
|
||||
// (if vars.installModules['ups-exporter'] then
|
||||
// { ['ups-exporter-' + name]: kp.upsExporter[name] for name in std.objectFields(kp.upsExporter) } else {}) +
|
||||
// (if vars.installModules['elastic-exporter'] then
|
||||
// { ['elasticexporter-' + name]: kp.elasticExporter[name] for name in std.objectFields(kp.elasticExporter) } else {})
|
||||
|
@ -5,7 +5,7 @@ metadata:
|
||||
namespace: monitoring
|
||||
spec:
|
||||
rules:
|
||||
- host: alertmanager.192.168.99.102.nip.io
|
||||
- host: alertmanager.192.168.99.100.nip.io
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
|
@ -5,7 +5,7 @@ metadata:
|
||||
namespace: monitoring
|
||||
spec:
|
||||
rules:
|
||||
- host: grafana.192.168.99.102.nip.io
|
||||
- host: grafana.192.168.99.100.nip.io
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
|
@ -5,7 +5,7 @@ metadata:
|
||||
namespace: monitoring
|
||||
spec:
|
||||
rules:
|
||||
- host: prometheus.192.168.99.102.nip.io
|
||||
- host: prometheus.192.168.99.100.nip.io
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
|
@ -26,7 +26,7 @@ spec:
|
||||
namespace: monitoring
|
||||
port: web
|
||||
baseImage: carlosedp/prometheus
|
||||
externalUrl: http://prometheus.192.168.99.102.nip.io
|
||||
externalUrl: http://prometheus.192.168.99.100.nip.io
|
||||
nodeSelector:
|
||||
beta.kubernetes.io/os: linux
|
||||
replicas: 1
|
||||
|
10
vars.jsonnet
10
vars.jsonnet
@ -3,27 +3,27 @@
|
||||
modules: [
|
||||
{
|
||||
name: 'armExporter',
|
||||
enabled: true,
|
||||
enabled: false,
|
||||
file: import 'arm_exporter.jsonnet',
|
||||
},
|
||||
{
|
||||
name: 'upsExporter',
|
||||
enabled: true,
|
||||
enabled: false,
|
||||
file: import 'ups_exporter.jsonnet',
|
||||
},
|
||||
{
|
||||
name: 'metallbExporter',
|
||||
enabled: true,
|
||||
enabled: false,
|
||||
file: import 'metallb.jsonnet',
|
||||
},
|
||||
{
|
||||
name: 'traefikExporter',
|
||||
enabled: true,
|
||||
enabled: false,
|
||||
file: import 'traefik.jsonnet',
|
||||
},
|
||||
{
|
||||
name: 'elasticExporter',
|
||||
enabled: true,
|
||||
enabled: false,
|
||||
file: import 'elasticsearch_exporter.jsonnet',
|
||||
},
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user