@@ -65,23 +65,25 @@ func (k *kubeLocator) Endpoints() ([]*locator.PrometheusEndpoint, error) {
6565 return nil , err
6666 }
6767 var port int32
68- for _ , p := range endp .Subsets [0 ].Ports {
69- if p .Protocol == v1 .ProtocolTCP {
70- if len (k .portName ) > 0 {
71- if k .portName == p .Name || p .Port == k .portNumber {
72- // 'port' flag was specified; match by name or port value
68+ if len (endp .Subsets ) > 0 {
69+ for _ , p := range endp .Subsets [0 ].Ports {
70+ if p .Protocol == v1 .ProtocolTCP {
71+ if len (k .portName ) > 0 {
72+ if k .portName == p .Name || p .Port == k .portNumber {
73+ // 'port' flag was specified; match by name or port value
74+ port = p .Port
75+ break
76+ }
77+ } else {
78+ // 'port' flag not specified; take the first (TCP) port we found
7379 port = p .Port
7480 break
7581 }
76- } else {
77- // 'port' flag not specified; take the first (TCP) port we found
78- port = p .Port
79- break
8082 }
8183 }
82- }
83- for _ , a := range endp . Subsets [ 0 ]. Addresses {
84- endpoints = append ( endpoints , fmt . Sprintf ( "http://%s:%d" , a . IP , port ))
84+ for _ , a := range endp . Subsets [ 0 ]. Addresses {
85+ endpoints = append ( endpoints , fmt . Sprintf ( "http://%s:%d" , a . IP , port ))
86+ }
8587 }
8688 } else {
8789 pods , err := k .clientset .Core ().Pods (k .namespace ).List (v1.ListOptions {
0 commit comments