@@ -19,6 +19,8 @@ package controllers
1919import (
2020 "context"
2121 "fmt"
22+ "github.com/openstack-k8s-operators/telemetry-operator/pkg/metricstorage"
23+ "strconv"
2224 "time"
2325
2426 appsv1 "k8s.io/api/apps/v1"
@@ -425,13 +427,30 @@ func (r *AutoscalingReconciler) reconcileNormal(
425427 // Get correct prometheus host, port and if TLS should be used
426428 // NOTE: Always do this before calling the generateServiceConfig to get the newest values in the ServiceConfig
427429 //
430+ prometheusEndpointSecret := & corev1.Secret {}
431+ err = r .Client .Get (ctx , client.ObjectKey {
432+ Name : autoscaling .PrometheusEndpointSecret ,
433+ Namespace : instance .Namespace ,
434+ }, prometheusEndpointSecret )
435+ if err != nil {
436+ Log .Info ("No Prometheus Endpoint Secret found" )
437+ }
438+
428439 if instance .Spec .PrometheusHost == "" {
429- instance .Status .PrometheusHost = fmt .Sprintf ("%s-prometheus.%s.svc" , telemetryv1 .DefaultServiceName , instance .Namespace )
440+ if prometheusEndpointSecret .Data != nil {
441+ instance .Status .PrometheusHost = string (prometheusEndpointSecret .Data [metricstorage .PrometheusHost ])
442+ }
430443 } else {
431444 instance .Status .PrometheusHost = instance .Spec .PrometheusHost
432445 }
433446 if instance .Spec .PrometheusPort == 0 {
434- instance .Status .PrometheusPort = telemetryv1 .DefaultPrometheusPort
447+ if prometheusEndpointSecret .Data != nil {
448+ port , err := strconv .Atoi (string (prometheusEndpointSecret .Data [metricstorage .PrometheusPort ]))
449+ if err != nil {
450+ return ctrlResult , err
451+ }
452+ instance .Status .PrometheusPort = int32 (port )
453+ }
435454 } else {
436455 instance .Status .PrometheusPort = instance .Spec .PrometheusPort
437456 }
@@ -595,8 +614,6 @@ func (r *AutoscalingReconciler) generateServiceConfig(
595614 "AodhPassword" : string (ospSecret .Data [instance .Spec .Aodh .PasswordSelectors .AodhService ]),
596615 "KeystoneInternalURL" : keystoneInternalURL ,
597616 "TransportURL" : string (transportURLSecret .Data ["transport_url" ]),
598- "PrometheusHost" : instance .Status .PrometheusHost ,
599- "PrometheusPort" : instance .Status .PrometheusPort ,
600617 "MemcachedServers" : mc .GetMemcachedServerListString (),
601618 "MemcachedServersWithInet" : mc .GetMemcachedServerListWithInetString (),
602619 "DatabaseConnection" : fmt .Sprintf ("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf" ,
0 commit comments