From 0a490f918150ec58a74c0fb597f6522fa2023b57 Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Sat, 9 Sep 2023 08:41:41 +1200 Subject: [PATCH] feat: Updated check ServiceMontior check to include APIVersions check for helm charts (#2683) * feat: Added check for APIVersions Signed-off-by: Parth Patel * test: unit test for the APIVersions check Signed-off-by: Parth Patel --------- Signed-off-by: Parth Patel --- .../templates/servicemonitor.yaml | 2 +- .../tests/__snapshot__/crds_test.yaml.snap | 2 +- .../tests/service_monitor_test.yaml | 34 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 deploy/charts/external-secrets/tests/service_monitor_test.yaml diff --git a/deploy/charts/external-secrets/templates/servicemonitor.yaml b/deploy/charts/external-secrets/templates/servicemonitor.yaml index 241ae4715..4153dc5dd 100644 --- a/deploy/charts/external-secrets/templates/servicemonitor.yaml +++ b/deploy/charts/external-secrets/templates/servicemonitor.yaml @@ -1,4 +1,4 @@ -{{- if .Values.serviceMonitor.enabled }} +{{- if and ( .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" ) .Values.serviceMonitor.enabled -}} apiVersion: v1 kind: Service metadata: diff --git a/deploy/charts/external-secrets/tests/__snapshot__/crds_test.yaml.snap b/deploy/charts/external-secrets/tests/__snapshot__/crds_test.yaml.snap index 7cb3a5500..ae40a7678 100644 --- a/deploy/charts/external-secrets/tests/__snapshot__/crds_test.yaml.snap +++ b/deploy/charts/external-secrets/tests/__snapshot__/crds_test.yaml.snap @@ -4,7 +4,7 @@ should match snapshot of default values: kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.12.1 + controller-gen.kubebuilder.io/version: v0.13.0 name: secretstores.external-secrets.io spec: conversion: diff --git a/deploy/charts/external-secrets/tests/service_monitor_test.yaml b/deploy/charts/external-secrets/tests/service_monitor_test.yaml new file mode 100644 index 000000000..327f9b083 --- /dev/null +++ b/deploy/charts/external-secrets/tests/service_monitor_test.yaml @@ -0,0 +1,34 @@ +suite: test service monitor +templates: + - servicemonitor.yaml +tests: + - it: should render service monitor when APIVersions is present and serviceMonitor is enabled + set: + serviceMonitor.enabled: true + capabilities: + apiVersions: + - "monitoring.coreos.com/v1" + asserts: + - hasDocuments: + count: 6 + - it: should not render service monitor when APIVersions is not present but serviceMonitor is enabled + set: + serviceMonitor.enabled: true + asserts: + - hasDocuments: + count: 0 + - it: should not render service monitor when APIVersions is present and serviceMonitor is disabled + set: + serviceMonitor.enabled: false + capabilities: + apiVersions: + - "monitoring.coreos.com/v1" + asserts: + - hasDocuments: + count: 0 + - it: should not render service monitor when APIVersions is not present and serviceMonitor is disabled + set: + serviceMonitor.enabled: false + asserts: + - hasDocuments: + count: 0 \ No newline at end of file