@@ -19,7 +19,10 @@ package controllers
1919import (
2020 "context"
2121 "fmt"
22+ "strconv"
23+
2224 "github.com/openstack-k8s-operators/telemetry-operator/pkg/cloudkitty"
25+ "github.com/openstack-k8s-operators/telemetry-operator/pkg/metricstorage"
2326
2427 k8s_errors "k8s.io/apimachinery/pkg/api/errors"
2528 "k8s.io/apimachinery/pkg/runtime"
@@ -813,6 +816,7 @@ func (r *CloudKittyReconciler) generateServiceConfigs(
813816 memcached * memcachedv1.Memcached ,
814817 db * mariadbv1.Database ,
815818) error {
819+ Log := r .GetLogger (ctx )
816820 //
817821 // create Secret required for cloudkitty input
818822 // - %-scripts holds scripts to e.g. bootstrap the service
@@ -855,6 +859,46 @@ func (r *CloudKittyReconciler) generateServiceConfigs(
855859 return err
856860 }
857861
862+ if instance .Spec .PrometheusHost == "" {
863+ // We're using MetricStorage for Prometheus.
864+ prometheusEndpointSecret := & corev1.Secret {}
865+ err = r .Client .Get (ctx , client.ObjectKey {
866+ Name : cloudkitty .PrometheusEndpointSecret ,
867+ Namespace : instance .Namespace ,
868+ }, prometheusEndpointSecret )
869+ if err != nil {
870+ Log .Info ("Prometheus Endpoint Secret not found" )
871+ }
872+ if prometheusEndpointSecret .Data != nil {
873+ instance .Status .PrometheusHost = string (prometheusEndpointSecret .Data [metricstorage .PrometheusHost ])
874+ port , err := strconv .Atoi (string (prometheusEndpointSecret .Data [metricstorage .PrometheusPort ]))
875+ if err != nil {
876+ return err
877+ }
878+ instance .Status .PrometheusPort = int32 (port )
879+
880+ metricStorage := & telemetryv1.MetricStorage {}
881+ err = r .Client .Get (ctx , client.ObjectKey {
882+ Namespace : instance .Namespace ,
883+ Name : telemetryv1 .DefaultServiceName ,
884+ }, metricStorage )
885+ if err != nil {
886+ instance .Status .Conditions .Set (condition .FalseCondition (
887+ condition .ServiceConfigReadyCondition ,
888+ condition .ErrorReason ,
889+ condition .SeverityWarning ,
890+ condition .ServiceConfigReadyErrorMessage ,
891+ err .Error ()))
892+ }
893+ instance .Status .PrometheusTLS = metricStorage .Spec .PrometheusTLS .Enabled ()
894+ }
895+ } else {
896+ // We're using user-deployed Prometheus.
897+ instance .Status .PrometheusHost = instance .Spec .PrometheusHost
898+ instance .Status .PrometheusPort = instance .Spec .PrometheusPort
899+ instance .Status .PrometheusTLS = instance .Spec .PrometheusTLSCaCertSecret != nil
900+ }
901+
858902 databaseAccount := db .GetAccount ()
859903 dbSecret := db .GetSecret ()
860904
@@ -864,6 +908,8 @@ func (r *CloudKittyReconciler) generateServiceConfigs(
864908 templateParameters ["KeystoneInternalURL" ] = keystoneInternalURL
865909 templateParameters ["KeystonePublicURL" ] = keystonePublicURL
866910 templateParameters ["TransportURL" ] = string (transportURLSecret .Data ["transport_url" ])
911+ templateParameters ["PrometheusHost" ] = instance .Status .PrometheusHost
912+ templateParameters ["PrometheusPort" ] = instance .Status .PrometheusPort
867913 templateParameters ["DatabaseConnection" ] = fmt .Sprintf ("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf" ,
868914 databaseAccount .Spec .UserName ,
869915 string (dbSecret .Data [mariadbv1 .DatabasePasswordSelector ]),
0 commit comments