mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	scheduler: clean up NoDiskConflict code in predicates.go
This commit is contained in:
		@@ -73,46 +73,31 @@ func (c *CachedNodeInfo) GetNodeInfo(id string) (*api.Node, error) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func isVolumeConflict(volume api.Volume, pod *api.Pod) bool {
 | 
					func isVolumeConflict(volume api.Volume, pod *api.Pod) bool {
 | 
				
			||||||
	if volume.GCEPersistentDisk != nil {
 | 
						for _, existingVolume := range pod.Spec.Volumes {
 | 
				
			||||||
		disk := volume.GCEPersistentDisk
 | 
							// Same GCE Disk can be mounted as read-only by multiple pod simultaneously.
 | 
				
			||||||
 | 
							// Or they conflicts
 | 
				
			||||||
 | 
							if volume.GCEPersistentDisk != nil && existingVolume.GCEPersistentDisk != nil {
 | 
				
			||||||
 | 
								disk, existingDisk := volume.GCEPersistentDisk, existingVolume.GCEPersistentDisk
 | 
				
			||||||
 | 
								if disk.PDName == existingDisk.PDName && !(disk.ReadOnly && existingDisk.ReadOnly) {
 | 
				
			||||||
 | 
									return true
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		existingPod := &(pod.Spec)
 | 
							if volume.AWSElasticBlockStore != nil && existingVolume.AWSElasticBlockStore != nil {
 | 
				
			||||||
		for ix := range existingPod.Volumes {
 | 
								if volume.AWSElasticBlockStore.VolumeID == existingVolume.AWSElasticBlockStore.VolumeID {
 | 
				
			||||||
			if existingPod.Volumes[ix].GCEPersistentDisk != nil &&
 | 
									return true
 | 
				
			||||||
				existingPod.Volumes[ix].GCEPersistentDisk.PDName == disk.PDName &&
 | 
								}
 | 
				
			||||||
				!(existingPod.Volumes[ix].GCEPersistentDisk.ReadOnly && disk.ReadOnly) {
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if volume.RBD != nil && existingVolume.RBD != nil {
 | 
				
			||||||
 | 
								mon, pool, image := volume.RBD.CephMonitors, volume.RBD.RBDPool, volume.RBD.RBDImage
 | 
				
			||||||
 | 
								emon, epool, eimage := existingVolume.RBD.CephMonitors, existingVolume.RBD.RBDPool, existingVolume.RBD.RBDImage
 | 
				
			||||||
 | 
								if haveSame(mon, emon) && pool == epool && image == eimage {
 | 
				
			||||||
				return true
 | 
									return true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if volume.AWSElasticBlockStore != nil {
 | 
					 | 
				
			||||||
		volumeID := volume.AWSElasticBlockStore.VolumeID
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		existingPod := &(pod.Spec)
 | 
					 | 
				
			||||||
		for ix := range existingPod.Volumes {
 | 
					 | 
				
			||||||
			if existingPod.Volumes[ix].AWSElasticBlockStore != nil &&
 | 
					 | 
				
			||||||
				existingPod.Volumes[ix].AWSElasticBlockStore.VolumeID == volumeID {
 | 
					 | 
				
			||||||
				return true
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if volume.RBD != nil {
 | 
					 | 
				
			||||||
		mon := volume.RBD.CephMonitors
 | 
					 | 
				
			||||||
		pool := volume.RBD.RBDPool
 | 
					 | 
				
			||||||
		image := volume.RBD.RBDImage
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		existingPod := &(pod.Spec)
 | 
					 | 
				
			||||||
		for ix := range existingPod.Volumes {
 | 
					 | 
				
			||||||
			if existingPod.Volumes[ix].RBD != nil {
 | 
					 | 
				
			||||||
				mon_m := existingPod.Volumes[ix].RBD.CephMonitors
 | 
					 | 
				
			||||||
				pool_m := existingPod.Volumes[ix].RBD.RBDPool
 | 
					 | 
				
			||||||
				image_m := existingPod.Volumes[ix].RBD.RBDImage
 | 
					 | 
				
			||||||
				if haveSame(mon, mon_m) && pool_m == pool && image_m == image {
 | 
					 | 
				
			||||||
					return true
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return false
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -125,10 +110,9 @@ func isVolumeConflict(volume api.Volume, pod *api.Pod) bool {
 | 
				
			|||||||
// - Ceph RBD forbids if any two pods share at least same monitor, and match pool and image.
 | 
					// - Ceph RBD forbids if any two pods share at least same monitor, and match pool and image.
 | 
				
			||||||
// TODO: migrate this into some per-volume specific code?
 | 
					// TODO: migrate this into some per-volume specific code?
 | 
				
			||||||
func NoDiskConflict(pod *api.Pod, existingPods []*api.Pod, node string) (bool, error) {
 | 
					func NoDiskConflict(pod *api.Pod, existingPods []*api.Pod, node string) (bool, error) {
 | 
				
			||||||
	podSpec := &(pod.Spec)
 | 
						for _, v := range pod.Spec.Volumes {
 | 
				
			||||||
	for ix := range podSpec.Volumes {
 | 
							for _, ev := range existingPods {
 | 
				
			||||||
		for podIx := range existingPods {
 | 
								if isVolumeConflict(v, ev) {
 | 
				
			||||||
			if isVolumeConflict(podSpec.Volumes[ix], existingPods[podIx]) {
 | 
					 | 
				
			||||||
				return false, nil
 | 
									return false, nil
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user