Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
1c5efe7e
Commit
1c5efe7e
authored
Apr 09, 2019
by
caiweidong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename some varible and clean up codes in scheduler_binder.go
parent
10fc2a11
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
13 deletions
+12
-13
scheduler_binder.go
pkg/controller/volume/persistentvolume/scheduler_binder.go
+12
-13
No files found.
pkg/controller/volume/persistentvolume/scheduler_binder.go
View file @
1c5efe7e
...
@@ -160,26 +160,26 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, node *v1.Node) (unboundVolume
...
@@ -160,26 +160,26 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, node *v1.Node) (unboundVolume
}()
}()
var
(
var
(
matched
Claims
[]
*
bindingInfo
matched
Bindings
[]
*
bindingInfo
provisionedClaims
[]
*
v1
.
PersistentVolumeClaim
provisionedClaims
[]
*
v1
.
PersistentVolumeClaim
)
)
defer
func
()
{
defer
func
()
{
// We recreate bindings for each new schedule loop.
// We recreate bindings for each new schedule loop.
if
len
(
matched
Claim
s
)
==
0
&&
len
(
provisionedClaims
)
==
0
{
if
len
(
matched
Binding
s
)
==
0
&&
len
(
provisionedClaims
)
==
0
{
// Clear cache if no claims to bind or provision for this node.
// Clear cache if no claims to bind or provision for this node.
b
.
podBindingCache
.
ClearBindings
(
pod
,
node
.
Name
)
b
.
podBindingCache
.
ClearBindings
(
pod
,
node
.
Name
)
return
return
}
}
// Although we do not distinguish nil from empty in this function, for
// Although we do not distinguish nil from empty in this function, for
// easier testing, we normalize empty to nil.
// easier testing, we normalize empty to nil.
if
len
(
matched
Claim
s
)
==
0
{
if
len
(
matched
Binding
s
)
==
0
{
matched
Claim
s
=
nil
matched
Binding
s
=
nil
}
}
if
len
(
provisionedClaims
)
==
0
{
if
len
(
provisionedClaims
)
==
0
{
provisionedClaims
=
nil
provisionedClaims
=
nil
}
}
// Mark cache with all matched and provisioned claims for this node
// Mark cache with all matched and provisioned claims for this node
b
.
podBindingCache
.
UpdateBindings
(
pod
,
node
.
Name
,
matched
Claim
s
,
provisionedClaims
)
b
.
podBindingCache
.
UpdateBindings
(
pod
,
node
.
Name
,
matched
Binding
s
,
provisionedClaims
)
}()
}()
// The pod's volumes need to be processed in one call to avoid the race condition where
// 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
...
@@ -225,7 +225,7 @@ func (b *volumeBinder) FindPodVolumes(pod *v1.Pod, node *v1.Node) (unboundVolume
// Find matching volumes
// Find matching volumes
if
len
(
claimsToFindMatching
)
>
0
{
if
len
(
claimsToFindMatching
)
>
0
{
var
unboundClaims
[]
*
v1
.
PersistentVolumeClaim
var
unboundClaims
[]
*
v1
.
PersistentVolumeClaim
unboundVolumesSatisfied
,
matched
Claim
s
,
unboundClaims
,
err
=
b
.
findMatchingVolumes
(
pod
,
claimsToFindMatching
,
node
)
unboundVolumesSatisfied
,
matched
Binding
s
,
unboundClaims
,
err
=
b
.
findMatchingVolumes
(
pod
,
claimsToFindMatching
,
node
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
false
,
err
return
false
,
false
,
err
}
}
...
@@ -598,10 +598,10 @@ func (b *volumeBinder) arePodVolumesBound(pod *v1.Pod) bool {
...
@@ -598,10 +598,10 @@ func (b *volumeBinder) arePodVolumesBound(pod *v1.Pod) bool {
// getPodVolumes returns a pod's PVCs separated into bound, unbound with delayed binding (including provisioning)
// getPodVolumes returns a pod's PVCs separated into bound, unbound with delayed binding (including provisioning)
// and unbound with immediate binding (including prebound)
// and unbound with immediate binding (including prebound)
func
(
b
*
volumeBinder
)
getPodVolumes
(
pod
*
v1
.
Pod
)
(
boundClaims
[]
*
v1
.
PersistentVolumeClaim
,
unboundClaims
[]
*
v1
.
PersistentVolumeClaim
,
unboundClaimsImmediate
[]
*
v1
.
PersistentVolumeClaim
,
err
error
)
{
func
(
b
*
volumeBinder
)
getPodVolumes
(
pod
*
v1
.
Pod
)
(
boundClaims
[]
*
v1
.
PersistentVolumeClaim
,
unboundClaims
DelayBinding
[]
*
v1
.
PersistentVolumeClaim
,
unboundClaimsImmediate
[]
*
v1
.
PersistentVolumeClaim
,
err
error
)
{
boundClaims
=
[]
*
v1
.
PersistentVolumeClaim
{}
boundClaims
=
[]
*
v1
.
PersistentVolumeClaim
{}
unboundClaimsImmediate
=
[]
*
v1
.
PersistentVolumeClaim
{}
unboundClaimsImmediate
=
[]
*
v1
.
PersistentVolumeClaim
{}
unboundClaims
=
[]
*
v1
.
PersistentVolumeClaim
{}
unboundClaims
DelayBinding
=
[]
*
v1
.
PersistentVolumeClaim
{}
for
_
,
vol
:=
range
pod
.
Spec
.
Volumes
{
for
_
,
vol
:=
range
pod
.
Spec
.
Volumes
{
volumeBound
,
pvc
,
err
:=
b
.
isVolumeBound
(
pod
.
Namespace
,
&
vol
)
volumeBound
,
pvc
,
err
:=
b
.
isVolumeBound
(
pod
.
Namespace
,
&
vol
)
...
@@ -621,7 +621,7 @@ func (b *volumeBinder) getPodVolumes(pod *v1.Pod) (boundClaims []*v1.PersistentV
...
@@ -621,7 +621,7 @@ func (b *volumeBinder) getPodVolumes(pod *v1.Pod) (boundClaims []*v1.PersistentV
// Prebound PVCs are treated as unbound immediate binding
// Prebound PVCs are treated as unbound immediate binding
if
delayBindingMode
&&
pvc
.
Spec
.
VolumeName
==
""
{
if
delayBindingMode
&&
pvc
.
Spec
.
VolumeName
==
""
{
// Scheduler path
// Scheduler path
unboundClaims
=
append
(
unboundClaims
,
pvc
)
unboundClaims
DelayBinding
=
append
(
unboundClaimsDelayBinding
,
pvc
)
}
else
{
}
else
{
// !delayBindingMode || pvc.Spec.VolumeName != ""
// !delayBindingMode || pvc.Spec.VolumeName != ""
// Immediate binding should have already been bound
// Immediate binding should have already been bound
...
@@ -629,7 +629,7 @@ func (b *volumeBinder) getPodVolumes(pod *v1.Pod) (boundClaims []*v1.PersistentV
...
@@ -629,7 +629,7 @@ func (b *volumeBinder) getPodVolumes(pod *v1.Pod) (boundClaims []*v1.PersistentV
}
}
}
}
}
}
return
boundClaims
,
unboundClaims
,
unboundClaimsImmediate
,
nil
return
boundClaims
,
unboundClaims
DelayBinding
,
unboundClaimsImmediate
,
nil
}
}
func
(
b
*
volumeBinder
)
checkBoundClaims
(
claims
[]
*
v1
.
PersistentVolumeClaim
,
node
*
v1
.
Node
,
podName
string
)
(
bool
,
error
)
{
func
(
b
*
volumeBinder
)
checkBoundClaims
(
claims
[]
*
v1
.
PersistentVolumeClaim
,
node
*
v1
.
Node
,
podName
string
)
(
bool
,
error
)
{
...
@@ -654,7 +654,7 @@ func (b *volumeBinder) checkBoundClaims(claims []*v1.PersistentVolumeClaim, node
...
@@ -654,7 +654,7 @@ func (b *volumeBinder) checkBoundClaims(claims []*v1.PersistentVolumeClaim, node
// findMatchingVolumes tries to find matching volumes for given claims,
// findMatchingVolumes tries to find matching volumes for given claims,
// and return unbound claims for further provision.
// and return unbound claims for further provision.
func
(
b
*
volumeBinder
)
findMatchingVolumes
(
pod
*
v1
.
Pod
,
claimsToBind
[]
*
v1
.
PersistentVolumeClaim
,
node
*
v1
.
Node
)
(
foundMatches
bool
,
matchedClaim
s
[]
*
bindingInfo
,
unboundClaims
[]
*
v1
.
PersistentVolumeClaim
,
err
error
)
{
func
(
b
*
volumeBinder
)
findMatchingVolumes
(
pod
*
v1
.
Pod
,
claimsToBind
[]
*
v1
.
PersistentVolumeClaim
,
node
*
v1
.
Node
)
(
foundMatches
bool
,
binding
s
[]
*
bindingInfo
,
unboundClaims
[]
*
v1
.
PersistentVolumeClaim
,
err
error
)
{
podName
:=
getPodName
(
pod
)
podName
:=
getPodName
(
pod
)
// Sort all the claims by increasing size request to get the smallest fits
// Sort all the claims by increasing size request to get the smallest fits
sort
.
Sort
(
byPVCSize
(
claimsToBind
))
sort
.
Sort
(
byPVCSize
(
claimsToBind
))
...
@@ -662,7 +662,6 @@ func (b *volumeBinder) findMatchingVolumes(pod *v1.Pod, claimsToBind []*v1.Persi
...
@@ -662,7 +662,6 @@ func (b *volumeBinder) findMatchingVolumes(pod *v1.Pod, claimsToBind []*v1.Persi
chosenPVs
:=
map
[
string
]
*
v1
.
PersistentVolume
{}
chosenPVs
:=
map
[
string
]
*
v1
.
PersistentVolume
{}
foundMatches
=
true
foundMatches
=
true
matchedClaims
=
[]
*
bindingInfo
{}
for
_
,
pvc
:=
range
claimsToBind
{
for
_
,
pvc
:=
range
claimsToBind
{
// Get storage class name from each PVC
// Get storage class name from each PVC
...
@@ -688,7 +687,7 @@ func (b *volumeBinder) findMatchingVolumes(pod *v1.Pod, claimsToBind []*v1.Persi
...
@@ -688,7 +687,7 @@ func (b *volumeBinder) findMatchingVolumes(pod *v1.Pod, claimsToBind []*v1.Persi
// matching PV needs to be excluded so we don't select it again
// matching PV needs to be excluded so we don't select it again
chosenPVs
[
pv
.
Name
]
=
pv
chosenPVs
[
pv
.
Name
]
=
pv
matchedClaims
=
append
(
matchedClaim
s
,
&
bindingInfo
{
pv
:
pv
,
pvc
:
pvc
})
bindings
=
append
(
binding
s
,
&
bindingInfo
{
pv
:
pv
,
pvc
:
pvc
})
klog
.
V
(
5
)
.
Infof
(
"Found matching PV %q for PVC %q on node %q for pod %q"
,
pv
.
Name
,
pvcName
,
node
.
Name
,
podName
)
klog
.
V
(
5
)
.
Infof
(
"Found matching PV %q for PVC %q on node %q for pod %q"
,
pv
.
Name
,
pvcName
,
node
.
Name
,
podName
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment