Skip to content

Commit f954144

Browse files
committed
Ignore ipv6 addresses.
1 parent 459e5dc commit f954144

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

internal/k8s/models.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package k8s
22

33
import (
44
"fmt"
5+
"regexp"
6+
7+
log "github.com/sirupsen/logrus"
58

69
"k8s.io/api/core/v1"
710
)
@@ -14,6 +17,19 @@ type Endpoint struct {
1417
ExternalIP string
1518
}
1619

20+
func isIpv4(ip string) bool {
21+
matched, err := regexp.MatchString(`^([0-9]{1,3}\.){3}[0-9]{1,3}$`, ip)
22+
if err != nil {
23+
log.WithFields(log.Fields{
24+
"err": err,
25+
"ip" : ip,
26+
}).Error("bad ip or regular experession")
27+
return false
28+
}
29+
30+
return matched
31+
}
32+
1733
// Create a new Endpoint from a k8s NodeAddress block
1834
func NewEndpoint(id string, addresses []v1.NodeAddress) *Endpoint {
1935
e := &Endpoint{
@@ -25,7 +41,14 @@ func NewEndpoint(id string, addresses []v1.NodeAddress) *Endpoint {
2541
case v1.NodeHostName:
2642
e.HostName = item.Address
2743
case v1.NodeInternalIP:
28-
e.InternalIP = item.Address
44+
if isIpv4(item.Address) {
45+
e.InternalIP = item.Address
46+
} else {
47+
log.WithFields(log.Fields{
48+
"ip": item.Address,
49+
"id": id,
50+
}).Info("found IPV6 ignoring")
51+
}
2952
case v1.NodeExternalIP:
3053
e.ExternalIP = item.Address
3154
default:

0 commit comments

Comments
 (0)