From 0f873376676193e83f07ad7870d9c3cc3a01a357 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sun, 8 Mar 2015 23:44:32 -0400 Subject: [PATCH] Kubelet tests broken on Macs with uppercase names Hostname behavior across operating systems is inconsistent (Macs can have uppercase host names, so can some other systems). In general, always strings.ToLower(os.Hostname()). --- pkg/kubelet/config/config.go | 2 ++ pkg/kubelet/config/file.go | 2 ++ pkg/kubelet/config/http_test.go | 2 ++ pkg/util/node.go | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/kubelet/config/config.go b/pkg/kubelet/config/config.go index aa3c0b064f2..70d23e839d1 100644 --- a/pkg/kubelet/config/config.go +++ b/pkg/kubelet/config/config.go @@ -20,6 +20,7 @@ import ( "fmt" "os" "reflect" + "strings" "sync" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" @@ -367,5 +368,6 @@ func GeneratePodName(name string) (string, error) { if err != nil { return "", err } + hostname = strings.ToLower(hostname) return fmt.Sprintf("%s-%s", name, hostname), nil } diff --git a/pkg/kubelet/config/file.go b/pkg/kubelet/config/file.go index c082c1832d0..1ef9f837355 100644 --- a/pkg/kubelet/config/file.go +++ b/pkg/kubelet/config/file.go @@ -25,6 +25,7 @@ import ( "os" "path/filepath" "sort" + "strings" "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" @@ -172,6 +173,7 @@ func extractFromFile(filename string) (api.BoundPod, error) { if err != nil { return pod, err } + hostname = strings.ToLower(hostname) if len(pod.UID) == 0 { hasher := md5.New() diff --git a/pkg/kubelet/config/http_test.go b/pkg/kubelet/config/http_test.go index b804b33bfce..7c1196e1d2c 100644 --- a/pkg/kubelet/config/http_test.go +++ b/pkg/kubelet/config/http_test.go @@ -20,6 +20,7 @@ import ( "encoding/json" "net/http/httptest" "os" + "strings" "testing" "time" @@ -118,6 +119,7 @@ func TestExtractInvalidManifest(t *testing.T) { func TestExtractFromHTTP(t *testing.T) { hostname, _ := os.Hostname() + hostname = strings.ToLower(hostname) var testCases = []struct { desc string diff --git a/pkg/util/node.go b/pkg/util/node.go index 4db7ae99772..7226da381f1 100644 --- a/pkg/util/node.go +++ b/pkg/util/node.go @@ -34,5 +34,5 @@ func GetHostname(hostnameOverride string) string { } hostname = fqdn } - return strings.TrimSpace(string(hostname)) + return strings.ToLower(strings.TrimSpace(string(hostname))) }