Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubectl should be able to display endpoints directly and for service #4195

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/kubectl/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,19 @@ func (d *ServiceDescriber) Describe(namespace, name string) (string, error) {
return "", err
}

endpoints, err := d.Endpoints(namespace).Get(name)
if err != nil {
endpoints = &api.Endpoints{}
}

events, _ := d.Events(namespace).Search(service)

return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", service.Name)
fmt.Fprintf(out, "Labels:\t%s\n", formatLabels(service.Labels))
fmt.Fprintf(out, "Selector:\t%s\n", formatLabels(service.Spec.Selector))
fmt.Fprintf(out, "Port:\t%d\n", service.Spec.Port)
fmt.Fprintf(out, "Endpoints:\t%s\n", stringList(endpoints.Endpoints))
if events != nil {
describeEvents(events, out)
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/kubectl/resource_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func (h *HumanReadablePrinter) validatePrintHandlerFunc(printFunc reflect.Value)
var podColumns = []string{"POD", "IP", "CONTAINER(S)", "IMAGE(S)", "HOST", "LABELS", "STATUS"}
var replicationControllerColumns = []string{"CONTROLLER", "CONTAINER(S)", "IMAGE(S)", "SELECTOR", "REPLICAS"}
var serviceColumns = []string{"NAME", "LABELS", "SELECTOR", "IP", "PORT"}
var endpointColumns = []string{"NAME", "ENDPOINTS"}
var minionColumns = []string{"NAME", "LABELS", "STATUS"}
var statusColumns = []string{"STATUS"}
var eventColumns = []string{"TIME", "NAME", "KIND", "SUBOBJECT", "REASON", "SOURCE", "MESSAGE"}
Expand All @@ -232,6 +233,7 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
h.Handler(replicationControllerColumns, printReplicationControllerList)
h.Handler(serviceColumns, printService)
h.Handler(serviceColumns, printServiceList)
h.Handler(endpointColumns, printEndpoints)
h.Handler(minionColumns, printMinion)
h.Handler(minionColumns, printMinionList)
h.Handler(statusColumns, printStatus)
Expand All @@ -255,6 +257,13 @@ func (h *HumanReadablePrinter) printHeader(columnNames []string, w io.Writer) er
return nil
}

func stringList(list []string) string {
if len(list) == 0 {
return "<empty>"
}
return strings.Join(list, ",")
}

func podHostString(host, ip string) string {
if host == "" && ip == "" {
return "<unassigned>"
Expand Down Expand Up @@ -352,6 +361,11 @@ func printServiceList(list *api.ServiceList, w io.Writer) error {
return nil
}

func printEndpoints(endpoint *api.Endpoints, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\n", endpoint.Name, stringList(endpoint.Endpoints))
return err
}

func printMinion(minion *api.Node, w io.Writer) error {
conditionMap := make(map[api.NodeConditionKind]*api.NodeCondition)
NodeAllConditions := []api.NodeConditionKind{api.NodeReady, api.NodeReachable}
Expand Down
3 changes: 2 additions & 1 deletion pkg/kubectl/resource_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,11 @@ func TestPrinters(t *testing.T) {
"pod": &api.Pod{ObjectMeta: om("pod")},
"emptyPodList": &api.PodList{},
"nonEmptyPodList": &api.PodList{Items: []api.Pod{{}}},
"endpoints": &api.Endpoints{Endpoints: []string{"127.0.0.1", "localhost:8080"}},
}
// map of printer name to set of objects it should fail on.
expectedErrors := map[string]util.StringSet{
"template2": util.NewStringSet("pod", "emptyPodList"),
"template2": util.NewStringSet("pod", "emptyPodList", "endpoints"),
}

for pName, p := range printers {
Expand Down