diff --git a/pkg/kubelet/config/common.go b/pkg/kubelet/config/common.go index 3bbf2166956..85a0a789382 100644 --- a/pkg/kubelet/config/common.go +++ b/pkg/kubelet/config/common.go @@ -21,6 +21,7 @@ import ( "crypto/md5" "encoding/hex" "fmt" + "strings" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1" @@ -33,6 +34,16 @@ import ( "github.com/golang/glog" ) +// Generate a pod name that is unique among nodes by appending the hostname. +func generatePodName(name, hostname string) (string, error) { + // Hostname can be a fully-qualified domain name. To increase readability, + // only append the first chunk. Note that this assumes that no two nodes in + // the cluster should have the same host-specific label; this is true if + // all nodes have the same domain name. + chunks := strings.Split(hostname, ".") + return fmt.Sprintf("%s-%s", name, chunks[0]), nil +} + func applyDefaults(pod *api.Pod, source string, isFile bool, hostname string) error { if len(pod.UID) == 0 { hasher := md5.New() @@ -53,7 +64,7 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, hostname string) er if len(pod.Name) == 0 { pod.Name = string(pod.UID) } - if pod.Name, err = GeneratePodName(pod.Name, hostname); err != nil { + if pod.Name, err = generatePodName(pod.Name, hostname); err != nil { return err } glog.V(5).Infof("Generated Name %q for UID %q from URL %s", pod.Name, pod.UID, source) diff --git a/pkg/kubelet/config/config.go b/pkg/kubelet/config/config.go index 998991dfebd..bc4c1685693 100644 --- a/pkg/kubelet/config/config.go +++ b/pkg/kubelet/config/config.go @@ -361,7 +361,3 @@ func bestPodIdentString(pod *api.Pod) string { } return fmt.Sprintf("%s.%s", name, namespace) } - -func GeneratePodName(name, hostname string) (string, error) { - return fmt.Sprintf("%s-%s", name, hostname), nil -}