From d786b6c8d0bbedc75dae0981815f8272063533e3 Mon Sep 17 00:00:00 2001 From: Marco Ebert Date: Mon, 26 Aug 2024 21:46:28 +0200 Subject: [PATCH] Chart: Add tests for `PrometheusRule` & `ServiceMonitor`. --- charts/ingress-nginx/README.md | 2 +- ...es.yaml => controller-prometheusrule.yaml} | 0 .../tests/controller-prometheusrule_test.yaml | 17 +++++++++++ .../tests/controller-servicemonitor_test.yaml | 29 +++++++++++++++++++ charts/ingress-nginx/values.yaml | 1 + 5 files changed, 48 insertions(+), 1 deletion(-) rename charts/ingress-nginx/templates/{controller-prometheusrules.yaml => controller-prometheusrule.yaml} (100%) create mode 100644 charts/ingress-nginx/tests/controller-prometheusrule_test.yaml create mode 100644 charts/ingress-nginx/tests/controller-servicemonitor_test.yaml diff --git a/charts/ingress-nginx/README.md b/charts/ingress-nginx/README.md index 48bc20771c..4d1abf1e62 100644 --- a/charts/ingress-nginx/README.md +++ b/charts/ingress-nginx/README.md @@ -370,7 +370,7 @@ As of version `1.26.0` of this chart, by simply not providing any clusterIP valu | controller.metrics.service.servicePort | int | `10254` | | | controller.metrics.service.type | string | `"ClusterIP"` | | | controller.metrics.serviceMonitor.additionalLabels | object | `{}` | | -| controller.metrics.serviceMonitor.annotations | object | `{}` | | +| controller.metrics.serviceMonitor.annotations | object | `{}` | Annotations to be added to the ServiceMonitor. | | controller.metrics.serviceMonitor.enabled | bool | `false` | | | controller.metrics.serviceMonitor.metricRelabelings | list | `[]` | | | controller.metrics.serviceMonitor.namespace | string | `""` | | diff --git a/charts/ingress-nginx/templates/controller-prometheusrules.yaml b/charts/ingress-nginx/templates/controller-prometheusrule.yaml similarity index 100% rename from charts/ingress-nginx/templates/controller-prometheusrules.yaml rename to charts/ingress-nginx/templates/controller-prometheusrule.yaml diff --git a/charts/ingress-nginx/tests/controller-prometheusrule_test.yaml b/charts/ingress-nginx/tests/controller-prometheusrule_test.yaml new file mode 100644 index 0000000000..d60a98315f --- /dev/null +++ b/charts/ingress-nginx/tests/controller-prometheusrule_test.yaml @@ -0,0 +1,17 @@ +suite: Controller > PrometheusRule +templates: + - controller-prometheusrule.yaml + +tests: + - it: should create a PrometheusRule if `controller.metrics.prometheusRule.enabled` is true + set: + controller.metrics.enabled: true + controller.metrics.prometheusRule.enabled: true + asserts: + - hasDocuments: + count: 1 + - isKind: + of: PrometheusRule + - equal: + path: metadata.name + value: RELEASE-NAME-ingress-nginx-controller diff --git a/charts/ingress-nginx/tests/controller-servicemonitor_test.yaml b/charts/ingress-nginx/tests/controller-servicemonitor_test.yaml new file mode 100644 index 0000000000..310097c1a2 --- /dev/null +++ b/charts/ingress-nginx/tests/controller-servicemonitor_test.yaml @@ -0,0 +1,29 @@ +suite: Controller > ServiceMonitor +templates: + - controller-servicemonitor.yaml + +tests: + - it: should create a ServiceMonitor if `controller.metrics.serviceMonitor.enabled` is true + set: + controller.metrics.enabled: true + controller.metrics.serviceMonitor.enabled: true + asserts: + - hasDocuments: + count: 1 + - isKind: + of: ServiceMonitor + - equal: + path: metadata.name + value: RELEASE-NAME-ingress-nginx-controller + + - it: should create a ServiceMonitor with annotations if `controller.metrics.serviceMonitor.annotations` is set + set: + controller.metrics.enabled: true + controller.metrics.serviceMonitor.enabled: true + controller.metrics.serviceMonitor.annotations: + my-little-annotation: test-value + asserts: + - equal: + path: metadata.annotations + value: + my-little-annotation: test-value diff --git a/charts/ingress-nginx/values.yaml b/charts/ingress-nginx/values.yaml index d822eca103..ee497213fc 100644 --- a/charts/ingress-nginx/values.yaml +++ b/charts/ingress-nginx/values.yaml @@ -847,6 +847,7 @@ controller: serviceMonitor: enabled: false additionalLabels: {} + # -- Annotations to be added to the ServiceMonitor. annotations: {} ## The label to use to retrieve the job name from. ## jobLabel: "app.kubernetes.io/name"