refact ep
parent
2c2de7b269
commit
71a0ebc3bf
|
|
@ -94,28 +94,35 @@ func (r *Endpoints) Fields(ns string) Row {
|
||||||
|
|
||||||
func (r *Endpoints) toEPs(ss []v1.EndpointSubset) string {
|
func (r *Endpoints) toEPs(ss []v1.EndpointSubset) string {
|
||||||
aa := make([]string, 0, len(ss))
|
aa := make([]string, 0, len(ss))
|
||||||
max := 3
|
|
||||||
for _, s := range ss {
|
for _, s := range ss {
|
||||||
pp := make([]string, 0, len(s.Ports))
|
pp := make([]string, len(s.Ports))
|
||||||
for _, p := range s.Ports {
|
portsToStrs(s.Ports, pp)
|
||||||
pp = append(pp, strconv.Itoa(int(p.Port)))
|
proccessIPs(aa, pp, s.Addresses)
|
||||||
}
|
|
||||||
|
|
||||||
for _, a := range s.Addresses {
|
|
||||||
if len(a.IP) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(pp) == 0 {
|
|
||||||
aa = append(aa, a.IP)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
add := a.IP + ":" + strings.Join(pp, ",")
|
|
||||||
if len(pp) > max {
|
|
||||||
add = a.IP + ":" + strings.Join(pp[:max], ",") + "..."
|
|
||||||
}
|
|
||||||
aa = append(aa, add)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(aa, ",")
|
return strings.Join(aa, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func portsToStrs(pp []v1.EndpointPort, ss []string) {
|
||||||
|
for i := 0; i < len(pp); i++ {
|
||||||
|
ss[i] = strconv.Itoa(int(pp[i].Port))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func proccessIPs(aa []string, pp []string, addrs []v1.EndpointAddress) {
|
||||||
|
const maxIPs = 3
|
||||||
|
for _, a := range addrs {
|
||||||
|
if len(a.IP) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(pp) == 0 {
|
||||||
|
aa = append(aa, a.IP)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(pp) > maxIPs {
|
||||||
|
aa = append(aa, a.IP+":"+strings.Join(pp[:maxIPs], ",")+"...")
|
||||||
|
} else {
|
||||||
|
aa = append(aa, a.IP+":"+strings.Join(pp, ","))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,21 @@ import (
|
||||||
"github.com/derailed/k9s/internal/color"
|
"github.com/derailed/k9s/internal/color"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LogOptions represent logger options.
|
type (
|
||||||
type LogOptions struct {
|
// Fqn uniquely describes a container
|
||||||
Namespace, Name, Container string
|
Fqn struct {
|
||||||
Lines int64
|
Namespace, Name, Container string
|
||||||
Previous bool
|
}
|
||||||
Color color.Paint
|
|
||||||
}
|
// LogOptions represent logger options.
|
||||||
|
LogOptions struct {
|
||||||
|
Fqn
|
||||||
|
|
||||||
|
Lines int64
|
||||||
|
Previous bool
|
||||||
|
Color color.Paint
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// HasContainer checks if a container is present.
|
// HasContainer checks if a container is present.
|
||||||
func (o LogOptions) HasContainer() bool {
|
func (o LogOptions) HasContainer() bool {
|
||||||
|
|
|
||||||
|
|
@ -124,11 +124,13 @@ func (v *logsView) doLoad(path, co string, prevLogs bool) error {
|
||||||
func (v *logsView) logOpts(path, co string, prevLogs bool) resource.LogOptions {
|
func (v *logsView) logOpts(path, co string, prevLogs bool) resource.LogOptions {
|
||||||
ns, po := namespaced(path)
|
ns, po := namespaced(path)
|
||||||
return resource.LogOptions{
|
return resource.LogOptions{
|
||||||
Namespace: ns,
|
Fqn: resource.Fqn{
|
||||||
Name: po,
|
Namespace: ns,
|
||||||
Container: co,
|
Name: po,
|
||||||
Lines: int64(v.app.config.K9s.LogRequestSize),
|
Container: co,
|
||||||
Previous: prevLogs,
|
},
|
||||||
|
Lines: int64(v.app.config.K9s.LogRequestSize),
|
||||||
|
Previous: prevLogs,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue