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
18453b01
Commit
18453b01
authored
Nov 16, 2018
by
Michelle Au
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tolerate apiserver being older than controller-manager
parent
9bbf768a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
13 deletions
+67
-13
index.go
pkg/controller/volume/persistentvolume/index.go
+14
-13
index_test.go
pkg/controller/volume/persistentvolume/index_test.go
+53
-0
No files found.
pkg/controller/volume/persistentvolume/index.go
View file @
18453b01
...
@@ -259,22 +259,23 @@ func findMatchingVolume(
...
@@ -259,22 +259,23 @@ func findMatchingVolume(
}
}
// checkVolumeModeMismatches is a convenience method that checks volumeMode for PersistentVolume
// checkVolumeModeMismatches is a convenience method that checks volumeMode for PersistentVolume
// and PersistentVolumeClaims
along with making sure that the feature gate BlockVolume is enabled.
// and PersistentVolumeClaims
func
checkVolumeModeMismatches
(
pvcSpec
*
v1
.
PersistentVolumeClaimSpec
,
pvSpec
*
v1
.
PersistentVolumeSpec
)
(
bool
,
error
)
{
func
checkVolumeModeMismatches
(
pvcSpec
*
v1
.
PersistentVolumeClaimSpec
,
pvSpec
*
v1
.
PersistentVolumeSpec
)
(
bool
,
error
)
{
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
BlockVolume
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
BlockVolume
)
{
if
pvSpec
.
VolumeMode
!=
nil
&&
pvcSpec
.
VolumeMode
!=
nil
{
requestedVolumeMode
:=
*
pvcSpec
.
VolumeMode
pvVolumeMode
:=
*
pvSpec
.
VolumeMode
return
requestedVolumeMode
!=
pvVolumeMode
,
nil
}
else
{
// This also should return an error, this means that
// the defaulting has failed.
return
true
,
fmt
.
Errorf
(
"api defaulting for volumeMode failed"
)
}
}
else
{
// feature gate is disabled
return
false
,
nil
return
false
,
nil
}
}
// In HA upgrades, we cannot guarantee that the apiserver is on a version >= controller-manager.
// So we default a nil volumeMode to filesystem
requestedVolumeMode
:=
v1
.
PersistentVolumeFilesystem
if
pvcSpec
.
VolumeMode
!=
nil
{
requestedVolumeMode
=
*
pvcSpec
.
VolumeMode
}
pvVolumeMode
:=
v1
.
PersistentVolumeFilesystem
if
pvSpec
.
VolumeMode
!=
nil
{
pvVolumeMode
=
*
pvSpec
.
VolumeMode
}
return
requestedVolumeMode
!=
pvVolumeMode
,
nil
}
}
// 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
...
...
pkg/controller/volume/persistentvolume/index_test.go
View file @
18453b01
...
@@ -1038,6 +1038,29 @@ func createVolumeModeFilesystemTestVolume() *v1.PersistentVolume {
...
@@ -1038,6 +1038,29 @@ func createVolumeModeFilesystemTestVolume() *v1.PersistentVolume {
}
}
}
}
func
createVolumeModeNilTestVolume
()
*
v1
.
PersistentVolume
{
return
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
UID
:
"local-1"
,
Name
:
"nil-mode"
,
},
Spec
:
v1
.
PersistentVolumeSpec
{
Capacity
:
v1
.
ResourceList
{
v1
.
ResourceName
(
v1
.
ResourceStorage
)
:
resource
.
MustParse
(
"10G"
),
},
PersistentVolumeSource
:
v1
.
PersistentVolumeSource
{
Local
:
&
v1
.
LocalVolumeSource
{},
},
AccessModes
:
[]
v1
.
PersistentVolumeAccessMode
{
v1
.
ReadWriteOnce
,
},
},
Status
:
v1
.
PersistentVolumeStatus
{
Phase
:
v1
.
VolumeAvailable
,
},
}
}
func
createTestVolOrderedIndex
(
pv
*
v1
.
PersistentVolume
)
persistentVolumeOrderedIndex
{
func
createTestVolOrderedIndex
(
pv
*
v1
.
PersistentVolume
)
persistentVolumeOrderedIndex
{
volFile
:=
newPersistentVolumeOrderedIndex
()
volFile
:=
newPersistentVolumeOrderedIndex
()
volFile
.
store
.
Add
(
pv
)
volFile
.
store
.
Add
(
pv
)
...
@@ -1081,6 +1104,36 @@ func TestVolumeModeCheck(t *testing.T) {
...
@@ -1081,6 +1104,36 @@ func TestVolumeModeCheck(t *testing.T) {
pvc
:
makeVolumeModePVC
(
"8G"
,
&
filesystemMode
,
nil
),
pvc
:
makeVolumeModePVC
(
"8G"
,
&
filesystemMode
,
nil
),
enableBlock
:
true
,
enableBlock
:
true
,
},
},
"feature enabled - pvc filesystem and pv nil"
:
{
isExpectedMismatch
:
false
,
vol
:
createVolumeModeNilTestVolume
(),
pvc
:
makeVolumeModePVC
(
"8G"
,
&
filesystemMode
,
nil
),
enableBlock
:
true
,
},
"feature enabled - pvc nil and pv filesytem"
:
{
isExpectedMismatch
:
false
,
vol
:
createVolumeModeFilesystemTestVolume
(),
pvc
:
makeVolumeModePVC
(
"8G"
,
nil
,
nil
),
enableBlock
:
true
,
},
"feature enabled - pvc nil and pv nil"
:
{
isExpectedMismatch
:
false
,
vol
:
createVolumeModeNilTestVolume
(),
pvc
:
makeVolumeModePVC
(
"8G"
,
nil
,
nil
),
enableBlock
:
true
,
},
"feature enabled - pvc nil and pv block"
:
{
isExpectedMismatch
:
true
,
vol
:
createVolumeModeBlockTestVolume
(),
pvc
:
makeVolumeModePVC
(
"8G"
,
nil
,
nil
),
enableBlock
:
true
,
},
"feature enabled - pvc block and pv nil"
:
{
isExpectedMismatch
:
true
,
vol
:
createVolumeModeNilTestVolume
(),
pvc
:
makeVolumeModePVC
(
"8G"
,
&
blockMode
,
nil
),
enableBlock
:
true
,
},
"feature disabled - pvc block and pv filesystem"
:
{
"feature disabled - pvc block and pv filesystem"
:
{
isExpectedMismatch
:
false
,
isExpectedMismatch
:
false
,
vol
:
createVolumeModeFilesystemTestVolume
(),
vol
:
createVolumeModeFilesystemTestVolume
(),
...
...
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