Break out of the loop when active endpoint is found

This commit is contained in:
Ted Yu 2019-09-11 09:01:06 -07:00 committed by Ted Yu
parent 8b4fd4104d
commit 31581e7cb5

View File

@ -210,6 +210,7 @@ func (c *AvailableConditionController) sync(key string) error {
if port.Port == *servicePort { if port.Port == *servicePort {
foundPort = true foundPort = true
portName = port.Name portName = port.Name
break
} }
} }
if !foundPort { if !foundPort {
@ -238,6 +239,7 @@ func (c *AvailableConditionController) sync(key string) error {
return err return err
} }
hasActiveEndpoints := false hasActiveEndpoints := false
outer:
for _, subset := range endpoints.Subsets { for _, subset := range endpoints.Subsets {
if len(subset.Addresses) == 0 { if len(subset.Addresses) == 0 {
continue continue
@ -245,6 +247,7 @@ func (c *AvailableConditionController) sync(key string) error {
for _, endpointPort := range subset.Ports { for _, endpointPort := range subset.Ports {
if endpointPort.Name == portName { if endpointPort.Name == portName {
hasActiveEndpoints = true hasActiveEndpoints = true
break outer
} }
} }
} }