@@ -4,7 +4,10 @@ import (
44 "context"
55 "fmt"
66
7+ certmgrv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
8+ "github.com/openstack-k8s-operators/lib-common/modules/certmanager"
79 "github.com/openstack-k8s-operators/lib-common/modules/common"
10+ "github.com/openstack-k8s-operators/lib-common/modules/common/clusterdns"
811 "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
912 "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
1013 "github.com/openstack-k8s-operators/lib-common/modules/common/service"
@@ -29,6 +32,7 @@ const (
2932
3033// ReconcileTelemetry puts telemetry resources to required state
3134func ReconcileTelemetry (ctx context.Context , instance * corev1beta1.OpenStackControlPlane , version * corev1beta1.OpenStackVersion , helper * helper.Helper ) (ctrl.Result , error ) {
35+ Log := helper .GetLogger ()
3236 telemetry := & telemetryv1.Telemetry {
3337 ObjectMeta : metav1.ObjectMeta {
3438 Name : telemetryName ,
@@ -272,6 +276,7 @@ func ReconcileTelemetry(ctx context.Context, instance *corev1beta1.OpenStackCont
272276 if instance .Spec .TLS .PodLevel .Enabled {
273277 instance .Spec .Telemetry .Template .Autoscaling .Aodh .TLS = telemetry .Spec .Autoscaling .Aodh .TLS
274278 instance .Spec .Telemetry .Template .MetricStorage .PrometheusTLS = telemetry .Spec .MetricStorage .PrometheusTLS
279+ instance .Spec .Telemetry .Template .MetricStorage .PrometheusClientCertSecret = telemetry .Spec .MetricStorage .PrometheusClientCertSecret
275280 instance .Spec .Telemetry .Template .Ceilometer .TLS = telemetry .Spec .Ceilometer .TLS
276281 instance .Spec .Telemetry .Template .Ceilometer .MysqldExporterTLS = telemetry .Spec .Ceilometer .MysqldExporterTLS
277282 instance .Spec .Telemetry .Template .Ceilometer .KSMTLS = telemetry .Spec .Ceilometer .KSMTLS
@@ -440,6 +445,47 @@ func ReconcileTelemetry(ctx context.Context, instance *corev1beta1.OpenStackCont
440445 // update TLS settings with cert secret
441446 instance .Spec .Telemetry .Template .MetricStorage .PrometheusTLS .SecretName = endpointDetails .GetEndptCertSecret (service .EndpointInternal )
442447
448+ // Generate Prometheus client certificate for scraping metrics from TLS-enabled endpoints
449+ if instance .Spec .TLS .PodLevel .Enabled {
450+ if promSvc , ok := endpointDetails .EndpointDetails [service .EndpointInternal ]; ok {
451+ Log .Info ("Reconciling Prometheus client certificate" , telemetryNamespaceLabel , instance .Namespace )
452+ clusterDomain := clusterdns .GetDNSClusterDomain ()
453+ certRequest := certmanager.CertificateRequest {
454+ IssuerName : instance .GetInternalIssuer (),
455+ CertName : fmt .Sprintf ("%s-client" , promSvc .Name ),
456+ Hostnames : []string {
457+ fmt .Sprintf ("*.%s.svc" , instance .Namespace ),
458+ fmt .Sprintf ("*.%s.svc.%s" , instance .Namespace , clusterDomain ),
459+ },
460+ Usages : []certmgrv1.KeyUsage {
461+ certmgrv1 .UsageKeyEncipherment ,
462+ certmgrv1 .UsageDigitalSignature ,
463+ certmgrv1 .UsageClientAuth ,
464+ },
465+ Labels : map [string ]string {ServiceCertSelector : "" },
466+ }
467+ if instance .Spec .TLS .PodLevel .Internal .Cert .Duration != nil {
468+ certRequest .Duration = & instance .Spec .TLS .PodLevel .Internal .Cert .Duration .Duration
469+ }
470+ if instance .Spec .TLS .PodLevel .Internal .Cert .RenewBefore != nil {
471+ certRequest .RenewBefore = & instance .Spec .TLS .PodLevel .Internal .Cert .RenewBefore .Duration
472+ }
473+ certSecret , ctrlResult , err := certmanager .EnsureCert (
474+ ctx ,
475+ helper ,
476+ certRequest ,
477+ nil )
478+ if err != nil {
479+ return ctrlResult , err
480+ } else if (ctrlResult != ctrl.Result {}) {
481+ return ctrlResult , nil
482+ }
483+ instance .Spec .Telemetry .Template .MetricStorage .PrometheusClientCertSecret .SecretName = & certSecret .Name
484+ } else {
485+ Log .Info ("Prometheus internal endpoint not found, skipping client certificate generation" , telemetryNamespaceLabel , instance .Namespace )
486+ }
487+ }
488+
443489 // TODO: rewrite this once we have TLS on alertmanager
444490 for _ , alertmanagerSvc := range alertmanagerSvcs .Items {
445491 ed := EndpointDetail {
@@ -539,7 +585,7 @@ func ReconcileTelemetry(ctx context.Context, instance *corev1beta1.OpenStackCont
539585 instance .Spec .Telemetry .Template .Ceilometer .KSMTLS .SecretName = ksmEpDetails .GetEndptCertSecret (service .EndpointInternal )
540586 }
541587
542- helper . GetLogger () .Info ("Reconciling Telemetry" , telemetryNamespaceLabel , instance .Namespace , telemetryNameLabel , telemetryName )
588+ Log .Info ("Reconciling Telemetry" , telemetryNamespaceLabel , instance .Namespace , telemetryNameLabel , telemetryName )
543589 op , err := controllerutil .CreateOrPatch (ctx , helper .GetClient (), telemetry , func () error {
544590 instance .Spec .Telemetry .Template .TelemetrySpecBase .DeepCopyInto (& telemetry .Spec .TelemetrySpecBase )
545591 instance .Spec .Telemetry .Template .Autoscaling .AutoscalingSpecBase .DeepCopyInto (& telemetry .Spec .Autoscaling .AutoscalingSpecBase )
@@ -639,11 +685,11 @@ func ReconcileTelemetry(ctx context.Context, instance *corev1beta1.OpenStackCont
639685 return ctrl.Result {}, err
640686 }
641687 if op != controllerutil .OperationResultNone {
642- helper . GetLogger () .Info (fmt .Sprintf ("%s %s - %s" , telemetryName , telemetry .Name , op ))
688+ Log .Info (fmt .Sprintf ("%s %s - %s" , telemetryName , telemetry .Name , op ))
643689 }
644690
645691 if telemetry .Status .ObservedGeneration == telemetry .Generation && telemetry .IsReady () {
646- helper . GetLogger () .Info ("Telemetry ready condition is true" )
692+ Log .Info ("Telemetry ready condition is true" )
647693 instance .Status .ContainerImages .CeilometerCentralImage = version .Status .ContainerImages .CeilometerCentralImage
648694 instance .Status .ContainerImages .CeilometerComputeImage = version .Status .ContainerImages .CeilometerComputeImage
649695 instance .Status .ContainerImages .CeilometerIpmiImage = version .Status .ContainerImages .CeilometerIpmiImage
0 commit comments