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
691fec5e
Commit
691fec5e
authored
Jan 24, 2018
by
Jan Safranek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't bind PVs and PVCs with different access modes.
PVC pre-bound to a PV can bind to the PV only if it has correct access mode. Report an event if it does not and keep the PVC Pending.
parent
2f4cca73
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
5 deletions
+41
-5
binder_test.go
pkg/controller/volume/persistentvolume/binder_test.go
+26
-0
framework_test.go
pkg/controller/volume/persistentvolume/framework_test.go
+7
-0
pv_controller.go
pkg/controller/volume/persistentvolume/pv_controller.go
+8
-5
No files found.
pkg/controller/volume/persistentvolume/binder_test.go
View file @
691fec5e
...
@@ -198,6 +198,32 @@ func TestSync(t *testing.T) {
...
@@ -198,6 +198,32 @@ func TestSync(t *testing.T) {
newClaimArray
(
"claim1-1"
,
"uid1-1"
,
"1Gi"
,
"volume1-1"
,
v1
.
ClaimBound
,
&
classWait
,
annBoundByController
,
annBindCompleted
),
newClaimArray
(
"claim1-1"
,
"uid1-1"
,
"1Gi"
,
"volume1-1"
,
v1
.
ClaimBound
,
&
classWait
,
annBoundByController
,
annBindCompleted
),
noevents
,
noerrors
,
testSyncClaim
,
noevents
,
noerrors
,
testSyncClaim
,
},
},
{
// syncClaim binds pre-bound PVC only to the volume it points to,
// even if there is smaller volume available
"1-15 - successful prebound PVC"
,
[]
*
v1
.
PersistentVolume
{
newVolume
(
"volume1-15_1"
,
"10Gi"
,
""
,
""
,
v1
.
VolumePending
,
v1
.
PersistentVolumeReclaimRetain
,
classEmpty
),
newVolume
(
"volume1-15_2"
,
"1Gi"
,
""
,
""
,
v1
.
VolumePending
,
v1
.
PersistentVolumeReclaimRetain
,
classEmpty
),
},
[]
*
v1
.
PersistentVolume
{
newVolume
(
"volume1-15_1"
,
"10Gi"
,
"uid1-15"
,
"claim1-15"
,
v1
.
VolumeBound
,
v1
.
PersistentVolumeReclaimRetain
,
classEmpty
,
annBoundByController
),
newVolume
(
"volume1-15_2"
,
"1Gi"
,
""
,
""
,
v1
.
VolumePending
,
v1
.
PersistentVolumeReclaimRetain
,
classEmpty
),
},
newClaimArray
(
"claim1-15"
,
"uid1-15"
,
"1Gi"
,
"volume1-15_1"
,
v1
.
ClaimPending
,
nil
),
withExpectedCapacity
(
"10Gi"
,
newClaimArray
(
"claim1-15"
,
"uid1-15"
,
"1Gi"
,
"volume1-15_1"
,
v1
.
ClaimBound
,
nil
,
annBindCompleted
)),
noevents
,
noerrors
,
testSyncClaim
,
},
{
// syncClaim does not bind pre-bound PVC to PV with different AccessMode
"1-16 - successful prebound PVC"
,
// PV has ReadWriteOnce
newVolumeArray
(
"volume1-16"
,
"1Gi"
,
""
,
""
,
v1
.
VolumePending
,
v1
.
PersistentVolumeReclaimRetain
,
classEmpty
),
newVolumeArray
(
"volume1-16"
,
"1Gi"
,
""
,
""
,
v1
.
VolumePending
,
v1
.
PersistentVolumeReclaimRetain
,
classEmpty
),
claimWithAccessMode
([]
v1
.
PersistentVolumeAccessMode
{
v1
.
ReadWriteMany
},
newClaimArray
(
"claim1-16"
,
"uid1-16"
,
"1Gi"
,
"volume1-16"
,
v1
.
ClaimPending
,
nil
)),
claimWithAccessMode
([]
v1
.
PersistentVolumeAccessMode
{
v1
.
ReadWriteMany
},
newClaimArray
(
"claim1-16"
,
"uid1-16"
,
"1Gi"
,
"volume1-16"
,
v1
.
ClaimPending
,
nil
)),
noevents
,
noerrors
,
testSyncClaim
,
},
// [Unit test set 2] User asked for a specific PV.
// [Unit test set 2] User asked for a specific PV.
// Test the binding when pv.ClaimRef is already set by controller or
// Test the binding when pv.ClaimRef is already set by controller or
...
...
pkg/controller/volume/persistentvolume/framework_test.go
View file @
691fec5e
...
@@ -802,6 +802,13 @@ func claimWithAnnotation(name, value string, claims []*v1.PersistentVolumeClaim)
...
@@ -802,6 +802,13 @@ func claimWithAnnotation(name, value string, claims []*v1.PersistentVolumeClaim)
return
claims
return
claims
}
}
// claimWithAccessMode saves given access into given claims.
// Meant to be used to compose claims specified inline in a test.
func
claimWithAccessMode
(
modes
[]
v1
.
PersistentVolumeAccessMode
,
claims
[]
*
v1
.
PersistentVolumeClaim
)
[]
*
v1
.
PersistentVolumeClaim
{
claims
[
0
]
.
Spec
.
AccessModes
=
modes
return
claims
}
func
testSyncClaim
(
ctrl
*
PersistentVolumeController
,
reactor
*
volumeReactor
,
test
controllerTest
)
error
{
func
testSyncClaim
(
ctrl
*
PersistentVolumeController
,
reactor
*
volumeReactor
,
test
controllerTest
)
error
{
return
ctrl
.
syncClaim
(
test
.
initialClaims
[
0
])
return
ctrl
.
syncClaim
(
test
.
initialClaims
[
0
])
}
}
...
...
pkg/controller/volume/persistentvolume/pv_controller.go
View file @
691fec5e
...
@@ -233,11 +233,6 @@ func (ctrl *PersistentVolumeController) syncClaim(claim *v1.PersistentVolumeClai
...
@@ -233,11 +233,6 @@ func (ctrl *PersistentVolumeController) syncClaim(claim *v1.PersistentVolumeClai
func
checkVolumeSatisfyClaim
(
volume
*
v1
.
PersistentVolume
,
claim
*
v1
.
PersistentVolumeClaim
)
error
{
func
checkVolumeSatisfyClaim
(
volume
*
v1
.
PersistentVolume
,
claim
*
v1
.
PersistentVolumeClaim
)
error
{
requestedQty
:=
claim
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
requestedQty
:=
claim
.
Spec
.
Resources
.
Requests
[
v1
.
ResourceName
(
v1
.
ResourceStorage
)]
requestedSize
:=
requestedQty
.
Value
()
requestedSize
:=
requestedQty
.
Value
()
isMisMatch
,
err
:=
checkVolumeModeMisMatches
(
&
claim
.
Spec
,
&
volume
.
Spec
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error checking volumeMode: %v"
,
err
)
}
volumeQty
:=
volume
.
Spec
.
Capacity
[
v1
.
ResourceStorage
]
volumeQty
:=
volume
.
Spec
.
Capacity
[
v1
.
ResourceStorage
]
volumeSize
:=
volumeQty
.
Value
()
volumeSize
:=
volumeQty
.
Value
()
if
volumeSize
<
requestedSize
{
if
volumeSize
<
requestedSize
{
...
@@ -249,10 +244,18 @@ func checkVolumeSatisfyClaim(volume *v1.PersistentVolume, claim *v1.PersistentVo
...
@@ -249,10 +244,18 @@ func checkVolumeSatisfyClaim(volume *v1.PersistentVolume, claim *v1.PersistentVo
return
fmt
.
Errorf
(
"storageClasseName does not match"
)
return
fmt
.
Errorf
(
"storageClasseName does not match"
)
}
}
isMisMatch
,
err
:=
checkVolumeModeMisMatches
(
&
claim
.
Spec
,
&
volume
.
Spec
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error checking volumeMode: %v"
,
err
)
}
if
isMisMatch
{
if
isMisMatch
{
return
fmt
.
Errorf
(
"incompatible volumeMode"
)
return
fmt
.
Errorf
(
"incompatible volumeMode"
)
}
}
if
!
checkAccessModes
(
claim
,
volume
)
{
return
fmt
.
Errorf
(
"incompatible accessMode"
)
}
return
nil
return
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