// ensureMetricsIntegration ensures that router prometheus metrics is integrated with openshift-monitoring for the given ingresscontroller.
ensureMetricsIntegration ensures that router prometheus metrics is integrated with openshift-monitoring for the given ingresscontroller.
// ensureMetricsIntegration ensures that router prometheus metrics is integrated with openshift - monitoring for the given ingresscontroller .
func (r *reconciler) ensureMetricsIntegration(ci *operatorv1.IngressController, svc *corev1.Service, deploymentRef metav1.OwnerReference) error {
	statsSecret := manifests.RouterStatsSecret(ci)
	if err := r.client.Get(context.TODO(), types.NamespacedName{Namespace: statsSecret.Namespace, Name: statsSecret.Name}, statsSecret); err != nil {
		if !errors.IsNotFound(err) {
			return fmt.Errorf("failed to get router stats secret %s/%s, %v", statsSecret.Namespace, statsSecret.Name, err)
		}
		statsSecret.SetOwnerReferences([]metav1.OwnerReference{deploymentRef})
		if err := r.client.Create(context.TODO(), statsSecret); err != nil {
			return fmt.Errorf("failed to create router stats secret %s/%s: %v", statsSecret.Namespace, statsSecret.Name, err)
		}
		log.Info("created router stats secret", "namespace", statsSecret.Namespace, "name", statsSecret.Name)
	}
	cr := manifests.MetricsClusterRole()
	if err := r.client.Get(context.TODO(), types.NamespacedName{Name: cr.Name}, cr); err != nil {
		if !errors.IsNotFound(err) {
			return fmt.Errorf("failed to get router metrics cluster role %s: %v", cr.Name, err)
		}
		if err := r.client.Create(context.TODO(), cr); err != nil {
			return fmt.Errorf("failed to create router metrics cluster role %s: %v", cr.Name, err)
		}
		log.Info("created router metrics cluster role", "name", cr.Name)
	}
	crb := manifests.MetricsClusterRoleBinding()
	if err := r.client.Get(context.TODO(), types.NamespacedName{Name: crb.Name}, crb); err != nil {
		if !errors.IsNotFound(err) {
			return fmt.Errorf("failed to get router metrics cluster role binding %s: %v", crb.Name, err)
		}
		if err := r.client.Create(context.TODO(), crb); err != nil {
			return fmt.Errorf("failed to create router metrics cluster role binding %s: %v", crb.Name, err)
		}
		log.Info("created router metrics cluster role binding", "name", crb.Name)
	}
	mr := manifests.MetricsRole()
	if err := r.client.Get(context.TODO(), types.NamespacedName{Namespace: mr.Namespace, Name: mr.Name}, mr); err != nil {
		if !errors.IsNotFound(err) {
			return fmt.Errorf("failed to get router metrics role %s: %v", mr.Name, err)
		}
		if err := r.client.Create(context.TODO(), mr); err != nil {
			return fmt.Errorf("failed to create router metrics role %s: %v", mr.Name, err)
		}
		log.Info("created router metrics role", "name", mr.Name)
	}
	mrb := manifests.MetricsRoleBinding()
	if err := r.client.Get(context.TODO(), types.NamespacedName{Namespace: mrb.Namespace, Name: mrb.Name}, mrb); err != nil {
		if !errors.IsNotFound(err) {
			return fmt.Errorf("failed to get router metrics role binding %s: %v", mrb.Name, err)
		}
		if err := r.client.Create(context.TODO(), mrb); err != nil {
			return fmt.Errorf("failed to create router metrics role binding %s: %v", mrb.Name, err)
		}
		log.Info("created router metrics role binding", "name", mrb.Name)
	}
	if _, err := r.ensureServiceMonitor(ci, svc, deploymentRef); err != nil {
		return fmt.Errorf("failed to ensure servicemonitor for %s: %v", ci.Name, err)
	}
	return nil
}
func ( r * reconciler ) ensureMetricsIntegration ( ci * operatorv1 . IngressController , svc * corev1 . Service , deploymentRef metav1 . OwnerReference ) error { statsSecret := manifests . RouterStatsSecret ( ci ) if err := r . client . Get ( context . TODO ( ) , types . NamespacedName { Namespace : statsSecret . Namespace , Name : statsSecret . Name } , statsSecret ) ; err != nil { if ! errors . IsNotFound ( err ) { return fmt . Errorf ( " " , statsSecret . Namespace , statsSecret . Name , err ) } statsSecret . SetOwnerReferences ( [ ] metav1 . OwnerReference { deploymentRef } ) if err := r . client . Create ( context . TODO ( ) , statsSecret ) ; err != nil { return fmt . Errorf ( " " , statsSecret . Namespace , statsSecret . Name , err ) } log . Info ( " " , " " , statsSecret . Namespace , " " , statsSecret . Name ) } cr := manifests . MetricsClusterRole ( ) if err := r . client . Get ( context . TODO ( ) , types . NamespacedName { Name : cr . Name } , cr ) ; err != nil { if ! errors . IsNotFound ( err ) { return fmt . Errorf ( " " , cr . Name , err ) } if err := r . client . Create ( context . TODO ( ) , cr ) ; err != nil { return fmt . Errorf ( " " , cr . Name , err ) } log . Info ( " " , " " , cr . Name ) } crb := manifests . MetricsClusterRoleBinding ( ) if err := r . client . Get ( context . TODO ( ) , types . NamespacedName { Name : crb . Name } , crb ) ; err != nil { if ! errors . IsNotFound ( err ) { return fmt . Errorf ( " " , crb . Name , err ) } if err := r . client . Create ( context . TODO ( ) , crb ) ; err != nil { return fmt . Errorf ( " " , crb . Name , err ) } log . Info ( " " , " " , crb . Name ) } mr := manifests . MetricsRole ( ) if err := r . client . Get ( context . TODO ( ) , types . NamespacedName { Namespace : mr . Namespace , Name : mr . Name } , mr ) ; err != nil { if ! errors . IsNotFound ( err ) { return fmt . Errorf ( " " , mr . Name , err ) } if err := r . client . Create ( context . TODO ( ) , mr ) ; err != nil { return fmt . Errorf ( " " , mr . Name , err ) } log . Info ( " " , " " , mr . Name ) } mrb := manifests . MetricsRoleBinding ( ) if err := r . client . Get ( context . TODO ( ) , types . NamespacedName { Namespace : mrb . Namespace , Name : mrb . Name } , mrb ) ; err != nil { if ! errors . IsNotFound ( err ) { return fmt . Errorf ( " " , mrb . Name , err ) } if err := r . client . Create ( context . TODO ( ) , mrb ) ; err != nil { return fmt . Errorf ( " " , mrb . Name , err ) } log . Info ( " " , " " , mrb . Name ) } if _ , err := r . ensureServiceMonitor ( ci , svc , deploymentRef ) ; err != nil { return fmt . Errorf ( " " , ci . Name , err ) } return nil }
ensureMetricsIntegration ensures that router prometheus metrics is integrated with openshift-monitoring for the given ingresscontroller.
ensureMetricsIntegration ensures that router prometheus metrics is integrated with openshift - monitoring for the given ingresscontroller .