mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #87461 from bboreham/fix-uid-gen
kubelet: ensure static pod UIDs are unique
This commit is contained in:
		@@ -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)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user