mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
Merge pull request #87461 from bboreham/fix-uid-gen
kubelet: ensure static pod UIDs are unique
This commit is contained in:
commit
61dc69ac2c
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user