mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Make standalone function to check for (pre-)bound volumes.
Note the semantic change, we now check for UID=""
This commit is contained in:
parent
20305f9235
commit
a195802d3e
@ -270,3 +270,19 @@ func (ctrl *PersistentVolumeController) Stop() {
|
||||
func (ctrl *PersistentVolumeController) isFullySynced() bool {
|
||||
return ctrl.volumeController.HasSynced() && ctrl.claimController.HasSynced()
|
||||
}
|
||||
|
||||
// isVolumeBoundToClaim returns true, if given volume is pre-bound or bound
|
||||
// to specific claim. Both claim.Name and claim.Namespace must be equal.
|
||||
// If claim.UID is present in volume.Spec.ClaimRef, it must be equal too.
|
||||
func isVolumeBoundToClaim(volume *api.PersistentVolume, claim *api.PersistentVolumeClaim) bool {
|
||||
if volume.Spec.ClaimRef == nil {
|
||||
return false
|
||||
}
|
||||
if claim.Name != volume.Spec.ClaimRef.Name || claim.Namespace != volume.Spec.ClaimRef.Namespace {
|
||||
return false
|
||||
}
|
||||
if volume.Spec.ClaimRef.UID != "" && claim.UID != volume.Spec.ClaimRef.UID {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -92,8 +92,8 @@ func (pvIndex *persistentVolumeOrderedIndex) findByClaim(claim *api.PersistentVo
|
||||
continue
|
||||
}
|
||||
|
||||
if claim.Name == volume.Spec.ClaimRef.Name && claim.Namespace == volume.Spec.ClaimRef.Namespace && claim.UID == volume.Spec.ClaimRef.UID {
|
||||
// exact match! No search required.
|
||||
if isVolumeBoundToClaim(volume, claim) {
|
||||
// Exact match! No search required.
|
||||
return volume, nil
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user