From 19de43137bf7b5069fe09e2b94b86217611a36f5 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 20 Mar 2017 17:24:40 -0700 Subject: [PATCH] kubelet: ensure pod UIDs are unique Ensure node name and file path are included in the hash which produces the pod UID, otherwise all pods created from the same manifest have the same UID across the cluster. The real author of this code is Yu-Ju Hong . I am resurrecting an abandoned PR, and changed the git author to pass CLA check. Signed-off-by: Bryan Boreham --- pkg/kubelet/config/common.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/kubelet/config/common.go b/pkg/kubelet/config/common.go index 84280cd435e..2a5733d4f48 100644 --- a/pkg/kubelet/config/common.go +++ b/pkg/kubelet/config/common.go @@ -58,13 +58,15 @@ func generatePodName(name string, nodeName types.NodeName) string { func applyDefaults(pod *api.Pod, source string, isFile bool, nodeName types.NodeName) error { if len(pod.UID) == 0 { hasher := md5.New() + hash.DeepHashObject(hasher, pod) + // DeepHashObject resets the hash, so we should write the pod source + // information AFTER it. if isFile { fmt.Fprintf(hasher, "host:%s", nodeName) fmt.Fprintf(hasher, "file:%s", source) } else { fmt.Fprintf(hasher, "url:%s", source) } - hash.DeepHashObject(hasher, pod) pod.UID = types.UID(hex.EncodeToString(hasher.Sum(nil)[0:])) klog.V(5).Infof("Generated UID %q pod %q from %s", pod.UID, pod.Name, source) }