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
dd517c9f
Commit
dd517c9f
authored
Jul 04, 2018
by
Matthew Wong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update all tests to account for BlockVolume enabled by default
parent
7a6acefd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
155 additions
and
48 deletions
+155
-48
fuzzer.go
pkg/apis/core/fuzzer/fuzzer.go
+4
-0
defaults_test.go
pkg/apis/core/v1/defaults_test.go
+4
-11
validation_test.go
pkg/apis/core/validation/validation_test.go
+76
-12
binder_test.go
pkg/controller/volume/persistentvolume/binder_test.go
+20
-11
framework_test.go
pkg/controller/volume/persistentvolume/framework_test.go
+13
-0
index.go
pkg/controller/volume/persistentvolume/index.go
+7
-9
index_test.go
pkg/controller/volume/persistentvolume/index_test.go
+0
-0
pv_controller.go
pkg/controller/volume/persistentvolume/pv_controller.go
+3
-3
scheduler_binder_test.go
...ntroller/volume/persistentvolume/scheduler_binder_test.go
+6
-0
desired_state_of_world_populator_test.go
...anager/populator/desired_state_of_world_populator_test.go
+5
-1
reconciler_test.go
pkg/kubelet/volumemanager/reconciler/reconciler_test.go
+4
-1
volume_manager_test.go
pkg/kubelet/volumemanager/volume_manager_test.go
+4
-0
fc_test.go
pkg/volume/fc/fc_test.go
+9
-0
No files found.
pkg/apis/core/fuzzer/fuzzer.go
View file @
dd517c9f
...
...
@@ -403,11 +403,15 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
pv
.
Status
.
Message
=
c
.
RandString
()
reclamationPolicies
:=
[]
core
.
PersistentVolumeReclaimPolicy
{
core
.
PersistentVolumeReclaimRecycle
,
core
.
PersistentVolumeReclaimRetain
}
pv
.
Spec
.
PersistentVolumeReclaimPolicy
=
reclamationPolicies
[
c
.
Rand
.
Intn
(
len
(
reclamationPolicies
))]
volumeModes
:=
[]
core
.
PersistentVolumeMode
{
core
.
PersistentVolumeFilesystem
,
core
.
PersistentVolumeBlock
}
pv
.
Spec
.
VolumeMode
=
&
volumeModes
[
c
.
Rand
.
Intn
(
len
(
volumeModes
))]
},
func
(
pvc
*
core
.
PersistentVolumeClaim
,
c
fuzz
.
Continue
)
{
c
.
FuzzNoCustom
(
pvc
)
// fuzz self without calling this function again
types
:=
[]
core
.
PersistentVolumeClaimPhase
{
core
.
ClaimBound
,
core
.
ClaimPending
,
core
.
ClaimLost
}
pvc
.
Status
.
Phase
=
types
[
c
.
Rand
.
Intn
(
len
(
types
))]
volumeModes
:=
[]
core
.
PersistentVolumeMode
{
core
.
PersistentVolumeFilesystem
,
core
.
PersistentVolumeBlock
}
pvc
.
Spec
.
VolumeMode
=
&
volumeModes
[
c
.
Rand
.
Intn
(
len
(
volumeModes
))]
},
func
(
obj
*
core
.
AzureDiskVolumeSource
,
c
fuzz
.
Continue
)
{
if
obj
.
CachingMode
==
nil
{
...
...
pkg/apis/core/v1/defaults_test.go
View file @
dd517c9f
...
...
@@ -27,8 +27,10 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
"k8s.io/kubernetes/pkg/api/legacyscheme"
corev1
"k8s.io/kubernetes/pkg/apis/core/v1"
"k8s.io/kubernetes/pkg/features"
utilpointer
"k8s.io/utils/pointer"
// enforce that all types are installed
...
...
@@ -803,6 +805,7 @@ func TestSetDefaultSecret(t *testing.T) {
}
func
TestSetDefaultPersistentVolume
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
BlockVolume
,
false
)()
pv
:=
&
v1
.
PersistentVolume
{}
obj2
:=
roundTrip
(
t
,
runtime
.
Object
(
pv
))
pv2
:=
obj2
.
(
*
v1
.
PersistentVolume
)
...
...
@@ -834,15 +837,10 @@ func TestSetDefaultPersistentVolume(t *testing.T) {
}
else
if
*
outputMode3
!=
defaultMode
{
t
.
Errorf
(
"Expected VolumeMode to be defaulted to: %+v, got: %+v"
,
defaultMode
,
outputMode3
)
}
err
=
utilfeature
.
DefaultFeatureGate
.
Set
(
"BlockVolume=false"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to disable feature gate for BlockVolume: %v"
,
err
)
}
}
func
TestSetDefaultPersistentVolumeClaim
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
BlockVolume
,
false
)()
pvc
:=
&
v1
.
PersistentVolumeClaim
{}
obj2
:=
roundTrip
(
t
,
runtime
.
Object
(
pvc
))
pvc2
:=
obj2
.
(
*
v1
.
PersistentVolumeClaim
)
...
...
@@ -871,11 +869,6 @@ func TestSetDefaultPersistentVolumeClaim(t *testing.T) {
}
else
if
*
outputMode3
!=
defaultMode
{
t
.
Errorf
(
"Expected VolumeMode to be defaulted to: %+v, got: %+v"
,
defaultMode
,
outputMode3
)
}
err
=
utilfeature
.
DefaultFeatureGate
.
Set
(
"BlockVolume=false"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to disable feature gate for BlockVolume: %v"
,
err
)
}
}
func
TestSetDefaulEndpointsProtocol
(
t
*
testing
.
T
)
{
...
...
pkg/apis/core/validation/validation_test.go
View file @
dd517c9f
...
...
@@ -66,9 +66,11 @@ func testVolume(name string, namespace string, spec core.PersistentVolumeSpec) *
func
TestValidatePersistentVolumes
(
t
*
testing
.
T
)
{
validMode
:=
core
.
PersistentVolumeFilesystem
invalidMode
:=
core
.
PersistentVolumeMode
(
"fakeVolumeMode"
)
scenarios
:=
map
[
string
]
struct
{
isExpectedFailure
bool
volume
*
core
.
PersistentVolume
isExpectedFailure
bool
volume
*
core
.
PersistentVolume
disableBlockVolume
bool
}{
"good-volume"
:
{
isExpectedFailure
:
false
,
...
...
@@ -147,6 +149,22 @@ func TestValidatePersistentVolumes(t *testing.T) {
PersistentVolumeReclaimPolicy
:
core
.
PersistentVolumeReclaimRetain
,
}),
},
"good-volume-with-volume-mode"
:
{
isExpectedFailure
:
false
,
volume
:
testVolume
(
"foo"
,
""
,
core
.
PersistentVolumeSpec
{
Capacity
:
core
.
ResourceList
{
core
.
ResourceName
(
core
.
ResourceStorage
)
:
resource
.
MustParse
(
"10G"
),
},
AccessModes
:
[]
core
.
PersistentVolumeAccessMode
{
core
.
ReadWriteOnce
},
PersistentVolumeSource
:
core
.
PersistentVolumeSource
{
HostPath
:
&
core
.
HostPathVolumeSource
{
Path
:
"/foo"
,
Type
:
newHostPathType
(
string
(
core
.
HostPathDirectory
)),
},
},
VolumeMode
:
&
validMode
,
}),
},
"invalid-accessmode"
:
{
isExpectedFailure
:
true
,
volume
:
testVolume
(
"foo"
,
""
,
core
.
PersistentVolumeSpec
{
...
...
@@ -178,6 +196,22 @@ func TestValidatePersistentVolumes(t *testing.T) {
PersistentVolumeReclaimPolicy
:
"fakeReclaimPolicy"
,
}),
},
"invalid-volume-mode"
:
{
isExpectedFailure
:
true
,
volume
:
testVolume
(
"foo"
,
""
,
core
.
PersistentVolumeSpec
{
Capacity
:
core
.
ResourceList
{
core
.
ResourceName
(
core
.
ResourceStorage
)
:
resource
.
MustParse
(
"10G"
),
},
AccessModes
:
[]
core
.
PersistentVolumeAccessMode
{
core
.
ReadWriteOnce
},
PersistentVolumeSource
:
core
.
PersistentVolumeSource
{
HostPath
:
&
core
.
HostPathVolumeSource
{
Path
:
"/foo"
,
Type
:
newHostPathType
(
string
(
core
.
HostPathDirectory
)),
},
},
VolumeMode
:
&
invalidMode
,
}),
},
"unexpected-namespace"
:
{
isExpectedFailure
:
true
,
volume
:
testVolume
(
"foo"
,
"unexpected-namespace"
,
core
.
PersistentVolumeSpec
{
...
...
@@ -336,10 +370,9 @@ func TestValidatePersistentVolumes(t *testing.T) {
StorageClassName
:
"-invalid-"
,
}),
},
// VolumeMode alpha feature disabled
// TODO: remove when no longer alpha
"alpha disabled valid volume mode"
:
{
isExpectedFailure
:
true
,
"feature disabled valid volume mode"
:
{
disableBlockVolume
:
true
,
isExpectedFailure
:
true
,
volume
:
testVolume
(
"foo"
,
""
,
core
.
PersistentVolumeSpec
{
Capacity
:
core
.
ResourceList
{
core
.
ResourceName
(
core
.
ResourceStorage
)
:
resource
.
MustParse
(
"10G"
),
...
...
@@ -400,6 +433,10 @@ func TestValidatePersistentVolumes(t *testing.T) {
}
for
name
,
scenario
:=
range
scenarios
{
var
restore
func
()
if
scenario
.
disableBlockVolume
{
restore
=
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
BlockVolume
,
false
)
}
errs
:=
ValidatePersistentVolume
(
scenario
.
volume
)
if
len
(
errs
)
==
0
&&
scenario
.
isExpectedFailure
{
t
.
Errorf
(
"Unexpected success for scenario: %s"
,
name
)
...
...
@@ -407,6 +444,9 @@ func TestValidatePersistentVolumes(t *testing.T) {
if
len
(
errs
)
>
0
&&
!
scenario
.
isExpectedFailure
{
t
.
Errorf
(
"Unexpected failure for scenario: %s - %+v"
,
name
,
errs
)
}
if
scenario
.
disableBlockVolume
{
restore
()
}
}
}
...
...
@@ -791,10 +831,12 @@ func testVolumeClaimStorageClassInAnnotationAndSpec(name, namespace, scNameInAnn
func
TestValidatePersistentVolumeClaim
(
t
*
testing
.
T
)
{
invalidClassName
:=
"-invalid-"
validClassName
:=
"valid"
invalidMode
:=
core
.
PersistentVolumeMode
(
"fakeVolumeMode"
)
validMode
:=
core
.
PersistentVolumeFilesystem
scenarios
:=
map
[
string
]
struct
{
isExpectedFailure
bool
claim
*
core
.
PersistentVolumeClaim
isExpectedFailure
bool
claim
*
core
.
PersistentVolumeClaim
disableBlockVolume
bool
}{
"good-claim"
:
{
isExpectedFailure
:
false
,
...
...
@@ -817,6 +859,7 @@ func TestValidatePersistentVolumeClaim(t *testing.T) {
},
},
StorageClassName
:
&
validClassName
,
VolumeMode
:
&
validMode
,
}),
},
"invalid-claim-zero-capacity"
:
{
...
...
@@ -988,10 +1031,9 @@ func TestValidatePersistentVolumeClaim(t *testing.T) {
StorageClassName
:
&
invalidClassName
,
}),
},
// VolumeMode alpha feature disabled
// TODO: remove when no longer alpha
"disabled alpha valid volume mode"
:
{
isExpectedFailure
:
true
,
"feature disabled valid volume mode"
:
{
disableBlockVolume
:
true
,
isExpectedFailure
:
true
,
claim
:
testVolumeClaim
(
"foo"
,
"ns"
,
core
.
PersistentVolumeClaimSpec
{
Selector
:
&
metav1
.
LabelSelector
{
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{
...
...
@@ -1014,9 +1056,28 @@ func TestValidatePersistentVolumeClaim(t *testing.T) {
VolumeMode
:
&
validMode
,
}),
},
"invalid-volume-mode"
:
{
isExpectedFailure
:
true
,
claim
:
testVolumeClaim
(
"foo"
,
"ns"
,
core
.
PersistentVolumeClaimSpec
{
AccessModes
:
[]
core
.
PersistentVolumeAccessMode
{
core
.
ReadWriteOnce
,
core
.
ReadOnlyMany
,
},
Resources
:
core
.
ResourceRequirements
{
Requests
:
core
.
ResourceList
{
core
.
ResourceName
(
core
.
ResourceStorage
)
:
resource
.
MustParse
(
"10G"
),
},
},
VolumeMode
:
&
invalidMode
,
}),
},
}
for
name
,
scenario
:=
range
scenarios
{
var
restore
func
()
if
scenario
.
disableBlockVolume
{
restore
=
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
BlockVolume
,
false
)
}
errs
:=
ValidatePersistentVolumeClaim
(
scenario
.
claim
)
if
len
(
errs
)
==
0
&&
scenario
.
isExpectedFailure
{
t
.
Errorf
(
"Unexpected success for scenario: %s"
,
name
)
...
...
@@ -1024,6 +1085,9 @@ func TestValidatePersistentVolumeClaim(t *testing.T) {
if
len
(
errs
)
>
0
&&
!
scenario
.
isExpectedFailure
{
t
.
Errorf
(
"Unexpected failure for scenario: %s - %+v"
,
name
,
errs
)
}
if
scenario
.
disableBlockVolume
{
restore
()
}
}
}
...
...
pkg/controller/volume/persistentvolume/binder_test.go
View file @
dd517c9f
...
...
@@ -23,6 +23,8 @@ import (
storage
"k8s.io/api/storage/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeaturetesting
"k8s.io/apiserver/pkg/util/feature/testing"
"k8s.io/kubernetes/pkg/features"
)
// Test single call to syncClaim and syncVolume methods.
...
...
@@ -35,8 +37,6 @@ func TestSync(t *testing.T) {
"foo"
:
"true"
,
"bar"
:
"false"
,
}
modeBlock
:=
v1
.
PersistentVolumeBlock
modeFile
:=
v1
.
PersistentVolumeFilesystem
tests
:=
[]
controllerTest
{
// [Unit test set 1] User did not care which PV they get.
...
...
@@ -589,9 +589,22 @@ func TestSync(t *testing.T) {
newClaimArray
(
"claim13-5"
,
"uid13-5"
,
"1Gi"
,
"volume13-5"
,
v1
.
ClaimBound
,
nil
,
annBoundByController
,
annBindCompleted
),
noevents
,
noerrors
,
testSyncClaim
,
},
}
// All of these should bind as feature set is not enabled for BlockVolume
// meaning volumeMode will be ignored and dropped
runSyncTests
(
t
,
tests
,
[]
*
storage
.
StorageClass
{
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
classWait
},
VolumeBindingMode
:
&
modeWait
,
},
},
[]
*
v1
.
Pod
{})
}
func
TestSyncBlockVolumeDisabled
(
t
*
testing
.
T
)
{
modeBlock
:=
v1
.
PersistentVolumeBlock
modeFile
:=
v1
.
PersistentVolumeFilesystem
// All of these should bind as feature set is not enabled for BlockVolume
// meaning volumeMode will be ignored and dropped
tests
:=
[]
controllerTest
{
{
// syncVolume binds a requested block claim to a block volume
"14-1 - binding to volumeMode block"
,
...
...
@@ -639,6 +652,7 @@ func TestSync(t *testing.T) {
},
}
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
BlockVolume
,
false
)()
runSyncTests
(
t
,
tests
,
[]
*
storage
.
StorageClass
{
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
classWait
},
...
...
@@ -647,7 +661,7 @@ func TestSync(t *testing.T) {
},
[]
*
v1
.
Pod
{})
}
func
TestSync
Alpha
BlockVolume
(
t
*
testing
.
T
)
{
func
TestSyncBlockVolume
(
t
*
testing
.
T
)
{
modeBlock
:=
v1
.
PersistentVolumeBlock
modeFile
:=
v1
.
PersistentVolumeFilesystem
...
...
@@ -827,12 +841,7 @@ func TestSyncAlphaBlockVolume(t *testing.T) {
},
}
err
:=
utilfeature
.
DefaultFeatureGate
.
Set
(
"BlockVolume=true"
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to enable feature gate for BlockVolume: %v"
,
err
)
return
}
defer
utilfeature
.
DefaultFeatureGate
.
Set
(
"BlockVolume=false"
)
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
BlockVolume
,
true
)()
runSyncTests
(
t
,
tests
,
[]
*
storage
.
StorageClass
{},
[]
*
v1
.
Pod
{})
}
...
...
pkg/controller/volume/persistentvolume/framework_test.go
View file @
dd517c9f
...
...
@@ -38,6 +38,7 @@ import (
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/informers"
clientset
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
...
...
@@ -48,6 +49,7 @@ import (
"k8s.io/client-go/tools/record"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/features"
vol
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util/recyclerclient"
)
...
...
@@ -179,6 +181,12 @@ func (r *volumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
return
true
,
nil
,
fmt
.
Errorf
(
"Cannot create volume %s: volume already exists"
,
volume
.
Name
)
}
// mimic apiserver defaulting
if
volume
.
Spec
.
VolumeMode
==
nil
&&
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
BlockVolume
)
{
volume
.
Spec
.
VolumeMode
=
new
(
v1
.
PersistentVolumeMode
)
*
volume
.
Spec
.
VolumeMode
=
v1
.
PersistentVolumeFilesystem
}
// Store the updated object to appropriate places.
r
.
volumes
[
volume
.
Name
]
=
volume
r
.
changedObjects
=
append
(
r
.
changedObjects
,
volume
)
...
...
@@ -630,6 +638,7 @@ func newTestController(kubeClient clientset.Interface, informerFactory informers
// newVolume returns a new volume with given attributes
func
newVolume
(
name
,
capacity
,
boundToClaimUID
,
boundToClaimName
string
,
phase
v1
.
PersistentVolumePhase
,
reclaimPolicy
v1
.
PersistentVolumeReclaimPolicy
,
class
string
,
annotations
...
string
)
*
v1
.
PersistentVolume
{
fs
:=
v1
.
PersistentVolumeFilesystem
volume
:=
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
name
,
...
...
@@ -645,6 +654,7 @@ func newVolume(name, capacity, boundToClaimUID, boundToClaimName string, phase v
AccessModes
:
[]
v1
.
PersistentVolumeAccessMode
{
v1
.
ReadWriteOnce
,
v1
.
ReadOnlyMany
},
PersistentVolumeReclaimPolicy
:
reclaimPolicy
,
StorageClassName
:
class
,
VolumeMode
:
&
fs
,
},
Status
:
v1
.
PersistentVolumeStatus
{
Phase
:
phase
,
...
...
@@ -740,6 +750,7 @@ func newVolumeArray(name, capacity, boundToClaimUID, boundToClaimName string, ph
// newClaim returns a new claim with given attributes
func
newClaim
(
name
,
claimUID
,
capacity
,
boundToVolume
string
,
phase
v1
.
PersistentVolumeClaimPhase
,
class
*
string
,
annotations
...
string
)
*
v1
.
PersistentVolumeClaim
{
fs
:=
v1
.
PersistentVolumeFilesystem
claim
:=
v1
.
PersistentVolumeClaim
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
name
,
...
...
@@ -756,6 +767,7 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.Persisten
},
VolumeName
:
boundToVolume
,
StorageClassName
:
class
,
VolumeMode
:
&
fs
,
},
Status
:
v1
.
PersistentVolumeClaimStatus
{
Phase
:
phase
,
...
...
@@ -1226,6 +1238,7 @@ func (plugin *mockVolumePlugin) Provision(selectedNode *v1.Node, allowedTopologi
Phase
:
v1
.
VolumeAvailable
,
},
}
pv
.
Spec
.
VolumeMode
=
plugin
.
provisionOptions
.
PVC
.
Spec
.
VolumeMode
}
plugin
.
provisionCallCounter
++
...
...
pkg/controller/volume/persistentvolume/index.go
View file @
dd517c9f
...
...
@@ -158,13 +158,13 @@ func findMatchingVolume(
volumeQty
:=
volume
.
Spec
.
Capacity
[
v1
.
ResourceStorage
]
// check if volumeModes do not match (
Alpha and
feature gate protected)
isMis
Match
,
err
:=
checkVolumeModeMisM
atches
(
&
claim
.
Spec
,
&
volume
.
Spec
)
// check if volumeModes do not match (feature gate protected)
isMis
match
,
err
:=
checkVolumeModeMism
atches
(
&
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
isMis
M
atch
{
if
isMis
m
atch
{
continue
}
...
...
@@ -258,18 +258,16 @@ func findMatchingVolume(
return
nil
,
nil
}
// checkVolumeModeMatches is a convenience method that checks volumeMode for PersistentVolume
// and PersistentVolumeClaims along with making sure that the Alpha feature gate BlockVolume is
// enabled.
// This is Alpha and could change in the future.
func
checkVolumeModeMisMatches
(
pvcSpec
*
v1
.
PersistentVolumeClaimSpec
,
pvSpec
*
v1
.
PersistentVolumeSpec
)
(
bool
,
error
)
{
// checkVolumeModeMismatches is a convenience method that checks volumeMode for PersistentVolume
// and PersistentVolumeClaims along with making sure that the feature gate BlockVolume is enabled.
func
checkVolumeModeMismatches
(
pvcSpec
*
v1
.
PersistentVolumeClaimSpec
,
pvSpec
*
v1
.
PersistentVolumeSpec
)
(
bool
,
error
)
{
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 ret
ru
n an error, this means that
// This also should ret
ur
n an error, this means that
// the defaulting has failed.
return
true
,
fmt
.
Errorf
(
"api defaulting for volumeMode failed"
)
}
...
...
pkg/controller/volume/persistentvolume/index_test.go
View file @
dd517c9f
This diff is collapsed.
Click to expand it.
pkg/controller/volume/persistentvolume/pv_controller.go
View file @
dd517c9f
...
...
@@ -270,11 +270,11 @@ func checkVolumeSatisfyClaim(volume *v1.PersistentVolume, claim *v1.PersistentVo
return
fmt
.
Errorf
(
"storageClassName does not match"
)
}
isMis
Match
,
err
:=
checkVolumeModeMisM
atches
(
&
claim
.
Spec
,
&
volume
.
Spec
)
isMis
match
,
err
:=
checkVolumeModeMism
atches
(
&
claim
.
Spec
,
&
volume
.
Spec
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error checking volumeMode: %v"
,
err
)
}
if
isMis
M
atch
{
if
isMis
m
atch
{
return
fmt
.
Errorf
(
"incompatible volumeMode"
)
}
...
...
@@ -613,7 +613,7 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *v1.PersistentVolume)
}
return
nil
}
else
if
claim
.
Spec
.
VolumeName
==
""
{
if
isMis
Match
,
err
:=
checkVolumeModeMisMatches
(
&
claim
.
Spec
,
&
volume
.
Spec
);
err
!=
nil
||
isMisM
atch
{
if
isMis
match
,
err
:=
checkVolumeModeMismatches
(
&
claim
.
Spec
,
&
volume
.
Spec
);
err
!=
nil
||
isMism
atch
{
// Binding for the volume won't be called in syncUnboundClaim,
// because findBestMatchForClaim won't return the volume due to volumeMode mismatch.
volumeMsg
:=
fmt
.
Sprintf
(
"Cannot bind PersistentVolume to requested PersistentVolumeClaim %q due to incompatible volumeMode."
,
claim
.
Name
)
...
...
pkg/controller/volume/persistentvolume/scheduler_binder_test.go
View file @
dd517c9f
...
...
@@ -426,6 +426,7 @@ const (
)
func
makeTestPVC
(
name
,
size
,
node
string
,
pvcBoundState
int
,
pvName
,
resourceVersion
string
,
className
*
string
)
*
v1
.
PersistentVolumeClaim
{
fs
:=
v1
.
PersistentVolumeFilesystem
pvc
:=
&
v1
.
PersistentVolumeClaim
{
TypeMeta
:
metav1
.
TypeMeta
{
Kind
:
"PersistentVolumeClaim"
,
...
...
@@ -445,6 +446,7 @@ func makeTestPVC(name, size, node string, pvcBoundState int, pvName, resourceVer
},
},
StorageClassName
:
className
,
VolumeMode
:
&
fs
,
},
}
...
...
@@ -462,6 +464,7 @@ func makeTestPVC(name, size, node string, pvcBoundState int, pvName, resourceVer
}
func
makeBadPVC
()
*
v1
.
PersistentVolumeClaim
{
fs
:=
v1
.
PersistentVolumeFilesystem
return
&
v1
.
PersistentVolumeClaim
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bad-pvc"
,
...
...
@@ -477,11 +480,13 @@ func makeBadPVC() *v1.PersistentVolumeClaim {
},
},
StorageClassName
:
&
waitClass
,
VolumeMode
:
&
fs
,
},
}
}
func
makeTestPV
(
name
,
node
,
capacity
,
version
string
,
boundToPVC
*
v1
.
PersistentVolumeClaim
,
className
string
)
*
v1
.
PersistentVolume
{
fs
:=
v1
.
PersistentVolumeFilesystem
pv
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
name
,
...
...
@@ -492,6 +497,7 @@ func makeTestPV(name, node, capacity, version string, boundToPVC *v1.PersistentV
v1
.
ResourceName
(
v1
.
ResourceStorage
)
:
resource
.
MustParse
(
capacity
),
},
StorageClassName
:
className
,
VolumeMode
:
&
fs
,
},
Status
:
v1
.
PersistentVolumeStatus
{
Phase
:
v1
.
VolumeAvailable
,
...
...
pkg/kubelet/volumemanager/populator/desired_state_of_world_populator_test.go
View file @
dd517c9f
...
...
@@ -46,12 +46,14 @@ import (
func
TestFindAndAddNewPods_FindAndRemoveDeletedPods
(
t
*
testing
.
T
)
{
// create dswp
mode
:=
v1
.
PersistentVolumeFilesystem
pv
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"dswp-test-volume-name"
,
},
Spec
:
v1
.
PersistentVolumeSpec
{
ClaimRef
:
&
v1
.
ObjectReference
{
Namespace
:
"ns"
,
Name
:
"file-bound"
},
ClaimRef
:
&
v1
.
ObjectReference
{
Namespace
:
"ns"
,
Name
:
"file-bound"
},
VolumeMode
:
&
mode
,
},
}
pvc
:=
&
v1
.
PersistentVolumeClaim
{
...
...
@@ -453,6 +455,7 @@ func TestCreateVolumeSpec_Invalid_Block_VolumeMounts(t *testing.T) {
}
func
TestCheckVolumeFSResize
(
t
*
testing
.
T
)
{
mode
:=
v1
.
PersistentVolumeFilesystem
pv
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"dswp-test-volume-name"
,
...
...
@@ -461,6 +464,7 @@ func TestCheckVolumeFSResize(t *testing.T) {
PersistentVolumeSource
:
v1
.
PersistentVolumeSource
{
RBD
:
&
v1
.
RBDPersistentVolumeSource
{}},
Capacity
:
volumeCapacity
(
1
),
ClaimRef
:
&
v1
.
ObjectReference
{
Namespace
:
"ns"
,
Name
:
"file-bound"
},
VolumeMode
:
&
mode
,
},
}
pvc
:=
&
v1
.
PersistentVolumeClaim
{
...
...
pkg/kubelet/volumemanager/reconciler/reconciler_test.go
View file @
dd517c9f
...
...
@@ -949,13 +949,15 @@ func Test_GenerateUnmapDeviceFunc_Plugin_Not_Found(t *testing.T) {
func
Test_Run_Positive_VolumeFSResizeControllerAttachEnabled
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
features
.
ExpandInUsePersistentVolumes
,
true
)()
fs
:=
v1
.
PersistentVolumeFilesystem
pv
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pv"
,
UID
:
"pvuid"
,
},
Spec
:
v1
.
PersistentVolumeSpec
{
ClaimRef
:
&
v1
.
ObjectReference
{
Name
:
"pvc"
},
ClaimRef
:
&
v1
.
ObjectReference
{
Name
:
"pvc"
},
VolumeMode
:
&
fs
,
},
}
pvc
:=
&
v1
.
PersistentVolumeClaim
{
...
...
@@ -965,6 +967,7 @@ func Test_Run_Positive_VolumeFSResizeControllerAttachEnabled(t *testing.T) {
},
Spec
:
v1
.
PersistentVolumeClaimSpec
{
VolumeName
:
"pv"
,
VolumeMode
:
&
fs
,
},
}
pod
:=
&
v1
.
Pod
{
...
...
pkg/kubelet/volumemanager/volume_manager_test.go
View file @
dd517c9f
...
...
@@ -167,6 +167,7 @@ func TestGetExtraSupplementalGroupsForPod(t *testing.T) {
}
for
_
,
tc
:=
range
cases
{
fs
:=
v1
.
PersistentVolumeFilesystem
pv
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pvA"
,
...
...
@@ -183,6 +184,7 @@ func TestGetExtraSupplementalGroupsForPod(t *testing.T) {
ClaimRef
:
&
v1
.
ObjectReference
{
Name
:
claim
.
ObjectMeta
.
Name
,
},
VolumeMode
:
&
fs
,
},
}
kubeClient
:=
fake
.
NewSimpleClientset
(
node
,
pod
,
pv
,
claim
)
...
...
@@ -273,6 +275,7 @@ func createObjects() (*v1.Node, *v1.Pod, *v1.PersistentVolume, *v1.PersistentVol
},
},
}
fs
:=
v1
.
PersistentVolumeFilesystem
pv
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pvA"
,
...
...
@@ -286,6 +289,7 @@ func createObjects() (*v1.Node, *v1.Pod, *v1.PersistentVolume, *v1.PersistentVol
ClaimRef
:
&
v1
.
ObjectReference
{
Name
:
"claimA"
,
},
VolumeMode
:
&
fs
,
},
}
claim
:=
&
v1
.
PersistentVolumeClaim
{
...
...
pkg/volume/fc/fc_test.go
View file @
dd517c9f
...
...
@@ -254,6 +254,7 @@ func TestPluginVolume(t *testing.T) {
func
TestPluginPersistentVolume
(
t
*
testing
.
T
)
{
lun
:=
int32
(
0
)
fs
:=
v1
.
PersistentVolumeFilesystem
vol
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"vol1"
,
...
...
@@ -266,6 +267,7 @@ func TestPluginPersistentVolume(t *testing.T) {
Lun
:
&
lun
,
},
},
VolumeMode
:
&
fs
,
},
}
doTestPlugin
(
t
,
volume
.
NewSpecFromPersistentVolume
(
vol
,
false
))
...
...
@@ -285,6 +287,7 @@ func TestPluginVolumeWWIDs(t *testing.T) {
}
func
TestPluginPersistentVolumeWWIDs
(
t
*
testing
.
T
)
{
fs
:=
v1
.
PersistentVolumeFilesystem
vol
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"vol1"
,
...
...
@@ -296,6 +299,7 @@ func TestPluginPersistentVolumeWWIDs(t *testing.T) {
FSType
:
"ext4"
,
},
},
VolumeMode
:
&
fs
,
},
}
doTestPlugin
(
t
,
volume
.
NewSpecFromPersistentVolume
(
vol
,
false
))
...
...
@@ -314,6 +318,7 @@ func TestPluginVolumeNoDiskInfo(t *testing.T) {
}
func
TestPluginPersistentVolumeNoDiskInfo
(
t
*
testing
.
T
)
{
fs
:=
v1
.
PersistentVolumeFilesystem
vol
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"vol1"
,
...
...
@@ -324,6 +329,7 @@ func TestPluginPersistentVolumeNoDiskInfo(t *testing.T) {
FSType
:
"ext4"
,
},
},
VolumeMode
:
&
fs
,
},
}
doTestPluginNilMounter
(
t
,
volume
.
NewSpecFromPersistentVolume
(
vol
,
false
))
...
...
@@ -337,6 +343,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
defer
os
.
RemoveAll
(
tmpDir
)
lun
:=
int32
(
0
)
fs
:=
v1
.
PersistentVolumeFilesystem
pv
:=
&
v1
.
PersistentVolume
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pvA"
,
...
...
@@ -352,6 +359,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
ClaimRef
:
&
v1
.
ObjectReference
{
Name
:
"claimA"
,
},
VolumeMode
:
&
fs
,
},
}
...
...
@@ -362,6 +370,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
},
Spec
:
v1
.
PersistentVolumeClaimSpec
{
VolumeName
:
"pvA"
,
VolumeMode
:
&
fs
,
},
Status
:
v1
.
PersistentVolumeClaimStatus
{
Phase
:
v1
.
ClaimBound
,
...
...
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