From cb92dbd6bec647b5b4efe9da4769bea6ba057f72 Mon Sep 17 00:00:00 2001 From: Dawn Chen Date: Thu, 22 Jan 2015 11:55:04 -0800 Subject: [PATCH] Generate pod.Name when pod.Name == "" for both HTTP and file sources. Fix #3584 --- pkg/kubelet/config/file.go | 6 ++++++ pkg/kubelet/config/http.go | 5 +++++ pkg/kubelet/config/http_test.go | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/pkg/kubelet/config/file.go b/pkg/kubelet/config/file.go index 84667dad592..bcc41bc49ad 100644 --- a/pkg/kubelet/config/file.go +++ b/pkg/kubelet/config/file.go @@ -156,6 +156,12 @@ func extractFromFile(filename string) (api.BoundPod, error) { if len(pod.UID) == 0 { pod.UID = simpleSubdomainSafeHash(filename) } + // This is required for backward compatibility, and should be removed once we + // completely deprecate ContainerManifest. + if len(pod.Name) == 0 { + pod.Name = string(pod.UID) + glog.V(5).Infof("Generated Name %q for UID %q from file %s", pod.Name, pod.UID, filename) + } if len(pod.Namespace) == 0 { pod.Namespace = api.NamespaceDefault } diff --git a/pkg/kubelet/config/http.go b/pkg/kubelet/config/http.go index 0670f33a8da..7ebdec75677 100644 --- a/pkg/kubelet/config/http.go +++ b/pkg/kubelet/config/http.go @@ -91,6 +91,11 @@ func (s *sourceURL) extractFromURL() error { if err := api.Scheme.Convert(&manifest, &pod); err != nil { return err } + // This is required for backward compatibility, and should be removed once we + // completely deprecate ContainerManifest. + if len(pod.Name) == 0 { + pod.Name = "1" + } if len(pod.Namespace) == 0 { pod.Namespace = api.NamespaceDefault } diff --git a/pkg/kubelet/config/http_test.go b/pkg/kubelet/config/http_test.go index a1c0b7d101b..b0421133337 100644 --- a/pkg/kubelet/config/http_test.go +++ b/pkg/kubelet/config/http_test.go @@ -136,6 +136,23 @@ func TestExtractFromHTTP(t *testing.T) { }, }), }, + { + desc: "Single manifest without ID", + manifests: api.ContainerManifest{Version: "v1beta1", UUID: "111"}, + expected: CreatePodUpdate(kubelet.SET, + kubelet.HTTPSource, + api.BoundPod{ + ObjectMeta: api.ObjectMeta{ + UID: "111", + Name: "1", + Namespace: "default", + }, + Spec: api.PodSpec{ + RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{}}, + DNSPolicy: api.DNSClusterFirst, + }, + }), + }, { desc: "Multiple manifests", manifests: []api.ContainerManifest{