Add kubectl describe for endpoints

This commit is contained in:
feisky
2015-11-05 20:47:32 +08:00
parent 4566e039bf
commit 3adb929eb9
5 changed files with 76 additions and 4 deletions

View File

@@ -79,6 +79,7 @@ func describerMap(c *client.Client) map[string]Describer {
"PersistentVolume": &PersistentVolumeDescriber{c},
"PersistentVolumeClaim": &PersistentVolumeClaimDescriber{c},
"Namespace": &NamespaceDescriber{c},
"Endpoints": &EndpointsDescriber{c},
}
return m
}
@@ -1105,6 +1106,76 @@ func describeService(service *api.Service, endpoints *api.Endpoints, events *api
})
}
// EndpointsDescriber generates information about an Endpoint.
type EndpointsDescriber struct {
client.Interface
}
func (d *EndpointsDescriber) Describe(namespace, name string) (string, error) {
c := d.Endpoints(namespace)
ep, err := c.Get(name)
if err != nil {
return "", err
}
events, _ := d.Events(namespace).Search(ep)
return describeEndpoints(ep, events)
}
func describeEndpoints(ep *api.Endpoints, events *api.EventList) (string, error) {
return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", ep.Name)
fmt.Fprintf(out, "Namespace:\t%s\n", ep.Namespace)
fmt.Fprintf(out, "Labels:\t%s\n", labels.FormatLabels(ep.Labels))
fmt.Fprintf(out, "Subsets:\n")
for i := range ep.Subsets {
subset := &ep.Subsets[i]
addresses := []string{}
for _, addr := range subset.Addresses {
addresses = append(addresses, addr.IP)
}
addressesString := strings.Join(addresses, ",")
if len(addressesString) == 0 {
addressesString = "<none>"
}
fmt.Fprintf(out, " Addresses:\t%s\n", addressesString)
notReadyAddresses := []string{}
for _, addr := range subset.NotReadyAddresses {
notReadyAddresses = append(notReadyAddresses, addr.IP)
}
notReadyAddressesString := strings.Join(notReadyAddresses, ",")
if len(notReadyAddressesString) == 0 {
notReadyAddressesString = "<none>"
}
fmt.Fprintf(out, " NotReadyAddresses:\t%s\n", notReadyAddressesString)
if len(subset.Ports) > 0 {
fmt.Fprintf(out, " Ports:\n")
fmt.Fprintf(out, " Name\tPort\tProtocol\n")
fmt.Fprintf(out, " ----\t----\t--------\n")
for _, port := range subset.Ports {
name := port.Name
if len(name) == 0 {
name = "<unnamed>"
}
fmt.Fprintf(out, " %s\t%d\t%s\n", name, port.Port, port.Protocol)
}
}
fmt.Fprintf(out, "\n")
}
if events != nil {
DescribeEvents(events, out)
}
return nil
})
}
// ServiceAccountDescriber generates information about a service.
type ServiceAccountDescriber struct {
client.Interface