Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion internal/controller/client/openstackclient_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,18 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}, metricStorage)
if err == nil {
configVars["PrometheusTls"] = env.SetValue(fmt.Sprint(metricStorage.Spec.PrometheusTLS.Enabled()))
} else if k8s_errors.IsNotFound(err) {
// MetricStorage is optional; clear the object so MCP config does not
// point at a Prometheus service that is not present.
metricStorage = nil
} else {
instance.Status.Conditions.Set(condition.FalseCondition(
clientv1.OpenStackClientReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
clientv1.OpenStackClientReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
}

// all cert input checks out so report InputReady
Expand Down Expand Up @@ -370,7 +382,13 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
configVars["mcp-tls"] = env.SetValue(certHash)
}

mcpConfigYAML := openstackclient.MCPConfigYAML(instance.Name, instance.Namespace, instance.Spec.CaBundleSecretName, mcpTLSSvc != nil)
mcpConfigYAML := openstackclient.MCPConfigYAML(
instance.Name,
instance.Namespace,
instance.Spec.CaBundleSecretName,
mcpTLSSvc != nil,
metricStorage,
)

mcpCloudsYAML := openstackclient.MCPCloudsYAML(
internalAuthURL,
Expand Down
28 changes: 25 additions & 3 deletions internal/openstackclient/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,33 @@ func ClientPodSpec(
// name and namespace identify the owning OpenStackClient and are used to scope
// mcp_transport_security to the MCP Service's own hostname (<name>-mcp.<namespace>.svc:8080),
// matching the URL OpenStackAssistant uses to reach it, instead of allowing any host/origin.
func MCPConfigYAML(name, namespace, caBundleSecretName string, mcpTLSEnabled bool) string {
// When MetricStorage is present, its Prometheus endpoint is configured explicitly
// for RHOSO versions where it is not registered in the Keystone catalog.
func MCPConfigYAML(
name, namespace, caBundleSecretName string,
mcpTLSEnabled bool,
metricStorage *telemetryv1.MetricStorage,
) string {
caCert := ""
if caBundleSecretName != "" {
caCert = fmt.Sprintf("\n ca_cert: %s", tls.DownstreamTLSCABundlePath)
}
prometheusConfig := ""
if metricStorage != nil {
prometheusCACert := ""
if metricStorage.Spec.PrometheusTLS.Enabled() {
prometheusCACert = fmt.Sprintf("\n ca_cert: %s", tls.DownstreamTLSCABundlePath)
}
prometheusConfig = fmt.Sprintf(`
prometheus:
host: %s-prometheus.%s.svc
port: %d%s`,
telemetryv1.DefaultServiceName,
namespace,
telemetryv1.DefaultPrometheusPort,
prometheusCACert,
)
}
mcpTLS := ""
if mcpTLSEnabled {
mcpTLS = `
Expand All @@ -211,7 +233,7 @@ tls:
port: 8080
openstack:
enabled: true
allow_write: false%s
allow_write: false%s%s
openshift:
enabled: false
mcp_transport_security:
Expand All @@ -220,7 +242,7 @@ mcp_transport_security:
- "%s"
allowed_origins:
%s%s
`, caCert, mcpHost, allowedOrigins, mcpTLS)
`, caCert, prometheusConfig, mcpHost, allowedOrigins, mcpTLS)
}

// MCPCloudsYAML returns a clouds.yaml using the given auth URL for the MCP sidecar.
Expand Down
40 changes: 38 additions & 2 deletions internal/openstackclient/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import (

"github.com/onsi/gomega"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
telemetryv1 "github.com/openstack-k8s-operators/telemetry-operator/api/v1beta1"
"k8s.io/utils/ptr"
)

func TestMCPConfigYAMLTLSIsIndependentFromCABundle(t *testing.T) {
t.Run("CA bundle configures only downstream trust", func(t *testing.T) {
g := gomega.NewWithT(t)
config := MCPConfigYAML("openstackclient", "openstack", "combined-ca-bundle", false)
config := MCPConfigYAML("openstackclient", "openstack", "combined-ca-bundle", false, nil)

g.Expect(config).To(gomega.ContainSubstring("ca_cert: " + tls.DownstreamTLSCABundlePath))
g.Expect(config).NotTo(gomega.ContainSubstring("\ntls:\n"))
Expand All @@ -33,11 +35,45 @@ func TestMCPConfigYAMLTLSIsIndependentFromCABundle(t *testing.T) {

t.Run("MCP TLS does not require a downstream CA bundle", func(t *testing.T) {
g := gomega.NewWithT(t)
config := MCPConfigYAML("openstackclient", "openstack", "", true)
config := MCPConfigYAML("openstackclient", "openstack", "", true, nil)

g.Expect(config).NotTo(gomega.ContainSubstring("ca_cert:"))
g.Expect(config).To(gomega.ContainSubstring("\ntls:\n"))
g.Expect(config).To(gomega.ContainSubstring("ssl_certfile: /etc/pki/tls/mcp/tls.crt"))
g.Expect(config).To(gomega.ContainSubstring("https://openstackclient-mcp.openstack.svc:8080"))
})
}

func TestMCPConfigYAMLPrometheus(t *testing.T) {
t.Run("no MetricStorage omits the prometheus section", func(t *testing.T) {
g := gomega.NewWithT(t)
config := MCPConfigYAML("openstackclient", "openstack", "", false, nil)

g.Expect(config).NotTo(gomega.ContainSubstring("prometheus:"))
})

t.Run("MetricStorage without TLS configures host/port but no ca_cert", func(t *testing.T) {
g := gomega.NewWithT(t)
metricStorage := &telemetryv1.MetricStorage{}
config := MCPConfigYAML("openstackclient", "openstack", "", false, metricStorage)

g.Expect(config).To(gomega.ContainSubstring(" prometheus:\n host: metric-storage-prometheus.openstack.svc\n port: 9090"))
g.Expect(config).NotTo(gomega.ContainSubstring("prometheus:\n host: metric-storage-prometheus.openstack.svc\n port: 9090\n ca_cert:"))
})

t.Run("MetricStorage with TLS enabled adds ca_cert under prometheus", func(t *testing.T) {
g := gomega.NewWithT(t)
metricStorage := &telemetryv1.MetricStorage{
Spec: telemetryv1.MetricStorageSpec{
PrometheusTLS: tls.SimpleService{
GenericService: tls.GenericService{
SecretName: ptr.To("prometheus-tls-secret"),
},
},
},
}
config := MCPConfigYAML("openstackclient", "openstack", "", false, metricStorage)

g.Expect(config).To(gomega.ContainSubstring(" prometheus:\n host: metric-storage-prometheus.openstack.svc\n port: 9090\n ca_cert: " + tls.DownstreamTLSCABundlePath))
})
}
Loading