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"); + } }); }