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
3211b8b0
Commit
3211b8b0
authored
Nov 08, 2017
by
Michelle Au
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor PV selection into a common call for scheduler and PV controller
parent
754017be
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
50 deletions
+63
-50
index.go
pkg/controller/volume/persistentvolume/index.go
+63
-50
No files found.
pkg/controller/volume/persistentvolume/index.go
View file @
3211b8b0
...
@@ -90,6 +90,25 @@ func (pvIndex *persistentVolumeOrderedIndex) findByClaim(claim *v1.PersistentVol
...
@@ -90,6 +90,25 @@ func (pvIndex *persistentVolumeOrderedIndex) findByClaim(claim *v1.PersistentVol
// example above).
// example above).
allPossibleModes
:=
pvIndex
.
allPossibleMatchingAccessModes
(
claim
.
Spec
.
AccessModes
)
allPossibleModes
:=
pvIndex
.
allPossibleMatchingAccessModes
(
claim
.
Spec
.
AccessModes
)
for
_
,
modes
:=
range
allPossibleModes
{
volumes
,
err
:=
pvIndex
.
listByAccessModes
(
modes
)
if
err
!=
nil
{
return
nil
,
err
}
bestVol
,
err
:=
findMatchingVolume
(
claim
,
volumes
)
if
err
!=
nil
{
return
nil
,
err
}
if
bestVol
!=
nil
{
return
bestVol
,
nil
}
}
return
nil
,
nil
}
func
findMatchingVolume
(
claim
*
v1
.
PersistentVolumeClaim
,
volumes
[]
*
v1
.
PersistentVolume
)
(
*
v1
.
PersistentVolume
,
error
)
{
var
smallestVolume
*
v1
.
PersistentVolume
var
smallestVolume
*
v1
.
PersistentVolume
var
smallestVolumeQty
resource
.
Quantity
var
smallestVolumeQty
resource
.
Quantity
requestedQty
:=
claim
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
requestedQty
:=
claim
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
...
@@ -105,67 +124,61 @@ func (pvIndex *persistentVolumeOrderedIndex) findByClaim(claim *v1.PersistentVol
...
@@ -105,67 +124,61 @@ func (pvIndex *persistentVolumeOrderedIndex) findByClaim(claim *v1.PersistentVol
selector
=
internalSelector
selector
=
internalSelector
}
}
for
_
,
modes
:=
range
allPossibleModes
{
// Go through all available volumes with two goals:
volumes
,
err
:=
pvIndex
.
listByAccessModes
(
modes
)
// - find a volume that is either pre-bound by user or dynamically
// provisioned for this claim. Because of this we need to loop through
// all volumes.
// - find the smallest matching one if there is no volume pre-bound to
// the claim.
for
_
,
volume
:=
range
volumes
{
volumeQty
:=
volume
.
Spec
.
Capacity
[
v1
.
ResourceStorage
]
// check if volumeModes do not match (Alpha and feature gate protected)
isMisMatch
,
err
:=
checkVolumeModeMisMatches
(
&
claim
.
Spec
,
&
volume
.
Spec
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
fmt
.
Errorf
(
"error checking if volumeMode was a mismatch: %v"
,
err
)
}
// filter out mismatching volumeModes
if
isMisMatch
{
continue
}
}
// Go through all available volumes with two goals:
if
isVolumeBoundToClaim
(
volume
,
claim
)
{
// - find a volume that is either pre-bound by user or dynamically
// this claim and volume are pre-bound; return
// provisioned for this claim. Because of this we need to loop through
// the volume if the size request is satisfied,
// all volumes.
// otherwise continue searching for a match
// - find the smallest matching one if there is no volume pre-bound to
if
volumeQty
.
Cmp
(
requestedQty
)
<
0
{
// the claim.
for
_
,
volume
:=
range
volumes
{
// check if volumeModes do not match (Alpha and feature gate protected)
isMisMatch
,
err
:=
checkVolumeModeMisMatches
(
&
claim
.
Spec
,
&
volume
.
Spec
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error checking if volumeMode was a mismatch: %v"
,
err
)
}
// filter out mismatching volumeModes
if
isMisMatch
{
continue
continue
}
}
return
volume
,
nil
}
if
isVolumeBoundToClaim
(
volume
,
claim
)
{
// filter out:
// this claim and volume are pre-bound; return
// - volumes bound to another claim
// the volume if the size request is satisfied,
// - volumes whose labels don't match the claim's selector, if specified
// otherwise continue searching for a match
// - volumes in Class that is not requested
volumeQty
:=
volume
.
Spec
.
Capacity
[
v1
.
ResourceStorage
]
if
volume
.
Spec
.
ClaimRef
!=
nil
{
if
volumeQty
.
Cmp
(
requestedQty
)
<
0
{
continue
continue
}
else
if
selector
!=
nil
&&
!
selector
.
Matches
(
labels
.
Set
(
volume
.
Labels
))
{
}
continue
return
volume
,
nil
}
}
if
v1helper
.
GetPersistentVolumeClass
(
volume
)
!=
requestedClass
{
continue
// filter out:
}
// - volumes bound to another claim
// - volumes whose labels don't match the claim's selector, if specified
// - volumes in Class that is not requested
if
volume
.
Spec
.
ClaimRef
!=
nil
{
continue
}
else
if
selector
!=
nil
&&
!
selector
.
Matches
(
labels
.
Set
(
volume
.
Labels
))
{
continue
}
if
v1helper
.
GetPersistentVolumeClass
(
volume
)
!=
requestedClass
{
continue
}
volumeQty
:=
volume
.
Spec
.
Capacity
[
v1
.
ResourceStorage
]
if
volumeQty
.
Cmp
(
requestedQty
)
>=
0
{
if
volumeQty
.
Cmp
(
requestedQty
)
>=
0
{
if
smallestVolume
==
nil
||
smallestVolumeQty
.
Cmp
(
volumeQty
)
>
0
{
if
smallestVolume
==
nil
||
smallestVolumeQty
.
Cmp
(
volumeQty
)
>
0
{
smallestVolume
=
volume
smallestVolume
=
volume
smallestVolumeQty
=
volumeQty
smallestVolumeQty
=
volumeQty
}
}
}
}
}
}
if
smallestVolume
!=
nil
{
if
smallestVolume
!=
nil
{
// Found a matching volume
// Found a matching volume
return
smallestVolume
,
nil
return
smallestVolume
,
nil
}
}
}
return
nil
,
nil
return
nil
,
nil
}
}
...
...
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