@@ -106,9 +106,10 @@ func k8sServiceFromInfo(info *resource.Info) (*Service, error) {
106
106
serviceCtx .Resource .Selectors = matchLabelSelectorToStrLabels (svcObj .Spec .Selector )
107
107
serviceCtx .Resource .ExposeExternally = (svcObj .Spec .Type == v1 .ServiceTypeLoadBalancer || svcObj .Spec .Type == v1 .ServiceTypeNodePort )
108
108
109
+ prometheusPort , prometheusPortValid := exposedPrometheusScrapePort (svcObj .Annotations )
109
110
for _ , p := range svcObj .Spec .Ports {
110
111
n := SvcNetworkAttr {Port : int (p .Port ), TargetPort : p .TargetPort , Protocol : p .Protocol , name : p .Name }
111
- n .exposeToCluster = exposesPrometheusScrapePort ( & n , svcObj . Annotations )
112
+ n .exposeToCluster = prometheusPortValid && n . equals ( prometheusPort )
112
113
serviceCtx .Resource .Network = append (serviceCtx .Resource .Network , n )
113
114
}
114
115
@@ -117,7 +118,7 @@ func k8sServiceFromInfo(info *resource.Info) (*Service, error) {
117
118
118
119
const defaultPrometheusScrapePort = 9090
119
120
120
- func exposesPrometheusScrapePort ( port * SvcNetworkAttr , annotations map [string ]string ) bool {
121
+ func exposedPrometheusScrapePort ( annotations map [string ]string ) ( * intstr. IntOrString , bool ) {
121
122
scrapeOn := false
122
123
scrapePort := intstr .FromInt (defaultPrometheusScrapePort )
123
124
for k , v := range annotations {
@@ -130,7 +131,7 @@ func exposesPrometheusScrapePort(port *SvcNetworkAttr, annotations map[string]st
130
131
}
131
132
}
132
133
133
- return scrapeOn && port . equals ( & scrapePort )
134
+ return & scrapePort , scrapeOn
134
135
}
135
136
136
137
func (port * SvcNetworkAttr ) equals (intStrPort * intstr.IntOrString ) bool {
0 commit comments