@@ -19,12 +19,14 @@ import (
1919
2020 "github.com/onsi/gomega"
2121 "github.com/openstack-k8s-operators/lib-common/modules/common/tls"
22+ telemetryv1 "github.com/openstack-k8s-operators/telemetry-operator/api/v1beta1"
23+ "k8s.io/utils/ptr"
2224)
2325
2426func TestMCPConfigYAMLTLSIsIndependentFromCABundle (t * testing.T ) {
2527 t .Run ("CA bundle configures only downstream trust" , func (t * testing.T ) {
2628 g := gomega .NewWithT (t )
27- config := MCPConfigYAML ("openstackclient" , "openstack" , "combined-ca-bundle" , false )
29+ config := MCPConfigYAML ("openstackclient" , "openstack" , "combined-ca-bundle" , false , nil )
2830
2931 g .Expect (config ).To (gomega .ContainSubstring ("ca_cert: " + tls .DownstreamTLSCABundlePath ))
3032 g .Expect (config ).NotTo (gomega .ContainSubstring ("\n tls:\n " ))
@@ -33,11 +35,45 @@ func TestMCPConfigYAMLTLSIsIndependentFromCABundle(t *testing.T) {
3335
3436 t .Run ("MCP TLS does not require a downstream CA bundle" , func (t * testing.T ) {
3537 g := gomega .NewWithT (t )
36- config := MCPConfigYAML ("openstackclient" , "openstack" , "" , true )
38+ config := MCPConfigYAML ("openstackclient" , "openstack" , "" , true , nil )
3739
3840 g .Expect (config ).NotTo (gomega .ContainSubstring ("ca_cert:" ))
3941 g .Expect (config ).To (gomega .ContainSubstring ("\n tls:\n " ))
4042 g .Expect (config ).To (gomega .ContainSubstring ("ssl_certfile: /etc/pki/tls/mcp/tls.crt" ))
4143 g .Expect (config ).To (gomega .ContainSubstring ("https://openstackclient-mcp.openstack.svc:8080" ))
4244 })
4345}
46+
47+ func TestMCPConfigYAMLPrometheus (t * testing.T ) {
48+ t .Run ("no MetricStorage omits the prometheus section" , func (t * testing.T ) {
49+ g := gomega .NewWithT (t )
50+ config := MCPConfigYAML ("openstackclient" , "openstack" , "" , false , nil )
51+
52+ g .Expect (config ).NotTo (gomega .ContainSubstring ("prometheus:" ))
53+ })
54+
55+ t .Run ("MetricStorage without TLS configures host/port but no ca_cert" , func (t * testing.T ) {
56+ g := gomega .NewWithT (t )
57+ metricStorage := & telemetryv1.MetricStorage {}
58+ config := MCPConfigYAML ("openstackclient" , "openstack" , "" , false , metricStorage )
59+
60+ g .Expect (config ).To (gomega .ContainSubstring (" prometheus:\n host: metric-storage-prometheus.openstack.svc\n port: 9090" ))
61+ g .Expect (config ).NotTo (gomega .ContainSubstring ("prometheus:\n host: metric-storage-prometheus.openstack.svc\n port: 9090\n ca_cert:" ))
62+ })
63+
64+ t .Run ("MetricStorage with TLS enabled adds ca_cert under prometheus" , func (t * testing.T ) {
65+ g := gomega .NewWithT (t )
66+ metricStorage := & telemetryv1.MetricStorage {
67+ Spec : telemetryv1.MetricStorageSpec {
68+ PrometheusTLS : tls.SimpleService {
69+ GenericService : tls.GenericService {
70+ SecretName : ptr .To ("prometheus-tls-secret" ),
71+ },
72+ },
73+ },
74+ }
75+ config := MCPConfigYAML ("openstackclient" , "openstack" , "" , false , metricStorage )
76+
77+ g .Expect (config ).To (gomega .ContainSubstring (" prometheus:\n host: metric-storage-prometheus.openstack.svc\n port: 9090\n ca_cert: " + tls .DownstreamTLSCABundlePath ))
78+ })
79+ }
0 commit comments