diff --git a/main.jsonnet b/main.jsonnet index a346dc4..7126b12 100644 --- a/main.jsonnet +++ b/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 {}) diff --git a/manifests/ingress-alertmanager-main.yaml b/manifests/ingress-alertmanager-main.yaml index 343d8e4..3b0723a 100644 --- a/manifests/ingress-alertmanager-main.yaml +++ b/manifests/ingress-alertmanager-main.yaml @@ -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: diff --git a/manifests/ingress-grafana.yaml b/manifests/ingress-grafana.yaml index defc89a..7b058b0 100644 --- a/manifests/ingress-grafana.yaml +++ b/manifests/ingress-grafana.yaml @@ -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: diff --git a/manifests/ingress-prometheus-k8s.yaml b/manifests/ingress-prometheus-k8s.yaml index b8542b3..fc6b211 100644 --- a/manifests/ingress-prometheus-k8s.yaml +++ b/manifests/ingress-prometheus-k8s.yaml @@ -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: diff --git a/manifests/prometheus-prometheus.yaml b/manifests/prometheus-prometheus.yaml index 542828a..fe21f9c 100644 --- a/manifests/prometheus-prometheus.yaml +++ b/manifests/prometheus-prometheus.yaml @@ -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 diff --git a/vars.jsonnet b/vars.jsonnet index 1f01c51..2e490fd 100644 --- a/vars.jsonnet +++ b/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', }, ],