From c2d25e08d79c071c3b8405e98c71251a6dc6fce4 Mon Sep 17 00:00:00 2001 From: Yecheng Fu Date: Wed, 16 Jan 2019 14:20:40 +0800 Subject: [PATCH] Skip if pod does not have claims. --- .../persistentvolume/scheduler_binder.go | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/pkg/controller/volume/persistentvolume/scheduler_binder.go b/pkg/controller/volume/persistentvolume/scheduler_binder.go index b285d801ed6..9cbf315d899 100644 --- a/pkg/controller/volume/persistentvolume/scheduler_binder.go +++ b/pkg/controller/volume/persistentvolume/scheduler_binder.go @@ -142,10 +142,40 @@ func (b *volumeBinder) GetBindingsCache() PodBindingCache { return b.podBindingCache } +func podHasClaims(pod *v1.Pod) bool { + for _, vol := range pod.Spec.Volumes { + if vol.PersistentVolumeClaim != nil { + return true + } + } + return false +} + // FindPodVolumes caches the matching PVs and PVCs to provision per node in podBindingCache. // This method intentionally takes in a *v1.Node object instead of using volumebinder.nodeInformer. // That's necessary because some operations will need to pass in to the predicate fake node objects. func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, node *v1.Node) (unboundVolumesSatisfied, boundVolumesSatisfied bool, err error) { + podName := getPodName(pod) + + // Warning: Below log needs high verbosity as it can be printed several times (#60933). + klog.V(5).Infof("FindPodVolumes for pod %q, node %q", podName, node.Name) + + // Initialize to true for pods that don't have volumes + unboundVolumesSatisfied = true + boundVolumesSatisfied = true + start := time.Now() + defer func() { + VolumeSchedulingStageLatency.WithLabelValues("predicate").Observe(time.Since(start).Seconds()) + if err != nil { + VolumeSchedulingStageFailed.WithLabelValues("predicate").Inc() + } + }() + + if !podHasClaims(pod) { + // Fast path + return unboundVolumesSatisfied, boundVolumesSatisfied, nil + } + var ( matchedClaims []*bindingInfo provisionedClaims []*v1.PersistentVolumeClaim @@ -164,22 +194,6 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, node *v1.Node) (unboundVolume b.podBindingCache.UpdateBindings(pod, node.Name, matchedClaims, provisionedClaims) }() - podName := getPodName(pod) - - // Warning: Below log needs high verbosity as it can be printed several times (#60933). - klog.V(5).Infof("FindPodVolumes for pod %q, node %q", podName, node.Name) - - // Initialize to true for pods that don't have volumes - unboundVolumesSatisfied = true - boundVolumesSatisfied = true - start := time.Now() - defer func() { - VolumeSchedulingStageLatency.WithLabelValues("predicate").Observe(time.Since(start).Seconds()) - if err != nil { - VolumeSchedulingStageFailed.WithLabelValues("predicate").Inc() - } - }() - // The pod's volumes need to be processed in one call to avoid the race condition where // volumes can get bound/provisioned in between calls. boundClaims, claimsToBind, unboundClaimsImmediate, err := b.getPodVolumes(pod)