mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 11:38:15 +00:00
Ports could be in reverse order or otherwise.
This commit is contained in:
parent
efd8e3c9c7
commit
a2c97c7b0e
@ -274,7 +274,7 @@ func (c *Controller) SetEndpoints(serviceName string, ip net.IP, endpointPorts [
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determine if the endpoint is in the format SetEndpoints expect (one subset,
|
// Determine if the endpoint is in the format SetEndpoints expect (one subset,
|
||||||
// one port, N IP addresses); and if the specified IP address is present and
|
// correct ports, N IP addresses); and if the specified IP address is present and
|
||||||
// the correct number of ip addresses are found.
|
// the correct number of ip addresses are found.
|
||||||
func checkEndpointSubsetFormat(e *api.Endpoints, ip string, ports []api.EndpointPort, count int) (formatCorrect, ipCorrect bool) {
|
func checkEndpointSubsetFormat(e *api.Endpoints, ip string, ports []api.EndpointPort, count int) (formatCorrect, ipCorrect bool) {
|
||||||
if len(e.Subsets) != 1 {
|
if len(e.Subsets) != 1 {
|
||||||
@ -284,9 +284,14 @@ func checkEndpointSubsetFormat(e *api.Endpoints, ip string, ports []api.Endpoint
|
|||||||
if len(sub.Ports) != len(ports) {
|
if len(sub.Ports) != len(ports) {
|
||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
for i, p := range ports {
|
for _, port := range ports {
|
||||||
ep := &sub.Ports[i]
|
contains := false
|
||||||
if p.Port != ep.Port || p.Protocol != ep.Protocol || p.Name != ep.Name {
|
for _, subPort := range sub.Ports {
|
||||||
|
if port == subPort {
|
||||||
|
contains = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !contains {
|
||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,6 +291,29 @@ func TestSetEndpoints(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "existing endpoints extra un-ordered service ports satisfy",
|
||||||
|
serviceName: "foo",
|
||||||
|
ip: "1.2.3.4",
|
||||||
|
endpointPorts: []api.EndpointPort{
|
||||||
|
{Name: "baz", Port: 1010, Protocol: "TCP"},
|
||||||
|
{Name: "foo", Port: 8080, Protocol: "TCP"},
|
||||||
|
{Name: "bar", Port: 1000, Protocol: "TCP"},
|
||||||
|
},
|
||||||
|
endpoints: &api.EndpointsList{
|
||||||
|
Items: []api.Endpoints{{
|
||||||
|
ObjectMeta: om("foo"),
|
||||||
|
Subsets: []api.EndpointSubset{{
|
||||||
|
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
|
||||||
|
Ports: []api.EndpointPort{
|
||||||
|
{Name: "bar", Port: 1000, Protocol: "TCP"},
|
||||||
|
{Name: "foo", Port: 8080, Protocol: "TCP"},
|
||||||
|
{Name: "baz", Port: 1010, Protocol: "TCP"},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
testName: "existing endpoints extra service ports missing port",
|
testName: "existing endpoints extra service ports missing port",
|
||||||
serviceName: "foo",
|
serviceName: "foo",
|
||||||
|
Loading…
Reference in New Issue
Block a user