Skip to content

Commit 1c5efe7

Browse files
author
caiweidong
committed
Rename some varible and clean up codes in scheduler_binder.go
1 parent 10fc2a1 commit 1c5efe7

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

pkg/controller/volume/persistentvolume/scheduler_binder.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,26 +160,26 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, node *v1.Node) (unboundVolume
160160
}()
161161

162162
var (
163-
matchedClaims []*bindingInfo
163+
matchedBindings []*bindingInfo
164164
provisionedClaims []*v1.PersistentVolumeClaim
165165
)
166166
defer func() {
167167
// We recreate bindings for each new schedule loop.
168-
if len(matchedClaims) == 0 && len(provisionedClaims) == 0 {
168+
if len(matchedBindings) == 0 && len(provisionedClaims) == 0 {
169169
// Clear cache if no claims to bind or provision for this node.
170170
b.podBindingCache.ClearBindings(pod, node.Name)
171171
return
172172
}
173173
// Although we do not distinguish nil from empty in this function, for
174174
// easier testing, we normalize empty to nil.
175-
if len(matchedClaims) == 0 {
176-
matchedClaims = nil
175+
if len(matchedBindings) == 0 {
176+
matchedBindings = nil
177177
}
178178
if len(provisionedClaims) == 0 {
179179
provisionedClaims = nil
180180
}
181181
// Mark cache with all matched and provisioned claims for this node
182-
b.podBindingCache.UpdateBindings(pod, node.Name, matchedClaims, provisionedClaims)
182+
b.podBindingCache.UpdateBindings(pod, node.Name, matchedBindings, provisionedClaims)
183183
}()
184184

185185
// The pod's volumes need to be processed in one call to avoid the race condition where
@@ -225,7 +225,7 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, node *v1.Node) (unboundVolume
225225
// Find matching volumes
226226
if len(claimsToFindMatching) > 0 {
227227
var unboundClaims []*v1.PersistentVolumeClaim
228-
unboundVolumesSatisfied, matchedClaims, unboundClaims, err = b.findMatchingVolumes(pod, claimsToFindMatching, node)
228+
unboundVolumesSatisfied, matchedBindings, unboundClaims, err = b.findMatchingVolumes(pod, claimsToFindMatching, node)
229229
if err != nil {
230230
return false, false, err
231231
}
@@ -598,10 +598,10 @@ func (b *volumeBinder) arePodVolumesBound(pod *v1.Pod) bool {
598598

599599
// getPodVolumes returns a pod's PVCs separated into bound, unbound with delayed binding (including provisioning)
600600
// and unbound with immediate binding (including prebound)
601-
func (b *volumeBinder) getPodVolumes(pod *v1.Pod) (boundClaims []*v1.PersistentVolumeClaim, unboundClaims []*v1.PersistentVolumeClaim, unboundClaimsImmediate []*v1.PersistentVolumeClaim, err error) {
601+
func (b *volumeBinder) getPodVolumes(pod *v1.Pod) (boundClaims []*v1.PersistentVolumeClaim, unboundClaimsDelayBinding []*v1.PersistentVolumeClaim, unboundClaimsImmediate []*v1.PersistentVolumeClaim, err error) {
602602
boundClaims = []*v1.PersistentVolumeClaim{}
603603
unboundClaimsImmediate = []*v1.PersistentVolumeClaim{}
604-
unboundClaims = []*v1.PersistentVolumeClaim{}
604+
unboundClaimsDelayBinding = []*v1.PersistentVolumeClaim{}
605605

606606
for _, vol := range pod.Spec.Volumes {
607607
volumeBound, pvc, err := b.isVolumeBound(pod.Namespace, &vol)
@@ -621,15 +621,15 @@ func (b *volumeBinder) getPodVolumes(pod *v1.Pod) (boundClaims []*v1.PersistentV
621621
// Prebound PVCs are treated as unbound immediate binding
622622
if delayBindingMode && pvc.Spec.VolumeName == "" {
623623
// Scheduler path
624-
unboundClaims = append(unboundClaims, pvc)
624+
unboundClaimsDelayBinding = append(unboundClaimsDelayBinding, pvc)
625625
} else {
626626
// !delayBindingMode || pvc.Spec.VolumeName != ""
627627
// Immediate binding should have already been bound
628628
unboundClaimsImmediate = append(unboundClaimsImmediate, pvc)
629629
}
630630
}
631631
}
632-
return boundClaims, unboundClaims, unboundClaimsImmediate, nil
632+
return boundClaims, unboundClaimsDelayBinding, unboundClaimsImmediate, nil
633633
}
634634

635635
func (b *volumeBinder) checkBoundClaims(claims []*v1.PersistentVolumeClaim, node *v1.Node, podName string) (bool, error) {
@@ -654,15 +654,14 @@ func (b *volumeBinder) checkBoundClaims(claims []*v1.PersistentVolumeClaim, node
654654

655655
// findMatchingVolumes tries to find matching volumes for given claims,
656656
// and return unbound claims for further provision.
657-
func (b *volumeBinder) findMatchingVolumes(pod *v1.Pod, claimsToBind []*v1.PersistentVolumeClaim, node *v1.Node) (foundMatches bool, matchedClaims []*bindingInfo, unboundClaims []*v1.PersistentVolumeClaim, err error) {
657+
func (b *volumeBinder) findMatchingVolumes(pod *v1.Pod, claimsToBind []*v1.PersistentVolumeClaim, node *v1.Node) (foundMatches bool, bindings []*bindingInfo, unboundClaims []*v1.PersistentVolumeClaim, err error) {
658658
podName := getPodName(pod)
659659
// Sort all the claims by increasing size request to get the smallest fits
660660
sort.Sort(byPVCSize(claimsToBind))
661661

662662
chosenPVs := map[string]*v1.PersistentVolume{}
663663

664664
foundMatches = true
665-
matchedClaims = []*bindingInfo{}
666665

667666
for _, pvc := range claimsToBind {
668667
// Get storage class name from each PVC
@@ -688,7 +687,7 @@ func (b *volumeBinder) findMatchingVolumes(pod *v1.Pod, claimsToBind []*v1.Persi
688687

689688
// matching PV needs to be excluded so we don't select it again
690689
chosenPVs[pv.Name] = pv
691-
matchedClaims = append(matchedClaims, &bindingInfo{pv: pv, pvc: pvc})
690+
bindings = append(bindings, &bindingInfo{pv: pv, pvc: pvc})
692691
klog.V(5).Infof("Found matching PV %q for PVC %q on node %q for pod %q", pv.Name, pvcName, node.Name, podName)
693692
}
694693

0 commit comments

Comments
 (0)