@@ -18,6 +18,7 @@ package controllers
1818
1919import (
2020 "context"
21+ "encoding/json"
2122 "fmt"
2223 "net"
2324 "reflect"
@@ -390,6 +391,12 @@ func (r *MetricStorageReconciler) reconcileNormal(
390391 }
391392 instance .Status .PrometheusTLSPatched = false
392393 }
394+
395+ // Create the PrometheusEndpoint secret that contains the details for Prometheus API endpoint
396+ if err := r .prometheusEndpointSecret (ctx , instance , helper , serviceLabels ); err != nil {
397+ return ctrl.Result {}, err
398+ }
399+
393400 instance .Status .Conditions .MarkTrue (telemetryv1 .PrometheusReadyCondition , condition .ReadyMessage )
394401
395402 // Patch Prometheus service to add route creation
@@ -511,6 +518,60 @@ func (r *MetricStorageReconciler) reconcileNormal(
511518 return ctrl.Result {}, nil
512519}
513520
521+ // PrometheusEndpointSecret creates a Secret that contains the details for Prometheus API endpoint
522+ func (r * MetricStorageReconciler ) prometheusEndpointSecret (
523+ ctx context.Context ,
524+ instance * telemetryv1.MetricStorage ,
525+ helper * helper.Helper ,
526+ labels map [string ]string ,
527+ ) error {
528+ secret := & corev1.Secret {
529+ ObjectMeta : metav1.ObjectMeta {
530+ Name : fmt .Sprintf ("%s-prometheus-endpoint" , instance .Name ),
531+ Namespace : instance .Namespace ,
532+ Labels : labels ,
533+ },
534+ }
535+
536+ secret .Data = map [string ][]byte {
537+ "host" : []byte (fmt .Sprintf ("%s-prometheus.%s.svc" , telemetryv1 .DefaultServiceName , instance .Namespace )),
538+ "port" : []byte (strconv .Itoa (telemetryv1 .DefaultPrometheusPort )),
539+ }
540+
541+ if _ , err := controllerutil .CreateOrUpdate (context .TODO (), helper .GetClient (), secret , func () error {
542+ secret .Type = corev1 .SecretTypeOpaque
543+
544+ err := controllerutil .SetControllerReference (instance , secret , helper .GetScheme ())
545+ if err != nil {
546+ return err
547+ }
548+
549+ return nil
550+ }); err != nil {
551+ return err
552+ }
553+
554+ if instance .Spec .PrometheusTLS .Enabled () {
555+ tlsSecret := & corev1.Secret {
556+ Data : map [string ][]byte {
557+ "ca_secret" : []byte (* instance .Spec .PrometheusTLS .SecretName ),
558+ "ca_key" : []byte (tls .CAKey ),
559+ },
560+ }
561+
562+ patch , err := json .Marshal (tlsSecret )
563+ if err != nil {
564+ return err
565+ }
566+
567+ if err := r .Client .Patch (ctx , secret , client .RawPatch (types .StrategicMergePatchType , patch )); err != nil {
568+ panic (err )
569+ }
570+ }
571+
572+ return nil
573+ }
574+
514575func (r * MetricStorageReconciler ) createServiceScrapeConfig (
515576 ctx context.Context ,
516577 instance * telemetryv1.MetricStorage ,
0 commit comments