Skip to content

Commit

Permalink
Always use alias as display name if its available.
Browse files Browse the repository at this point in the history
This is useful for identifying k8 containers on /docker handler.
Since k8 handles are pretty long, I arbitrarily decided to truncate the display.
Let me know if you don't like it.
  • Loading branch information
rjnagal committed Feb 28, 2015
1 parent e3e6552 commit 7b6b9e6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pages/pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"html/template"
"net/http"
"strings"

auth "github.com/abbot/go-http-auth"
"github.com/golang/glog"
Expand Down Expand Up @@ -121,14 +122,26 @@ func RegisterHandlersBasic(containerManager manager.Manager, authenticator *auth
}

func getContainerDisplayName(cont info.ContainerReference) string {
// Pick the shortest name of the container as the display name.
displayName := cont.Name
// Pick a user-added alias as display name.
displayName := ""
for _, alias := range cont.Aliases {
if len(displayName) >= len(alias) {
// ignore container id as alias.
if strings.Contains(cont.Name, alias) {
continue
}
// pick shortest display name if multiple aliases are available.
if displayName == "" || len(displayName) >= len(alias) {
displayName = alias
}
}

if displayName == "" {
displayName = cont.Name
} else if len(displayName) > 50 {
// truncate display name to fit in one line.
displayName = displayName[:50] + "..."
}

// Add the full container name to the display name.
if displayName != cont.Name {
displayName = fmt.Sprintf("%s (%s)", displayName, cont.Name)
Expand Down

0 comments on commit 7b6b9e6

Please sign in to comment.