From ed5a2f94fcfd1091ec3abb6ca7ce0ceb2c73dcb9 Mon Sep 17 00:00:00 2001
From: Damien Grisonnet <dgrisonn@redhat.com>
Date: Fri, 9 Apr 2021 12:44:51 +0200
Subject: [PATCH] jsonnet: fix test failures with platformPatch

Signed-off-by: Damien Grisonnet <dgrisonn@redhat.com>
---
 jsonnet/kube-prometheus/main.libsonnet        |  6 ++--
 .../platforms/platforms.libsonnet             | 31 +++++++++++++++++--
 2 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/jsonnet/kube-prometheus/main.libsonnet b/jsonnet/kube-prometheus/main.libsonnet
index ddb241d8..1c13b7b9 100644
--- a/jsonnet/kube-prometheus/main.libsonnet
+++ b/jsonnet/kube-prometheus/main.libsonnet
@@ -9,7 +9,7 @@ local prometheusAdapter = import './components/prometheus-adapter.libsonnet';
 local prometheusOperator = import './components/prometheus-operator.libsonnet';
 local prometheus = import './components/prometheus.libsonnet';
 
-local platformPatch = (import './platforms/platforms.libsonnet').platformPatch;
+local platformPatch = import './platforms/platforms.libsonnet';
 
 {
   // using `values` as this is similar to helm
@@ -127,5 +127,5 @@ local platformPatch = (import './platforms/platforms.libsonnet').platformPatch;
         name: $.values.kubePrometheus.namespace,
       },
     },
-  } + platformPatch($.values.kubePrometheus.platform),
-}
+  },
+} + platformPatch
diff --git a/jsonnet/kube-prometheus/platforms/platforms.libsonnet b/jsonnet/kube-prometheus/platforms/platforms.libsonnet
index 9c6f07c7..979190f2 100644
--- a/jsonnet/kube-prometheus/platforms/platforms.libsonnet
+++ b/jsonnet/kube-prometheus/platforms/platforms.libsonnet
@@ -9,8 +9,33 @@ local platforms = {
   kubespray: import './kubespray.libsonnet',
 };
 
+// platformPatch returns the platform specific patch associated to the given
+// platform.
+local platformPatch(p) = if p != null && std.objectHas(platforms, p) then platforms[p] else {};
+
 {
-  // platformPatch returns the platform specific patch associated to the given
-  // platform.
-  platformPatch(p): if p != null && std.objectHas(platforms, p) then platforms[p] else {},
+  // initialize the object to prevent "Indexed object has no field" lint errors
+  local p = {
+    alertmanager: {},
+    blackboxExporter: {},
+    grafana: {},
+    kubeStateMetrics: {},
+    nodeExporter: {},
+    prometheus: {},
+    prometheusAdapter: {},
+    prometheusOperator: {},
+    kubernetesControlPlane: {},
+    kubePrometheus: {},
+  } + platformPatch($.values.kubePrometheus.platform),
+
+  alertmanager+: p.alertmanager,
+  blackboxExporter+: p.blackboxExporter,
+  grafana+: p.grafana,
+  kubeStateMetrics+: p.kubeStateMetrics,
+  nodeExporter+: p.nodeExporter,
+  prometheus+: p.prometheus,
+  prometheusAdapter+: p.prometheusAdapter,
+  prometheusOperator+: p.prometheusOperator,
+  kubernetesControlPlane+: p.kubernetesControlPlane,
+  kubePrometheus+: p.kubePrometheus,
 }
-- 
GitLab