From 7f0bae764594b0f9a3b98f7268239fbb6ef19a52 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 26 Jul 2021 13:34:28 +0300 Subject: [PATCH] Only add prometheus annotation and specific k8s resources Fixes: #15598 --- .../deployment/KubernetesCommonHelper.java | 13 +++-- .../kubernetes/KubernetesWithMetricsTest.java | 50 +++++++++++++------ 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java index d0a1fba013c86..76ececeee141f 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesCommonHelper.java @@ -77,6 +77,8 @@ public class KubernetesCommonHelper { private static final String OUTPUT_ARTIFACT_FORMAT = "%s%s.jar"; + private static final String[] PROMETHEUS_ANNOTATION_TARGETS = { "Service", + "Deployment", "DeploymentConfig" }; public static Optional createProject(ApplicationInfoBuildItem app, Optional customProjectRoot, OutputTargetBuildItem outputTarget, @@ -440,13 +442,16 @@ private static List createAnnotationDecorators(Optional p.getFileName().endsWith("kubernetes.yml")); List kubernetesList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("kubernetes.yml")); - assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Deployment.class, d -> { - assertThat(d.getMetadata()).satisfies(m -> { - assertThat(m.getName()).isEqualTo("metrics"); - }); - - assertThat(d.getSpec()).satisfies(deploymentSpec -> { - assertThat(deploymentSpec.getTemplate()).satisfies(t -> { - assertThat(t.getMetadata()).satisfies(meta -> { - assertThat(meta.getAnnotations()).contains(entry("prometheus.io/scrape", "true"), - entry("prometheus.io/path", "/q/metrics"), entry("prometheus.io/port", "9090"), - entry("prometheus.io/scheme", "http")); + + assertThat(kubernetesList).filteredOn(h -> "Deployment".equals(h.getKind())).singleElement() + .isInstanceOfSatisfying(Deployment.class, d -> { + assertThat(d.getMetadata()).satisfies(m -> assertThat(m.getName()).isEqualTo("metrics")); + + assertThat(d.getSpec()).satisfies(deploymentSpec -> { + assertThat(deploymentSpec.getTemplate()).satisfies(t -> { + assertThat(t.getMetadata()).satisfies(meta -> { + assertThat(meta.getAnnotations()).contains(entry("prometheus.io/scrape", "true"), + entry("prometheus.io/path", "/q/metrics"), entry("prometheus.io/port", "9090"), + entry("prometheus.io/scheme", "http")); + }); + }); }); }); - }); + + assertThat(kubernetesList).filteredOn(h -> "Service".equals(h.getKind())).singleElement().satisfies(h -> { + assertThat(h.getMetadata().getAnnotations()).contains(entry("prometheus.io/scrape", "true"), + entry("prometheus.io/path", "/q/metrics"), entry("prometheus.io/port", "9090"), + entry("prometheus.io/scheme", "http")); + }); + + assertThat(kubernetesList).filteredOn(h -> "ServiceAccount".equals(h.getKind())).singleElement().satisfies(h -> { + if (h.getMetadata().getAnnotations() != null) { + assertThat(h.getMetadata().getAnnotations()).doesNotContainKeys("prometheus.io/scrape", "prometheus.io/path", + "prometheus.io/port", "prometheus.io/scheme"); + } + }); + + assertThat(kubernetesList).filteredOn(h -> "RoleBinding".equals(h.getKind())).singleElement().satisfies(h -> { + if (h.getMetadata().getAnnotations() != null) { + assertThat(h.getMetadata().getAnnotations()).doesNotContainKeys("prometheus.io/scrape", "prometheus.io/path", + "prometheus.io/port", "prometheus.io/scheme"); + } }); }