@@ -115,7 +115,7 @@ type InTreeToCSITranslator interface {
115
115
// PV controller to fully bind and provision the PVCs. If binding fails, the Pod is sent
116
116
// back through the scheduler.
117
117
// ii. After BindPodVolumes() is complete, then the scheduler does the final Pod->Node binding.
118
- // 2. Once all the assume operations are done in d ), the scheduler processes the next Pod in the scheduler queue
118
+ // 2. Once all the assume operations are done in e ), the scheduler processes the next Pod in the scheduler queue
119
119
// while the actual binding operation occurs in the background.
120
120
type SchedulerVolumeBinder interface {
121
121
// GetPodVolumes returns a pod's PVCs separated into bound, unbound with delayed binding (including provisioning)
@@ -160,14 +160,15 @@ type SchedulerVolumeBinder interface {
160
160
}
161
161
162
162
type volumeBinder struct {
163
- kubeClient clientset.Interface
164
- classLister storagelisters.StorageClassLister
163
+ kubeClient clientset.Interface
165
164
166
- podLister corelisters.PodLister
167
- nodeInformer coreinformers.NodeInformer
168
- csiNodeInformer storageinformers.CSINodeInformer
169
- pvcCache PVCAssumeCache
170
- pvCache PVAssumeCache
165
+ classLister storagelisters.StorageClassLister
166
+ podLister corelisters.PodLister
167
+ nodeLister corelisters.NodeLister
168
+ csiNodeLister storagelisters.CSINodeLister
169
+
170
+ pvcCache PVCAssumeCache
171
+ pvCache PVAssumeCache
171
172
172
173
// Amount of time to wait for the bind operation to succeed
173
174
bindTimeout time.Duration
@@ -186,15 +187,15 @@ func NewVolumeBinder(
186
187
storageClassInformer storageinformers.StorageClassInformer ,
187
188
bindTimeout time.Duration ) SchedulerVolumeBinder {
188
189
return & volumeBinder {
189
- kubeClient : kubeClient ,
190
- podLister : podInformer .Lister (),
191
- classLister : storageClassInformer .Lister (),
192
- nodeInformer : nodeInformer ,
193
- csiNodeInformer : csiNodeInformer ,
194
- pvcCache : NewPVCAssumeCache (pvcInformer .Informer ()),
195
- pvCache : NewPVAssumeCache (pvInformer .Informer ()),
196
- bindTimeout : bindTimeout ,
197
- translator : csitrans .New (),
190
+ kubeClient : kubeClient ,
191
+ podLister : podInformer .Lister (),
192
+ classLister : storageClassInformer .Lister (),
193
+ nodeLister : nodeInformer . Lister () ,
194
+ csiNodeLister : csiNodeInformer . Lister () ,
195
+ pvcCache : NewPVCAssumeCache (pvcInformer .Informer ()),
196
+ pvCache : NewPVAssumeCache (pvInformer .Informer ()),
197
+ bindTimeout : bindTimeout ,
198
+ translator : csitrans .New (),
198
199
}
199
200
}
200
201
@@ -234,20 +235,20 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, boundClaims, claimsToBind []*
234
235
}()
235
236
236
237
var (
237
- matchedBindings []* BindingInfo
238
- provisionedClaims []* v1.PersistentVolumeClaim
238
+ staticBindings []* BindingInfo
239
+ dynamicProvisions []* v1.PersistentVolumeClaim
239
240
)
240
241
defer func () {
241
242
// Although we do not distinguish nil from empty in this function, for
242
243
// easier testing, we normalize empty to nil.
243
- if len (matchedBindings ) == 0 {
244
- matchedBindings = nil
244
+ if len (staticBindings ) == 0 {
245
+ staticBindings = nil
245
246
}
246
- if len (provisionedClaims ) == 0 {
247
- provisionedClaims = nil
247
+ if len (dynamicProvisions ) == 0 {
248
+ dynamicProvisions = nil
248
249
}
249
- podVolumes .StaticBindings = matchedBindings
250
- podVolumes .DynamicProvisions = provisionedClaims
250
+ podVolumes .StaticBindings = staticBindings
251
+ podVolumes .DynamicProvisions = dynamicProvisions
251
252
}()
252
253
253
254
// Check PV node affinity on bound volumes
@@ -282,7 +283,7 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, boundClaims, claimsToBind []*
282
283
// Find matching volumes
283
284
if len (claimsToFindMatching ) > 0 {
284
285
var unboundClaims []* v1.PersistentVolumeClaim
285
- unboundVolumesSatisfied , matchedBindings , unboundClaims , err = b .findMatchingVolumes (pod , claimsToFindMatching , node )
286
+ unboundVolumesSatisfied , staticBindings , unboundClaims , err = b .findMatchingVolumes (pod , claimsToFindMatching , node )
286
287
if err != nil {
287
288
return
288
289
}
@@ -291,7 +292,7 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, boundClaims, claimsToBind []*
291
292
292
293
// Check for claims to provision
293
294
if len (claimsToProvision ) > 0 {
294
- unboundVolumesSatisfied , provisionedClaims , err = b .checkVolumeProvisions (pod , claimsToProvision , node )
295
+ unboundVolumesSatisfied , dynamicProvisions , err = b .checkVolumeProvisions (pod , claimsToProvision , node )
295
296
if err != nil {
296
297
return
297
298
}
@@ -452,7 +453,7 @@ func (b *volumeBinder) bindAPIUpdate(podName string, bindings []*BindingInfo, cl
452
453
for _ , binding = range bindings {
453
454
klog .V (5 ).Infof ("bindAPIUpdate: Pod %q, binding PV %q to PVC %q" , podName , binding .pv .Name , binding .pvc .Name )
454
455
// TODO: does it hurt if we make an api call and nothing needs to be updated?
455
- claimKey := claimToClaimKey (binding .pvc )
456
+ claimKey := getPVCName (binding .pvc )
456
457
klog .V (2 ).Infof ("claim %q bound to volume %q" , claimKey , binding .pv .Name )
457
458
newPV , err := b .kubeClient .CoreV1 ().PersistentVolumes ().Update (context .TODO (), binding .pv , metav1.UpdateOptions {})
458
459
if err != nil {
@@ -504,12 +505,12 @@ func (b *volumeBinder) checkBindings(pod *v1.Pod, bindings []*BindingInfo, claim
504
505
return false , fmt .Errorf ("failed to get cached claims to provision for pod %q" , podName )
505
506
}
506
507
507
- node , err := b .nodeInformer . Lister () .Get (pod .Spec .NodeName )
508
+ node , err := b .nodeLister .Get (pod .Spec .NodeName )
508
509
if err != nil {
509
510
return false , fmt .Errorf ("failed to get node %q: %v" , pod .Spec .NodeName , err )
510
511
}
511
512
512
- csiNode , err := b .csiNodeInformer . Lister () .Get (node .Name )
513
+ csiNode , err := b .csiNodeLister .Get (node .Name )
513
514
if err != nil {
514
515
// TODO: return the error once CSINode is created by default
515
516
klog .V (4 ).Infof ("Could not get a CSINode object for the node %q: %v" , node .Name , err )
@@ -711,7 +712,7 @@ func (b *volumeBinder) GetPodVolumes(pod *v1.Pod) (boundClaims []*v1.PersistentV
711
712
}
712
713
713
714
func (b * volumeBinder ) checkBoundClaims (claims []* v1.PersistentVolumeClaim , node * v1.Node , podName string ) (bool , error ) {
714
- csiNode , err := b .csiNodeInformer . Lister () .Get (node .Name )
715
+ csiNode , err := b .csiNodeLister .Get (node .Name )
715
716
if err != nil {
716
717
// TODO: return the error once CSINode is created by default
717
718
klog .V (4 ).Infof ("Could not get a CSINode object for the node %q: %v" , node .Name , err )
@@ -786,9 +787,9 @@ func (b *volumeBinder) findMatchingVolumes(pod *v1.Pod, claimsToBind []*v1.Persi
786
787
// checkVolumeProvisions checks given unbound claims (the claims have gone through func
787
788
// findMatchingVolumes, and do not have matching volumes for binding), and return true
788
789
// if all of the claims are eligible for dynamic provision.
789
- func (b * volumeBinder ) checkVolumeProvisions (pod * v1.Pod , claimsToProvision []* v1.PersistentVolumeClaim , node * v1.Node ) (provisionSatisfied bool , provisionedClaims []* v1.PersistentVolumeClaim , err error ) {
790
+ func (b * volumeBinder ) checkVolumeProvisions (pod * v1.Pod , claimsToProvision []* v1.PersistentVolumeClaim , node * v1.Node ) (provisionSatisfied bool , dynamicProvisions []* v1.PersistentVolumeClaim , err error ) {
790
791
podName := getPodName (pod )
791
- provisionedClaims = []* v1.PersistentVolumeClaim {}
792
+ dynamicProvisions = []* v1.PersistentVolumeClaim {}
792
793
793
794
for _ , claim := range claimsToProvision {
794
795
pvcName := getPVCName (claim )
@@ -816,12 +817,12 @@ func (b *volumeBinder) checkVolumeProvisions(pod *v1.Pod, claimsToProvision []*v
816
817
// TODO: Check if capacity of the node domain in the storage class
817
818
// can satisfy resource requirement of given claim
818
819
819
- provisionedClaims = append (provisionedClaims , claim )
820
+ dynamicProvisions = append (dynamicProvisions , claim )
820
821
821
822
}
822
823
klog .V (4 ).Infof ("Provisioning for %d claims of pod %q that has no matching volumes on node %q ..." , len (claimsToProvision ), podName , node .Name )
823
824
824
- return true , provisionedClaims , nil
825
+ return true , dynamicProvisions , nil
825
826
}
826
827
827
828
func (b * volumeBinder ) revertAssumedPVs (bindings []* BindingInfo ) {
@@ -853,10 +854,6 @@ func (a byPVCSize) Less(i, j int) bool {
853
854
return iSize .Cmp (jSize ) == - 1
854
855
}
855
856
856
- func claimToClaimKey (claim * v1.PersistentVolumeClaim ) string {
857
- return fmt .Sprintf ("%s/%s" , claim .Namespace , claim .Name )
858
- }
859
-
860
857
// isCSIMigrationOnForPlugin checks if CSI migrartion is enabled for a given plugin.
861
858
func isCSIMigrationOnForPlugin (pluginName string ) bool {
862
859
switch pluginName {
0 commit comments