From cbf2224ad61eceadcc1b4e40d83bf2273337ceb0 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Fri, 15 Nov 2024 15:42:19 -0500 Subject: [PATCH 1/4] Fix the prometheus tests --- .../tests/prometheus_test.yaml | 68 +++++++++++++++++++ .../tests/update_strategy_test.yaml | 34 ++++++++++ 2 files changed, 102 insertions(+) create mode 100644 ci/rstudio-workbench/tests/prometheus_test.yaml create mode 100644 ci/rstudio-workbench/tests/update_strategy_test.yaml diff --git a/ci/rstudio-workbench/tests/prometheus_test.yaml b/ci/rstudio-workbench/tests/prometheus_test.yaml new file mode 100644 index 00000000..aebb5710 --- /dev/null +++ b/ci/rstudio-workbench/tests/prometheus_test.yaml @@ -0,0 +1,68 @@ +suite: Workbench prometheus configuration +templates: + - configmap-general.yaml + - configmap-graphite-exporter.yaml + - configmap-prestart.yaml + - configmap-secret.yaml + - configmap-session.yaml + - deployment.yaml + - svc.yaml +tests: + - it: should ensure the specified metrics port is used in the service + template: svc.yaml + set: + prometheus: + enabled: true + port: 8989 + asserts: + - equal: + path: "spec.ports[1].name" + value: "metrics" + - equal: + path: "spec.ports[1].port" + value: 8989 + - it: should ensure the legacy metrics port is used in the service + template: svc.yaml + set: + prometheus: + enabled: true + legacy: true + port: 8989 + asserts: + - equal: + path: "spec.ports[1].name" + value: "metrics" + - equal: + path: "spec.ports[1].port" + value: 9108 + - it: should ensure the prometheus annotations are defined in the service, and that the graphite exporter checksum is non-existent + template: deployment.yaml + set: + prometheus: + enabled: true + port: 8989 + asserts: + - isSubset: + path: spec.template.metadata.annotations + content: + prometheus.io/scrape: "true" + prometheus.io/path: "/metrics" + prometheus.io/port: "8989" + - notExists: + path: "spec.template.metadata.annotations.checksum/config-graphite" + - it: should ensure the legacy prometheus annotations are defined in the service, and that the graphite exporter checksum exists + template: deployment.yaml + set: + prometheus: + enabled: true + legacy: true + port: 8989 + asserts: + - isSubset: + path: spec.template.metadata.annotations + content: + prometheus.io/scrape: "true" + prometheus.io/path: "/metrics" + prometheus.io/port: "9108" + - exists: + path: "spec.template.metadata.annotations.checksum/config-graphite" diff --git a/ci/rstudio-workbench/tests/update_strategy_test.yaml b/ci/rstudio-workbench/tests/update_strategy_test.yaml new file mode 100644 index 00000000..d864113b --- /dev/null +++ b/ci/rstudio-workbench/tests/update_strategy_test.yaml @@ -0,0 +1,34 @@ +suite: Workbench Deployment +templates: + - configmap-general.yaml + - configmap-prestart.yaml + - configmap-secret.yaml + - configmap-session.yaml + - deployment.yaml +tests: + - it: should not specify the RollingUpdate configuration if the strategy type is not RollingUpdate + template: deployment.yaml + set: + strategy: + type: "Recreate" + asserts: + - notExists: + path: "spec.strategy.rollingUpdate" + - it: should specify the RollingUpdate configuration if the strategy type is RollingUpdate + template: deployment.yaml + set: + strategy: + type: "RollingUpdate" + rollingUpdate: + maxUnavailable: 1 + maxSurge: "50%" + asserts: + - equal: + path: "spec.strategy.type" + value: "RollingUpdate" + - equal: + path: "spec.strategy.rollingUpdate.maxUnavailable" + value: 1 + - equal: + path: "spec.strategy.rollingUpdate.maxSurge" + value: "50%" From 98b236a7f7bc0b061976e40243e0ff05062fb279 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Mon, 18 Nov 2024 11:27:13 -0500 Subject: [PATCH 2/4] Test for the prometheus exporter as well --- .../tests/prometheus_test.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ci/rstudio-workbench/tests/prometheus_test.yaml b/ci/rstudio-workbench/tests/prometheus_test.yaml index aebb5710..74199d4e 100644 --- a/ci/rstudio-workbench/tests/prometheus_test.yaml +++ b/ci/rstudio-workbench/tests/prometheus_test.yaml @@ -66,3 +66,22 @@ tests: prometheus.io/port: "9108" - exists: path: "spec.template.metadata.annotations.checksum/config-graphite" + - it: should ensure the legacy metrics port is used and that the graphite exporter container exists + template: deployment.yaml + set: + prometheus: + enabled: true + legacy: true + port: 8989 + prometheusExporter: + enabled: true + asserts: + - equal: + path: "spec.template.spec.containers[1].name" + value: "exporter" + - equal: + path: "spec.template.spec.containers[1].ports[0].name" + value: "metrics" + - equal: + path: "spec.template.spec.containers[1].ports[0].containerPort" + value: 9108 From fa543d664171322bdc69099b7fd8440408780b36 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Mon, 18 Nov 2024 12:17:21 -0500 Subject: [PATCH 3/4] Add unit tests for the ingress.yaml template --- ci/rstudio-workbench/tests/ingress_test.yaml | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ci/rstudio-workbench/tests/ingress_test.yaml diff --git a/ci/rstudio-workbench/tests/ingress_test.yaml b/ci/rstudio-workbench/tests/ingress_test.yaml new file mode 100644 index 00000000..ef79b777 --- /dev/null +++ b/ci/rstudio-workbench/tests/ingress_test.yaml @@ -0,0 +1,38 @@ +suite: Workbench Ingress +templates: + - ingress.yaml +tests: + - it: should include the tls path if tls has values specified and ingress is enabled + template: ingress.yaml + set: + ingress: + enabled: true + tls: + - hosts: + - "example.com" + secretName: "example-tls" + asserts: + - exists: + path: "spec.tls" + - equal: + path: "spec.tls[0].hosts[0]" + value: "example.com" + - it: should not include the tls path if tls has no values specified and ingress is enabled + template: ingress.yaml + set: + ingress: + enabled: true + tls: [] + asserts: + - notExists: + path: "spec.tls" + - it: should include the ingressClassName if defined and ingress is enabled + template: ingress.yaml + set: + ingress: + enabled: true + ingressClassName: "alb" + asserts: + - equal: + path: "spec.ingressClassName" + value: "alb" From fa96405c442d0c8aedb8202a4903532a9bac4555 Mon Sep 17 00:00:00 2001 From: "Joshua C. Forest" Date: Tue, 19 Nov 2024 09:26:37 -0500 Subject: [PATCH 4/4] A couple of more tests for the ingress template. Better explanation for a couple of promettheus tests --- ci/rstudio-workbench/tests/ingress_test.yaml | 20 +++++++++++++++++++ .../tests/prometheus_test.yaml | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ci/rstudio-workbench/tests/ingress_test.yaml b/ci/rstudio-workbench/tests/ingress_test.yaml index ef79b777..ad7f878d 100644 --- a/ci/rstudio-workbench/tests/ingress_test.yaml +++ b/ci/rstudio-workbench/tests/ingress_test.yaml @@ -26,6 +26,18 @@ tests: asserts: - notExists: path: "spec.tls" + - it: should include the tls path if tls has values specified and ingress is enabled + template: ingress.yaml + set: + ingress: + enabled: true + tls: + - secretName: chart-example-tls + hosts: + - chart-example.local + asserts: + - exists: + path: "spec.tls" - it: should include the ingressClassName if defined and ingress is enabled template: ingress.yaml set: @@ -36,3 +48,11 @@ tests: - equal: path: "spec.ingressClassName" value: "alb" + - it: should not include the ingressClassName if it is not defined and ingress is enabled + template: ingress.yaml + set: + ingress: + enabled: true + asserts: + - notExists: + path: "spec.ingressClassName" diff --git a/ci/rstudio-workbench/tests/prometheus_test.yaml b/ci/rstudio-workbench/tests/prometheus_test.yaml index 74199d4e..4bae9f00 100644 --- a/ci/rstudio-workbench/tests/prometheus_test.yaml +++ b/ci/rstudio-workbench/tests/prometheus_test.yaml @@ -8,7 +8,7 @@ templates: - deployment.yaml - svc.yaml tests: - - it: should ensure the specified metrics port is used in the service + - it: should ensure the specified metrics port is used in the service if prometheus is enabled and legacy is not true template: svc.yaml set: prometheus: @@ -21,7 +21,7 @@ tests: - equal: path: "spec.ports[1].port" value: 8989 - - it: should ensure the legacy metrics port is used in the service + - it: should ensure the legacy metrics port is used in the service if prometheus is enabled and legacy is true template: svc.yaml set: prometheus: