Skip to content

Commit

Permalink
Ignore empty or invalid IP in Endpoint Set*IP
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Jan 21, 2025
1 parent 662dbfd commit a30086d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/submariner.io/v1/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ func getIPFrom(family k8snet.IPFamily, ips []string, ipv4Fallback string) string

func setIP(ips []string, ipv4Fallback, newIP string) ([]string, string) {
family := k8snet.IPFamilyOfString(newIP)
if family == k8snet.IPFamilyUnknown {
return ips, ipv4Fallback
}

if family == k8snet.IPv4 {
ipv4Fallback = newIP
Expand Down
30 changes: 30 additions & 0 deletions pkg/apis/submariner.io/v1/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ func testGetIP(ipsSetter func(*v1.EndpointSpec, []string, string), ipsGetter fun
})
})
})

When("the specified family is IPFamilyUnknown", func() {
BeforeEach(func() {
ips = []string{ipV4Addr, ipV6Addr}
})

It("should return empty string", func() {
Expect(ipsGetter(spec, k8snet.IPFamilyUnknown)).To(BeEmpty())
})
})
}

func testSetIP(initIPs func(*v1.EndpointSpec, []string), ipsSetter func(*v1.EndpointSpec, string),
Expand Down Expand Up @@ -309,6 +319,26 @@ func testSetIP(initIPs func(*v1.EndpointSpec, []string), ipsSetter func(*v1.Endp
})
})
})

When("the specified IP is empty", func() {
BeforeEach(func() {
initialIPs = []string{ipV6Addr}
})

It("should not add it", func() {
verifyIPs([]string{ipV6Addr}, "")
})
})

When("the specified IP is invalid", func() {
BeforeEach(func() {
ipToSet = "invalid"
})

It("should not add it", func() {
verifyIPs([]string{}, "")
})
})
}

func testGetHealthCheckIP() {
Expand Down

0 comments on commit a30086d

Please sign in to comment.