mirror of https://github.com/k3s-io/k3s
Tweaked order of ingress IPs in ServiceLB (#8711)
* Tweaked order of ingress IPs in ServiceLB
Previously, ingress IPs were only string-sorted when returned
Sorted by IP family and string-sorted in each family as part of
filterByIPFamily method
* Update pkg/cloudprovider/servicelb.go
* Formatting
Signed-off-by: Jason Costello <jason@hazy.com>
Co-authored-by: Brad Davidson <brad@oatmail.org>
(cherry picked from commit 07ee854914
)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/8889/head
parent
57ed39a4b9
commit
91622fcedc
|
@ -285,8 +285,6 @@ func (k *k3s) getStatus(svc *core.Service) (*core.LoadBalancerStatus, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Strings(expectedIPs)
|
|
||||||
|
|
||||||
loadbalancer := &core.LoadBalancerStatus{}
|
loadbalancer := &core.LoadBalancerStatus{}
|
||||||
for _, ip := range expectedIPs {
|
for _, ip := range expectedIPs {
|
||||||
loadbalancer.Ingress = append(loadbalancer.Ingress, core.LoadBalancerIngress{
|
loadbalancer.Ingress = append(loadbalancer.Ingress, core.LoadBalancerIngress{
|
||||||
|
@ -393,6 +391,9 @@ func filterByIPFamily(ips []string, svc *core.Service) ([]string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Strings(ipv4Addresses)
|
||||||
|
sort.Strings(ipv6Addresses)
|
||||||
|
|
||||||
for _, ipFamily := range svc.Spec.IPFamilies {
|
for _, ipFamily := range svc.Spec.IPFamilies {
|
||||||
switch ipFamily {
|
switch ipFamily {
|
||||||
case core.IPv4Protocol:
|
case core.IPv4Protocol:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cloudprovider
|
package cloudprovider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/rand"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -9,7 +10,9 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
addrv4 = "1.2.3.4"
|
addrv4 = "1.2.3.4"
|
||||||
|
addrv4_2 = "2.3.4.5"
|
||||||
addrv6 = "2001:db8::1"
|
addrv6 = "2001:db8::1"
|
||||||
|
addrv6_2 = "3001:db8::1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_UnitFilterByIPFamily(t *testing.T) {
|
func Test_UnitFilterByIPFamily(t *testing.T) {
|
||||||
|
@ -89,3 +92,22 @@ func Test_UnitFilterByIPFamily(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_UnitFilterByIPFamily_Ordering(t *testing.T) {
|
||||||
|
want := []string{addrv4, addrv4_2, addrv6, addrv6_2}
|
||||||
|
ips := []string{addrv4, addrv4_2, addrv6, addrv6_2}
|
||||||
|
rand.Shuffle(len(ips), func(i, j int) {
|
||||||
|
ips[i], ips[j] = ips[j], ips[i]
|
||||||
|
})
|
||||||
|
svc := &core.Service{
|
||||||
|
Spec: core.ServiceSpec{
|
||||||
|
IPFamilies: []core.IPFamily{core.IPv4Protocol, core.IPv6Protocol},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
got, _ := filterByIPFamily(ips, svc)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(got, want) {
|
||||||
|
t.Errorf("filterByIPFamily() = %+v\nWant = %+v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue