Skip to content

Commit

Permalink
adds service stats to details
Browse files Browse the repository at this point in the history
  • Loading branch information
mhausenblas committed Nov 29, 2019
1 parent af54a3b commit 89ab9d7
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions pkg/fleet/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func Details(configFlags *genericclioptions.ConfigFlags, args []string) error {
// coreResDetails returns details about useful core resources in given context.
// Useful core resources include pods, services, deployments,
func coreResDetails(cfg api.Config, context string) (result string, err error) {
result = fmt.Sprintf("# Core resources stats by namespace\n\n")
cs, err := csForContext(cfg, context)
if err != nil {
return "", errors.Wrap(err, "Can't create a clientset based on config provided")
Expand All @@ -47,23 +46,37 @@ func coreResDetails(cfg api.Config, context string) (result string, err error) {
}
for _, ns := range namespaces.Items {
nsname := ns.Name
result += fmt.Sprintf("namespace [%v] has ", nsname)
result += fmt.Sprintf("# namespace [%v]\n", nsname)
// pod stats in namespace:
pods, err := cs.CoreV1().Pods(nsname).List(metav1.ListOptions{})
if err != nil {
return "", errors.Wrap(err, "Can't get pods")
}
switch len(pods.Items) {
case 0:
result += fmt.Sprintf("no pods\n")
result += fmt.Sprintf("has no pods\n")
default:
result += fmt.Sprintf("%v pod(s) overall:\n", len(pods.Items))
result += fmt.Sprintf("has %v pod(s) overall:\n", len(pods.Items))
for _, pod := range pods.Items {
result += fmt.Sprintf("- %v", podInfo(pod))
}
}
// service stats in namespace:
svcs, err := cs.CoreV1().Services(nsname).List(metav1.ListOptions{})
if err != nil {
return "", errors.Wrap(err, "Can't get services")
}
switch len(svcs.Items) {
case 0:
result += fmt.Sprintf("has no services\n")
default:
result += fmt.Sprintf("has %v service(s) overall:\n", len(svcs.Items))
for _, svc := range svcs.Items {
result += fmt.Sprintf("- %v", svcInfo(svc))
}
}
// mark end of namespace stats:
result += strings.Repeat("-", 80) + "\n"
result += strings.Repeat("-", 80) + "\n\n"
}
return result, nil
}
Expand All @@ -79,3 +92,16 @@ func podInfo(pod v1.Pod) (result string) {
result += fmt.Sprintf("pod [%v] is %v and uses image(s) %v\n", podname, podstatus, images)
return result
}

// svcInfo renders details of the status and config of a service given
func svcInfo(svc v1.Service) (result string) {
svcname := svc.Name
svctype := svc.Spec.Type
svcclusterip := svc.Spec.ClusterIP
ports := ""
for _, port := range svc.Spec.Ports {
ports += fmt.Sprintf(" %v %v/%v", port.Name, port.Protocol, port.Port)
}
result += fmt.Sprintf("service [%v] of type %v uses IP %v and port(s)%v\n", svcname, svctype, svcclusterip, ports)
return result
}

0 comments on commit 89ab9d7

Please sign in to comment.