mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #112675 from aimuz/improve-readability
improve readability, code nesting too deep
This commit is contained in:
commit
adec07998b
@ -619,35 +619,38 @@ func formatEndpoints(endpoints *api.Endpoints, ports sets.String) string {
|
|||||||
ss := &endpoints.Subsets[i]
|
ss := &endpoints.Subsets[i]
|
||||||
if len(ss.Ports) == 0 {
|
if len(ss.Ports) == 0 {
|
||||||
// It's possible to have headless services with no ports.
|
// It's possible to have headless services with no ports.
|
||||||
|
count += len(ss.Addresses)
|
||||||
for i := range ss.Addresses {
|
for i := range ss.Addresses {
|
||||||
if len(list) == max {
|
if len(list) == max {
|
||||||
more = true
|
more = true
|
||||||
|
// the next loop is redundant
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if !more {
|
list = append(list, ss.Addresses[i].IP)
|
||||||
list = append(list, ss.Addresses[i].IP)
|
|
||||||
}
|
|
||||||
count++
|
|
||||||
}
|
}
|
||||||
} else {
|
// avoid nesting code too deeply
|
||||||
// "Normal" services with ports defined.
|
continue
|
||||||
for i := range ss.Ports {
|
}
|
||||||
port := &ss.Ports[i]
|
|
||||||
if ports == nil || ports.Has(port.Name) {
|
// "Normal" services with ports defined.
|
||||||
for i := range ss.Addresses {
|
for i := range ss.Ports {
|
||||||
if len(list) == max {
|
port := &ss.Ports[i]
|
||||||
more = true
|
if ports == nil || ports.Has(port.Name) {
|
||||||
}
|
count += len(ss.Addresses)
|
||||||
addr := &ss.Addresses[i]
|
for i := range ss.Addresses {
|
||||||
if !more {
|
if len(list) == max {
|
||||||
hostPort := net.JoinHostPort(addr.IP, strconv.Itoa(int(port.Port)))
|
more = true
|
||||||
list = append(list, hostPort)
|
// the next loop is redundant
|
||||||
}
|
break
|
||||||
count++
|
|
||||||
}
|
}
|
||||||
|
addr := &ss.Addresses[i]
|
||||||
|
hostPort := net.JoinHostPort(addr.IP, strconv.Itoa(int(port.Port)))
|
||||||
|
list = append(list, hostPort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := strings.Join(list, ",")
|
ret := strings.Join(list, ",")
|
||||||
if more {
|
if more {
|
||||||
return fmt.Sprintf("%s + %d more...", ret, count-max)
|
return fmt.Sprintf("%s + %d more...", ret, count-max)
|
||||||
|
Loading…
Reference in New Issue
Block a user