@@ -706,6 +706,7 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
706706 }
707707
708708 }
709+
709710 Log .Info ("Reconciled Service successfully" )
710711 return ctrl.Result {}, nil
711712}
@@ -828,7 +829,14 @@ func (r *OVNDBClusterReconciler) reconcileServices(
828829 common .AppSelector : serviceName ,
829830 "statefulset.kubernetes.io/pod-name" : ovnPod .Name ,
830831 }
831- ovndbServiceLabels := util .MergeMaps (ovndbSelectorLabels , map [string ]string {"type" : ovnv1 .ServiceClusterType })
832+ // Build service labels - always use cluster type, add metrics label if enabled
833+ serviceTypeLabels := map [string ]string {"type" : ovnv1 .ServiceClusterType }
834+ // Add metrics label if metrics are enabled and exporter image is specified
835+ if instance .Spec .ExporterImage != "" && (instance .Spec .MetricsEnabled == nil || * instance .Spec .MetricsEnabled ) {
836+ serviceTypeLabels ["metrics" ] = "enabled"
837+ }
838+ ovndbServiceLabels := util .MergeMaps (ovndbSelectorLabels , serviceTypeLabels )
839+
832840 svc , err := service .NewService (
833841 ovndbcluster .Service (ovnPod .Name , instance , ovndbServiceLabels , ovndbSelectorLabels ),
834842 time .Duration (5 )* time .Second ,
@@ -843,6 +851,23 @@ func (r *OVNDBClusterReconciler) reconcileServices(
843851 } else if (ctrlResult != ctrl.Result {}) {
844852 return ctrl.Result {}, nil
845853 }
854+
855+ // Check if we need to remove metrics label from existing service
856+ needsMetricsRemoval := instance .Spec .ExporterImage == "" || (instance .Spec .MetricsEnabled != nil && ! * instance .Spec .MetricsEnabled )
857+ if needsMetricsRemoval {
858+ // Get the service that was just created/updated
859+ existingSvc , err := service .GetServiceWithName (ctx , helper , ovnPod .Name , ovnPod .Namespace )
860+ if err == nil && existingSvc != nil {
861+ if _ , exists := existingSvc .Labels ["metrics" ]; exists {
862+ // Create a patch to remove the metrics label
863+ delete (existingSvc .Labels , "metrics" )
864+ err = r .GetClient ().Update (ctx , existingSvc )
865+ if err != nil {
866+ return ctrl.Result {}, fmt .Errorf ("error removing metrics label from service %s: %w" , ovnPod .Name , err )
867+ }
868+ }
869+ }
870+ }
846871 // create service - end
847872 }
848873
@@ -985,9 +1010,12 @@ func (r *OVNDBClusterReconciler) generateExternalConfigMaps(
9851010 cms := []util.Template {
9861011 // EDP ConfigMap
9871012 {
988- Name : "ovncontroller-config" ,
989- Namespace : instance .Namespace ,
990- Type : util .TemplateTypeConfig ,
1013+ Name : "ovncontroller-config" ,
1014+ Namespace : instance .Namespace ,
1015+ Type : util .TemplateTypeNone ,
1016+ AdditionalTemplate : map [string ]string {
1017+ "ovsdb-config" : "/ovndbcluster/config/ovsdb-config" ,
1018+ },
9911019 InstanceType : instance .Kind ,
9921020 Labels : cmLabels ,
9931021 ConfigOptions : externalTemplateParameters ,
@@ -1045,6 +1073,8 @@ func (r *OVNDBClusterReconciler) generateServiceConfigMaps(
10451073 templateParameters ["OVNDB_CERT_PATH" ] = ovn_common .OVNDbCertPath
10461074 templateParameters ["OVNDB_KEY_PATH" ] = ovn_common .OVNDbKeyPath
10471075 templateParameters ["OVNDB_CACERT_PATH" ] = ovn_common .OVNDbCaCertPath
1076+ templateParameters ["OVN_METRICS_CERT_PATH" ] = ovn_common .OVNMetricsCertPath
1077+ templateParameters ["OVN_METRICS_KEY_PATH" ] = ovn_common .OVNMetricsKeyPath
10481078
10491079 cms := []util.Template {
10501080 // ScriptsConfigMap
@@ -1057,6 +1087,20 @@ func (r *OVNDBClusterReconciler) generateServiceConfigMaps(
10571087 ConfigOptions : templateParameters ,
10581088 },
10591089 }
1090+ // Add ConfigConfigMap for network exporter only if metrics are enabled and exporter image is specified
1091+ if instance .Spec .ExporterImage != "" && (instance .Spec .MetricsEnabled == nil || * instance .Spec .MetricsEnabled ) {
1092+ cms = append (cms , util.Template {
1093+ Name : fmt .Sprintf ("%s-config" , instance .Name ),
1094+ Namespace : instance .Namespace ,
1095+ Type : util .TemplateTypeNone ,
1096+ AdditionalTemplate : map [string ]string {
1097+ "openstack-network-exporter.yaml" : "/ovndbcluster/config/openstack-network-exporter.yaml" ,
1098+ },
1099+ InstanceType : instance .Kind ,
1100+ Labels : cmLabels ,
1101+ ConfigOptions : templateParameters ,
1102+ })
1103+ }
10601104 return configmap .EnsureConfigMaps (ctx , h , instance , cms , envVars )
10611105}
10621106
0 commit comments