mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-03 23:40:03 +00:00 
			
		
		
		
	Merge pull request #42631 from NickrenREN/pv-isVolumeBoundToClaim-1
Automatic merge from submit-queue (batch tested with PRs 42522, 42545, 42556, 42006, 42631) optimize the binding logic of bindClaimToVolume extract var shouldSetBoundByController and do not need to judge volumename twice **Release note**: ```release-note NONE ```
This commit is contained in:
		@@ -790,9 +790,9 @@ func (ctrl *PersistentVolumeController) bindClaimToVolume(claim *v1.PersistentVo
 | 
			
		||||
	dirty := false
 | 
			
		||||
 | 
			
		||||
	// Check if the claim was already bound (either by controller or by user)
 | 
			
		||||
	shouldSetBoundByController := false
 | 
			
		||||
	shouldBind := false
 | 
			
		||||
	if volume.Name != claim.Spec.VolumeName {
 | 
			
		||||
		shouldSetBoundByController = true
 | 
			
		||||
		shouldBind = true
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// The claim from method args can be pointing to watcher cache. We must not
 | 
			
		||||
@@ -806,16 +806,15 @@ func (ctrl *PersistentVolumeController) bindClaimToVolume(claim *v1.PersistentVo
 | 
			
		||||
		return nil, fmt.Errorf("Unexpected claim cast error : %v", claimClone)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Bind the claim to the volume if it is not bound yet
 | 
			
		||||
	if claimClone.Spec.VolumeName != volume.Name {
 | 
			
		||||
		claimClone.Spec.VolumeName = volume.Name
 | 
			
		||||
	if shouldBind {
 | 
			
		||||
		dirty = true
 | 
			
		||||
	}
 | 
			
		||||
		// Bind the claim to the volume
 | 
			
		||||
		claimClone.Spec.VolumeName = volume.Name
 | 
			
		||||
 | 
			
		||||
		// Set annBoundByController if it is not set yet
 | 
			
		||||
	if shouldSetBoundByController && !metav1.HasAnnotation(claimClone.ObjectMeta, annBoundByController) {
 | 
			
		||||
		if !metav1.HasAnnotation(claimClone.ObjectMeta, annBoundByController) {
 | 
			
		||||
			metav1.SetMetaDataAnnotation(&claimClone.ObjectMeta, annBoundByController, "yes")
 | 
			
		||||
		dirty = true
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Set annBindCompleted if it is not set yet
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user