Skip to content

Commit

Permalink
Merge pull request #115615 from princepereira/automated-cherry-pick-o…
Browse files Browse the repository at this point in the history
…f-#115503-upstream-release-1.25

Automated cherry pick of #115503: Fix for issue with Loadbalancer policy
  • Loading branch information
k8s-ci-robot committed Mar 10, 2023
2 parents abee58e + 9be591d commit 12b3ca6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/proxy/winkernel/hns.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,28 @@ func (hns hns) getAllEndpointsByNetwork(networkName string) (map[string]*(endpoi
terminating: false,
}
endpointInfos[ep.IpConfigurations[0].IpAddress] = endpointInfos[ep.Id]

if len(ep.IpConfigurations) == 1 {
continue
}

// If ipFamilyPolicy is RequireDualStack or PreferDualStack, then there will be 2 IPS (iPV4 and IPV6)
// in the endpoint list
endpointDualstack := &endpointsInfo{
ip: ep.IpConfigurations[1].IpAddress,
isLocal: uint32(ep.Flags&hcn.EndpointFlagsRemoteEndpoint) == 0,
macAddress: ep.MacAddress,
hnsID: ep.Id,
hns: hns,
// only ready and not terminating endpoints were added to HNS
ready: true,
serving: true,
terminating: false,
}
endpointInfos[ep.IpConfigurations[1].IpAddress] = endpointDualstack
}
klog.V(3).InfoS("Queried endpoints from network", "network", networkName)
klog.V(5).InfoS("Queried endpoints details", "network", networkName, "endpointInfos", endpointInfos)
return endpointInfos, nil
}

Expand Down
47 changes: 47 additions & 0 deletions pkg/proxy/winkernel/hns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/json"

"github.com/Microsoft/hcsshim/hcn"
"github.com/stretchr/testify/assert"

"strings"
"testing"
Expand All @@ -37,6 +38,7 @@ const (
gatewayAddress = "192.168.1.1"
epMacAddress = "00-11-22-33-44-55"
epIpAddress = "192.168.1.3"
epIpv6Address = "192::3"
epIpAddressB = "192.168.1.4"
epIpAddressRemote = "192.168.2.3"
epPaAddress = "10.0.0.3"
Expand All @@ -45,6 +47,51 @@ const (
externalPort = 32440
)

func TestGetAllEndpointsByNetwork(t *testing.T) {
hns := hns{}
Network := mustTestNetwork(t)

ipv4Config := &hcn.IpConfig{
IpAddress: epIpAddress,
}
ipv6Config := &hcn.IpConfig{
IpAddress: epIpv6Address,
}
Endpoint := &hcn.HostComputeEndpoint{
IpConfigurations: []hcn.IpConfig{*ipv4Config, *ipv6Config},
MacAddress: epMacAddress,
SchemaVersion: hcn.SchemaVersion{
Major: 2,
Minor: 0,
},
}
Endpoint, err := Network.CreateEndpoint(Endpoint)
if err != nil {
t.Error(err)
}

mapEndpointsInfo, err := hns.getAllEndpointsByNetwork(Network.Name)
if err != nil {
t.Error(err)
}
endpointIpv4, ipv4EpPresent := mapEndpointsInfo[ipv4Config.IpAddress]
assert.True(t, ipv4EpPresent, "IPV4 endpoint is missing in Dualstack mode")
assert.Equal(t, endpointIpv4.ip, epIpAddress, "IPV4 IP is missing in Dualstack mode")

endpointIpv6, ipv6EpPresent := mapEndpointsInfo[ipv6Config.IpAddress]
assert.True(t, ipv6EpPresent, "IPV6 endpoint is missing in Dualstack mode")
assert.Equal(t, endpointIpv6.ip, epIpv6Address, "IPV6 IP is missing in Dualstack mode")

err = Endpoint.Delete()
if err != nil {
t.Error(err)
}
err = Network.Delete()
if err != nil {
t.Error(err)
}
}

func TestGetNetworkByName(t *testing.T) {
hns := hns{}
Network := mustTestNetwork(t)
Expand Down

0 comments on commit 12b3ca6

Please sign in to comment.