@@ -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,14 +445,64 @@ 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
443- // TODO: rewrite this once we have TLS on alertmanager
444- for _ , alertmanagerSvc := range alertmanagerSvcs .Items {
445- ed := EndpointDetail {
446- Name : alertmanagerSvc .Name ,
447- Namespace : alertmanagerSvc .Namespace ,
448- Type : service .Endpoint (alertmanagerSvc .Annotations [service .AnnotationEndpointKey ]),
449- Service : ServiceDetails {
450- Spec : & alertmanagerSvc ,
448+ // Generate Prometheus client certificate for scraping metrics from TLS-enabled endpoints
449+ if instance .Spec .TLS .PodLevel .Enabled {
450+ if promSvc , ok := prometheusEndpointDetails .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+
489+ // EnsureEndpoint for alertmanager
490+ // NOTE: We don't manage the alertmanager service, it's managed by COO, we just annotate it
491+ alertmanagerEndpointDetails , ctrlResult , err := EnsureEndpointConfig (
492+ ctx ,
493+ instance ,
494+ helper ,
495+ telemetry ,
496+ alertmanagerSvcs ,
497+ nil ,
498+ instance .Spec .Telemetry .AlertmanagerOverride ,
499+ corev1beta1 .OpenStackControlPlaneExposeTelemetryReadyCondition ,
500+ false , // TODO (mschuppert) could be removed when all integrated service support TLS
501+ tls.API {
502+ API : tls.APIService {
503+ Public : tls.GenericService {
504+ SecretName : instance .Spec .Telemetry .Template .MetricStorage .AlertmanagerTLS .SecretName ,
505+ },
451506 },
452507 }
453508 ed .Route .Create = alertmanagerSvc .Annotations [service .AnnotationIngressCreateKey ] == "true"
@@ -539,7 +594,7 @@ func ReconcileTelemetry(ctx context.Context, instance *corev1beta1.OpenStackCont
539594 instance .Spec .Telemetry .Template .Ceilometer .KSMTLS .SecretName = ksmEpDetails .GetEndptCertSecret (service .EndpointInternal )
540595 }
541596
542- helper . GetLogger () .Info ("Reconciling Telemetry" , telemetryNamespaceLabel , instance .Namespace , telemetryNameLabel , telemetryName )
597+ Log .Info ("Reconciling Telemetry" , telemetryNamespaceLabel , instance .Namespace , telemetryNameLabel , telemetryName )
543598 op , err := controllerutil .CreateOrPatch (ctx , helper .GetClient (), telemetry , func () error {
544599 instance .Spec .Telemetry .Template .TelemetrySpecBase .DeepCopyInto (& telemetry .Spec .TelemetrySpecBase )
545600 instance .Spec .Telemetry .Template .Autoscaling .AutoscalingSpecBase .DeepCopyInto (& telemetry .Spec .Autoscaling .AutoscalingSpecBase )
@@ -639,11 +694,11 @@ func ReconcileTelemetry(ctx context.Context, instance *corev1beta1.OpenStackCont
639694 return ctrl.Result {}, err
640695 }
641696 if op != controllerutil .OperationResultNone {
642- helper . GetLogger () .Info (fmt .Sprintf ("%s %s - %s" , telemetryName , telemetry .Name , op ))
697+ Log .Info (fmt .Sprintf ("%s %s - %s" , telemetryName , telemetry .Name , op ))
643698 }
644699
645700 if telemetry .Status .ObservedGeneration == telemetry .Generation && telemetry .IsReady () {
646- helper . GetLogger () .Info ("Telemetry ready condition is true" )
701+ Log .Info ("Telemetry ready condition is true" )
647702 instance .Status .ContainerImages .CeilometerCentralImage = version .Status .ContainerImages .CeilometerCentralImage
648703 instance .Status .ContainerImages .CeilometerComputeImage = version .Status .ContainerImages .CeilometerComputeImage
649704 instance .Status .ContainerImages .CeilometerIpmiImage = version .Status .ContainerImages .CeilometerIpmiImage
0 commit comments