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
67a55a4b
Commit
67a55a4b
authored
Mar 07, 2017
by
NickrenREN
Committed by
NickrenREN
Apr 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
matchPredicate does not fit findByClaim()
matchPredicate has two args which are type of PV,and is not used in function findByClaim(),remove it
parent
31db570a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
14 deletions
+11
-14
index.go
pkg/controller/volume/persistentvolume/index.go
+2
-14
index_test.go
pkg/controller/volume/persistentvolume/index_test.go
+9
-0
No files found.
pkg/controller/volume/persistentvolume/index.go
View file @
67a55a4b
...
@@ -68,11 +68,8 @@ func (pvIndex *persistentVolumeOrderedIndex) listByAccessModes(modes []v1.Persis
...
@@ -68,11 +68,8 @@ func (pvIndex *persistentVolumeOrderedIndex) listByAccessModes(modes []v1.Persis
return
volumes
,
nil
return
volumes
,
nil
}
}
// matchPredicate is a function that indicates that a persistent volume matches another
type
matchPredicate
func
(
compareThis
,
toThis
*
v1
.
PersistentVolume
)
bool
// find returns the nearest PV from the ordered list or nil if a match is not found
// find returns the nearest PV from the ordered list or nil if a match is not found
func
(
pvIndex
*
persistentVolumeOrderedIndex
)
findByClaim
(
claim
*
v1
.
PersistentVolumeClaim
,
matchPredicate
matchPredicate
)
(
*
v1
.
PersistentVolume
,
error
)
{
func
(
pvIndex
*
persistentVolumeOrderedIndex
)
findByClaim
(
claim
*
v1
.
PersistentVolumeClaim
)
(
*
v1
.
PersistentVolume
,
error
)
{
// PVs are indexed by their access modes to allow easier searching. Each
// PVs are indexed by their access modes to allow easier searching. Each
// index is the string representation of a set of access modes. There is a
// index is the string representation of a set of access modes. There is a
// finite number of possible sets and PVs will only be indexed in one of
// finite number of possible sets and PVs will only be indexed in one of
...
@@ -170,16 +167,7 @@ func (pvIndex *persistentVolumeOrderedIndex) findByClaim(claim *v1.PersistentVol
...
@@ -170,16 +167,7 @@ func (pvIndex *persistentVolumeOrderedIndex) findByClaim(claim *v1.PersistentVol
// findBestMatchForClaim is a convenience method that finds a volume by the claim's AccessModes and requests for Storage
// findBestMatchForClaim is a convenience method that finds a volume by the claim's AccessModes and requests for Storage
func
(
pvIndex
*
persistentVolumeOrderedIndex
)
findBestMatchForClaim
(
claim
*
v1
.
PersistentVolumeClaim
)
(
*
v1
.
PersistentVolume
,
error
)
{
func
(
pvIndex
*
persistentVolumeOrderedIndex
)
findBestMatchForClaim
(
claim
*
v1
.
PersistentVolumeClaim
)
(
*
v1
.
PersistentVolume
,
error
)
{
return
pvIndex
.
findByClaim
(
claim
,
matchStorageCapacity
)
return
pvIndex
.
findByClaim
(
claim
)
}
// matchStorageCapacity is a matchPredicate used to sort and find volumes
func
matchStorageCapacity
(
pvA
,
pvB
*
v1
.
PersistentVolume
)
bool
{
aQty
:=
pvA
.
Spec
.
Capacity
[
v1
.
ResourceStorage
]
bQty
:=
pvB
.
Spec
.
Capacity
[
v1
.
ResourceStorage
]
aSize
:=
aQty
.
Value
()
bSize
:=
bQty
.
Value
()
return
aSize
<=
bSize
}
}
// allPossibleMatchingAccessModes returns an array of AccessMode arrays that
// allPossibleMatchingAccessModes returns an array of AccessMode arrays that
...
...
pkg/controller/volume/persistentvolume/index_test.go
View file @
67a55a4b
...
@@ -689,3 +689,12 @@ func (c byCapacity) Swap(i, j int) {
...
@@ -689,3 +689,12 @@ func (c byCapacity) Swap(i, j int) {
func
(
c
byCapacity
)
Len
()
int
{
func
(
c
byCapacity
)
Len
()
int
{
return
len
(
c
.
volumes
)
return
len
(
c
.
volumes
)
}
}
// matchStorageCapacity is a matchPredicate used to sort and find volumes
func
matchStorageCapacity
(
pvA
,
pvB
*
v1
.
PersistentVolume
)
bool
{
aQty
:=
pvA
.
Spec
.
Capacity
[
v1
.
ResourceStorage
]
bQty
:=
pvB
.
Spec
.
Capacity
[
v1
.
ResourceStorage
]
aSize
:=
aQty
.
Value
()
bSize
:=
bQty
.
Value
()
return
aSize
<=
bSize
}
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